@rebilly/instruments 4.8.1 → 4.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/index.js +1 -1
- package/dist/index.min.js +1 -1
- package/package.json +5 -1
- package/.babelrc +0 -26
- package/project.json +0 -31
- package/rollup.config.mjs +0 -79
- package/src/data/options-schema/index.js +0 -112
- package/src/data/options-schema/schemas/options-schema.js +0 -448
- package/src/events/base-event.js +0 -47
- package/src/events/events.spec.js +0 -11
- package/src/events/index.js +0 -15
- package/src/functions/destroy.js +0 -29
- package/src/functions/destroy.spec.js +0 -63
- package/src/functions/mount/fetch-data.js +0 -236
- package/src/functions/mount/fetch-data.spec.js +0 -317
- package/src/functions/mount/get-lead-source-data.js +0 -46
- package/src/functions/mount/get-lead-source-data.spec.js +0 -38
- package/src/functions/mount/index.js +0 -105
- package/src/functions/mount/mount.spec.js +0 -96
- package/src/functions/mount/setup-element.js +0 -29
- package/src/functions/mount/setup-framepay-theme.js +0 -104
- package/src/functions/mount/setup-framepay.js +0 -26
- package/src/functions/mount/setup-i18n.js +0 -21
- package/src/functions/mount/setup-options.js +0 -100
- package/src/functions/mount/setup-options.spec.js +0 -353
- package/src/functions/mount/setup-storefront.js +0 -23
- package/src/functions/mount/setup-styles-vars.js +0 -30
- package/src/functions/mount/setup-user-flow.js +0 -60
- package/src/functions/on.js +0 -22
- package/src/functions/on.spec.js +0 -75
- package/src/functions/purchase.js +0 -173
- package/src/functions/purchase.spec.js +0 -80
- package/src/functions/setup.js +0 -66
- package/src/functions/setup.spec.js +0 -111
- package/src/functions/show.js +0 -30
- package/src/functions/show.spec.js +0 -62
- package/src/functions/update.js +0 -40
- package/src/functions/update.spec.js +0 -104
- package/src/i18n/en.json +0 -35
- package/src/i18n/es.json +0 -32
- package/src/i18n/i18n.spec.js +0 -27
- package/src/i18n/index.js +0 -59
- package/src/index.js +0 -3
- package/src/instance.js +0 -48
- package/src/instance.spec.js +0 -44
- package/src/loader/index.js +0 -145
- package/src/loader/loader.spec.js +0 -74
- package/src/state/iframes.js +0 -23
- package/src/state/index.js +0 -64
- package/src/storefront/account-and-website.js +0 -18
- package/src/storefront/account-and-website.spec.js +0 -73
- package/src/storefront/deposit-requests.js +0 -12
- package/src/storefront/fetch-plans-from-addons-bumpOffer.js +0 -30
- package/src/storefront/fetch-products-from-plans.js +0 -59
- package/src/storefront/fetch-products-from-plans.spec.js +0 -113
- package/src/storefront/index.js +0 -78
- package/src/storefront/invoices.js +0 -23
- package/src/storefront/invoices.spec.js +0 -92
- package/src/storefront/models/account-model.js +0 -36
- package/src/storefront/models/base-model.js +0 -7
- package/src/storefront/models/deposit-request-model.js +0 -24
- package/src/storefront/models/invoice-model.js +0 -20
- package/src/storefront/models/payment-metadata.js +0 -7
- package/src/storefront/models/plan-model.js +0 -94
- package/src/storefront/models/product-model.js +0 -3
- package/src/storefront/models/ready-to-pay-model.js +0 -76
- package/src/storefront/models/summary-model.js +0 -56
- package/src/storefront/models/transaction-model.js +0 -16
- package/src/storefront/models/website-model.js +0 -3
- package/src/storefront/payment-instruments.js +0 -47
- package/src/storefront/payment-instruments.spec.js +0 -88
- package/src/storefront/purchase.js +0 -60
- package/src/storefront/purchase.spec.js +0 -53
- package/src/storefront/ready-to-pay.js +0 -96
- package/src/storefront/ready-to-pay.spec.js +0 -76
- package/src/storefront/storefront.spec.js +0 -14
- package/src/storefront/summary.js +0 -114
- package/src/storefront/summary.spec.js +0 -136
- package/src/storefront/transactions.js +0 -12
- package/src/style/base/__snapshots__/theme.spec.js.snap +0 -143
- package/src/style/base/default-theme.js +0 -955
- package/src/style/base/index.js +0 -688
- package/src/style/base/theme.js +0 -30
- package/src/style/base/theme.spec.js +0 -19
- package/src/style/index.js +0 -11
- package/src/style/utils/border.js +0 -47
- package/src/style/utils/color-values.js +0 -35
- package/src/style/utils/minifyCss.js +0 -14
- package/src/utils/add-dom-element.js +0 -17
- package/src/utils/format-currency.js +0 -8
- package/src/utils/has-valid-css-selector.js +0 -4
- package/src/utils/index.js +0 -15
- package/src/utils/is-dom-element.js +0 -3
- package/src/utils/process-property-as-dom-element.js +0 -31
- package/src/utils/quantity.js +0 -47
- package/src/utils/sleep.js +0 -5
- package/src/views/amount-selector.js +0 -46
- package/src/views/common/iframe/base-iframe.js +0 -66
- package/src/views/common/iframe/events/change-iframe-src-handler.js +0 -6
- package/src/views/common/iframe/events/dispatch-event-handler.js +0 -8
- package/src/views/common/iframe/events/resize-component-handler.js +0 -9
- package/src/views/common/iframe/events/show-error-handler.js +0 -5
- package/src/views/common/iframe/events/stop-loader-handler.js +0 -9
- package/src/views/common/iframe/events/update-addons-handler.js +0 -23
- package/src/views/common/iframe/events/update-coupons-handler.js +0 -12
- package/src/views/common/iframe/events/update-items-handler.js +0 -34
- package/src/views/common/iframe/index.js +0 -5
- package/src/views/common/iframe/modal-iframe.js +0 -82
- package/src/views/common/iframe/view-iframe.js +0 -23
- package/src/views/common/render-utilities.js +0 -4
- package/src/views/confirmation.js +0 -45
- package/src/views/errors.js +0 -115
- package/src/views/form.js +0 -61
- package/src/views/method-selector/__snapshots__/method-selector.spec.js.snap +0 -135
- package/src/views/method-selector/express-methods.js +0 -52
- package/src/views/method-selector/generate-digital-wallet.js +0 -53
- package/src/views/method-selector/generate-digital-wallet.spec.js +0 -121
- package/src/views/method-selector/generate-framepay-config.js +0 -56
- package/src/views/method-selector/generate-framepay-config.spec.js +0 -216
- package/src/views/method-selector/get-method-data.js +0 -11
- package/src/views/method-selector/get-payment-methods.js +0 -25
- package/src/views/method-selector/get-payment-methods.spec.js +0 -41
- package/src/views/method-selector/index.js +0 -223
- package/src/views/method-selector/method-selector.spec.js +0 -20
- package/src/views/method-selector/mount-bump-offer.js +0 -120
- package/src/views/method-selector/mount-express-methods.js +0 -107
- package/src/views/modal.js +0 -103
- package/src/views/result.js +0 -24
- package/src/views/summary.js +0 -38
- package/tests/async-utilities.js +0 -22
- package/tests/mocks/framepay-mock.js +0 -15
- package/tests/mocks/rebilly-api-mock.js +0 -11
- package/tests/mocks/rebilly-instruments-mock.js +0 -141
- package/tests/mocks/storefront-api-mock.js +0 -62
- package/tests/mocks/storefront-mock.js +0 -20
- package/tests/msw/server.js +0 -14
- package/tests/setup-test.js +0 -30
- package/vitest.config.js +0 -18
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import state from '../state';
|
|
2
|
-
import { postPurchase, postPayment } from '../storefront/purchase';
|
|
3
|
-
import Events from '../events';
|
|
4
|
-
import { mountModal } from '../views/modal';
|
|
5
|
-
import { DataInstance } from './mount/fetch-data';
|
|
6
|
-
import { showError } from '../views/errors';
|
|
7
|
-
import { mapItemsQuantities } from '../utils/quantity';
|
|
8
|
-
|
|
9
|
-
export async function makePayment({ payload }) {
|
|
10
|
-
const {
|
|
11
|
-
_raw: { id },
|
|
12
|
-
isExistingInstrument,
|
|
13
|
-
} = payload;
|
|
14
|
-
delete payload.isExistingInstrument;
|
|
15
|
-
delete payload._raw;
|
|
16
|
-
|
|
17
|
-
const data = {
|
|
18
|
-
...payload,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
if (isExistingInstrument) {
|
|
22
|
-
data.paymentInstrumentId = id;
|
|
23
|
-
} else {
|
|
24
|
-
data.token = id;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (state.options?.invoiceId) {
|
|
28
|
-
data.invoiceId = state.options.invoiceId;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (state.options?.transactionId) {
|
|
32
|
-
data.transactionId = state.options.transactionId;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (state.options?.money) {
|
|
36
|
-
data.websiteId = state.options.websiteId;
|
|
37
|
-
data.amount = state.options.money.amount;
|
|
38
|
-
data.currency = state.options.money.currency;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (state.options?.deposit) {
|
|
42
|
-
data.websiteId = state.options.websiteId;
|
|
43
|
-
data.amount = state.data.amountAndCurrency.amount;
|
|
44
|
-
data.currency = state.data.amountAndCurrency.currency;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (state.data?.couponIds && Array.isArray(state.data.couponIds)) {
|
|
48
|
-
data.couponIds = state.data.couponIds;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
let { fields } = await postPayment({
|
|
52
|
-
state,
|
|
53
|
-
data,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
fields = {
|
|
57
|
-
transaction: fields,
|
|
58
|
-
token: fields.token || state.options.jwt,
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
if (state.data.invoice) {
|
|
62
|
-
fields.invoice = state.data.invoice;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return fields;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export async function makePurchase({ payload }) {
|
|
69
|
-
const data = {
|
|
70
|
-
websiteId: state.options.websiteId,
|
|
71
|
-
paymentInstruction: {
|
|
72
|
-
token: payload._raw.id,
|
|
73
|
-
},
|
|
74
|
-
...payload,
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
if (state.data.acceptBumpOffer) {
|
|
78
|
-
data.items = state.options.bumpOffer;
|
|
79
|
-
} else {
|
|
80
|
-
data.items = mapItemsQuantities(state.options.items);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (state.data.couponIds && Array.isArray(state.data.couponIds)) {
|
|
84
|
-
data.couponIds = state.data.couponIds;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
state.options.addons &&
|
|
89
|
-
state.data.addons &&
|
|
90
|
-
Array.isArray(state.data.addons)
|
|
91
|
-
) {
|
|
92
|
-
state.options.addons.forEach((addon) => {
|
|
93
|
-
if (state.data.addons.includes(addon.planId)) {
|
|
94
|
-
data.items.push(addon);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const { fields } = await postPurchase({
|
|
100
|
-
state,
|
|
101
|
-
data,
|
|
102
|
-
});
|
|
103
|
-
return fields;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function handleApprovalUrl({ fields, payload }) {
|
|
107
|
-
if (
|
|
108
|
-
state.options.features.fullPageRedirect &&
|
|
109
|
-
(payload.redirectUrl || fields.transaction?.approvalUrl)
|
|
110
|
-
) {
|
|
111
|
-
window.location =
|
|
112
|
-
payload.redirectUrl || fields.transaction?.approvalUrl;
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (payload.redirectUrl || !fields.transaction?.approvalUrl) {
|
|
117
|
-
const { paymentMethodsUrl } = state.options._computed;
|
|
118
|
-
const modelSafeFields = JSON.parse(JSON.stringify(fields));
|
|
119
|
-
|
|
120
|
-
const model = {};
|
|
121
|
-
if (state.data.isPayment) {
|
|
122
|
-
model.payment = modelSafeFields;
|
|
123
|
-
} else {
|
|
124
|
-
model.purchase = modelSafeFields;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
state.data = new DataInstance({ ...fields });
|
|
128
|
-
|
|
129
|
-
const name = 'rebilly-instruments-approval-url';
|
|
130
|
-
mountModal({
|
|
131
|
-
name,
|
|
132
|
-
url: `${paymentMethodsUrl}?name=${name}`,
|
|
133
|
-
model,
|
|
134
|
-
close: (updatedPurchase) => {
|
|
135
|
-
Events.purchaseCompleted.dispatch(updatedPurchase);
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
} else if (fields.transaction?.approvalUrl) {
|
|
139
|
-
window.location = fields.transaction?.approvalUrl;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export async function purchase({ payload }) {
|
|
144
|
-
Object.keys(payload).forEach((key) => {
|
|
145
|
-
if (payload[key] === null) {
|
|
146
|
-
delete payload[key];
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
try {
|
|
151
|
-
let fields;
|
|
152
|
-
if (state.data.isPayment) {
|
|
153
|
-
fields = await makePayment({ payload });
|
|
154
|
-
} else {
|
|
155
|
-
fields = await makePurchase({ payload });
|
|
156
|
-
}
|
|
157
|
-
if (
|
|
158
|
-
fields.transaction?.approvalUrl &&
|
|
159
|
-
fields.transaction?.result === 'unknown'
|
|
160
|
-
) {
|
|
161
|
-
if (state.options.features.fullPageRedirect) {
|
|
162
|
-
window.location = fields.transaction?.approvalUrl;
|
|
163
|
-
} else {
|
|
164
|
-
handleApprovalUrl({ fields, payload });
|
|
165
|
-
}
|
|
166
|
-
} else {
|
|
167
|
-
Events.purchaseCompleted.dispatch(fields);
|
|
168
|
-
}
|
|
169
|
-
} catch (error) {
|
|
170
|
-
showError(error);
|
|
171
|
-
return error;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { RenderMockRebillyInstruments } from 'tests/mocks/rebilly-instruments-mock';
|
|
2
|
-
import { ok, post } from 'msw-when-then';
|
|
3
|
-
import { when } from 'tests/msw/server';
|
|
4
|
-
import { storefrontURL } from 'tests/mocks/storefront-api-mock';
|
|
5
|
-
import { avoidUnhandledPromises } from 'tests/async-utilities';
|
|
6
|
-
import Events from '../events';
|
|
7
|
-
import { mapItemsQuantities } from '../utils/quantity';
|
|
8
|
-
|
|
9
|
-
describe('RebillyInstruments purchase', () => {
|
|
10
|
-
it('should be able to make a purchase', async () => {
|
|
11
|
-
const options = {
|
|
12
|
-
websiteId: 'test-website-id',
|
|
13
|
-
items: [{ planId: 'test-plan-id', quantity: 1 }],
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const token = {
|
|
17
|
-
id: 'test-token-id',
|
|
18
|
-
};
|
|
19
|
-
const billingAddress = {
|
|
20
|
-
billing: 'address',
|
|
21
|
-
};
|
|
22
|
-
const deliveryAddress = {
|
|
23
|
-
delivery: 'address',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const fields = {
|
|
27
|
-
orderId: 'test-order-id',
|
|
28
|
-
invoice: {
|
|
29
|
-
id: 'test-invoice-id',
|
|
30
|
-
},
|
|
31
|
-
transaction: {
|
|
32
|
-
id: 'test-transaction-id',
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
when(post(`${storefrontURL}/purchase`)).thenReturn(ok(fields));
|
|
37
|
-
const rebillyInstruments = await RenderMockRebillyInstruments(options);
|
|
38
|
-
const spyStorefrontPurchase = vi.spyOn(
|
|
39
|
-
rebillyInstruments.state.storefront.purchase,
|
|
40
|
-
'purchase',
|
|
41
|
-
);
|
|
42
|
-
vi.spyOn(Events.purchaseCompleted, 'dispatch');
|
|
43
|
-
|
|
44
|
-
const purchaseCompletedListener = vi.fn();
|
|
45
|
-
|
|
46
|
-
rebillyInstruments.on('purchase-completed', purchaseCompletedListener);
|
|
47
|
-
|
|
48
|
-
const purchasePayload = {
|
|
49
|
-
billingAddress,
|
|
50
|
-
deliveryAddress,
|
|
51
|
-
_raw: token,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const purchasePayloadParsed = {
|
|
55
|
-
websiteId: rebillyInstruments.state.options.websiteId,
|
|
56
|
-
items: mapItemsQuantities(rebillyInstruments.state.options.items),
|
|
57
|
-
billingAddress,
|
|
58
|
-
deliveryAddress,
|
|
59
|
-
couponIds: [],
|
|
60
|
-
paymentInstruction: {
|
|
61
|
-
token: token.id,
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
await rebillyInstruments.purchase(purchasePayload);
|
|
66
|
-
|
|
67
|
-
expect(spyStorefrontPurchase).toBeCalledTimes(1);
|
|
68
|
-
expect(spyStorefrontPurchase).toBeCalledWith({
|
|
69
|
-
data: expect.objectContaining(purchasePayloadParsed),
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
expect(Events.purchaseCompleted.dispatch).toBeCalledTimes(1);
|
|
73
|
-
|
|
74
|
-
expect(purchaseCompletedListener).toBeCalledTimes(1);
|
|
75
|
-
expect(purchaseCompletedListener).toBeCalledWith(
|
|
76
|
-
expect.objectContaining(fields),
|
|
77
|
-
);
|
|
78
|
-
await avoidUnhandledPromises();
|
|
79
|
-
});
|
|
80
|
-
});
|
package/src/functions/setup.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import state from '../state';
|
|
2
|
-
import { setupPaymentInstrument } from '../storefront/payment-instruments';
|
|
3
|
-
import Events from '../events';
|
|
4
|
-
import { mountModal } from '../views/modal';
|
|
5
|
-
import { DataInstance } from './mount/fetch-data';
|
|
6
|
-
import { showError } from '../views/errors';
|
|
7
|
-
|
|
8
|
-
export async function setup({ payload }) {
|
|
9
|
-
try {
|
|
10
|
-
const {
|
|
11
|
-
_raw: { id },
|
|
12
|
-
isExistingInstrument,
|
|
13
|
-
} = payload;
|
|
14
|
-
delete payload.isExistingInstrument;
|
|
15
|
-
delete payload._raw;
|
|
16
|
-
|
|
17
|
-
const data = {
|
|
18
|
-
...payload,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
if (isExistingInstrument) {
|
|
22
|
-
data.paymentInstrumentId = id;
|
|
23
|
-
} else {
|
|
24
|
-
data.token = id;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const { instrument, transaction } = await setupPaymentInstrument({
|
|
28
|
-
data: {
|
|
29
|
-
websiteId: state.options?.websiteId,
|
|
30
|
-
...data,
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
state.data = new DataInstance({ instrument, transaction });
|
|
35
|
-
|
|
36
|
-
if (transaction.approvalUrl && transaction.result === 'unknown') {
|
|
37
|
-
if (state.options.features.fullPageRedirect) {
|
|
38
|
-
window.location = transaction.approvalUrl;
|
|
39
|
-
} else {
|
|
40
|
-
const { paymentMethodsUrl } = state.options._computed;
|
|
41
|
-
mountModal({
|
|
42
|
-
name: 'rebilly-instruments-approval-url',
|
|
43
|
-
url: `${paymentMethodsUrl}/approval-url`,
|
|
44
|
-
model: {
|
|
45
|
-
setup: { transaction },
|
|
46
|
-
},
|
|
47
|
-
close: ({
|
|
48
|
-
transaction: updatedTransaction = transaction,
|
|
49
|
-
}) => {
|
|
50
|
-
Events.setupCompleted.dispatch({
|
|
51
|
-
instrument,
|
|
52
|
-
transaction: updatedTransaction,
|
|
53
|
-
});
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
Events.setupCompleted.dispatch({ instrument, transaction });
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return { instrument, transaction };
|
|
62
|
-
} catch (error) {
|
|
63
|
-
showError(error);
|
|
64
|
-
return error;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { RenderMockRebillyInstruments } from 'tests/mocks/rebilly-instruments-mock';
|
|
2
|
-
import { ok, post } from 'msw-when-then';
|
|
3
|
-
import { when } from 'tests/msw/server';
|
|
4
|
-
import { storefrontURL } from 'tests/mocks/storefront-api-mock';
|
|
5
|
-
import Events from '../events';
|
|
6
|
-
import { avoidUnhandledPromises } from 'tests/async-utilities';
|
|
7
|
-
|
|
8
|
-
describe('RebillyInstruments setup', () => {
|
|
9
|
-
it('should be able to setup a payment instrument', async () => {
|
|
10
|
-
const options = {
|
|
11
|
-
websiteId: 'test-website-id',
|
|
12
|
-
money: {
|
|
13
|
-
amount: 30,
|
|
14
|
-
currency: 'USD',
|
|
15
|
-
},
|
|
16
|
-
transactionType: 'setup',
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const token = {
|
|
20
|
-
id: 'test-token-id',
|
|
21
|
-
};
|
|
22
|
-
const billingAddress = {
|
|
23
|
-
billing: 'address',
|
|
24
|
-
};
|
|
25
|
-
const deliveryAddress = {
|
|
26
|
-
delivery: 'address',
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const paymentInstrumentFields = {
|
|
30
|
-
id: 'payment-instrument-id',
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const paymentInstrumentSetupFields = {
|
|
34
|
-
id: 'payment-instrument-id',
|
|
35
|
-
approvalUrl: null,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
when(post(`${storefrontURL}/payment-instruments`)).thenReturn(
|
|
39
|
-
ok(paymentInstrumentFields),
|
|
40
|
-
);
|
|
41
|
-
when(post(`${storefrontURL}/payment-instruments/*/setup`)).thenReturn(
|
|
42
|
-
ok(paymentInstrumentSetupFields),
|
|
43
|
-
);
|
|
44
|
-
const rebillyInstruments = await RenderMockRebillyInstruments(options);
|
|
45
|
-
|
|
46
|
-
const spyCreatePaymentInstrument = vi.spyOn(
|
|
47
|
-
rebillyInstruments.state.storefront.paymentInstruments,
|
|
48
|
-
'create',
|
|
49
|
-
);
|
|
50
|
-
const spySetupPaymentInstrument = vi.spyOn(
|
|
51
|
-
rebillyInstruments.state.storefront.paymentInstruments,
|
|
52
|
-
'setup',
|
|
53
|
-
);
|
|
54
|
-
const spyDispatchSetupCompleted = vi.spyOn(
|
|
55
|
-
Events.setupCompleted,
|
|
56
|
-
'dispatch',
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
const setupCompletedListener = vi.fn();
|
|
60
|
-
|
|
61
|
-
rebillyInstruments.on('setup-completed', setupCompletedListener);
|
|
62
|
-
|
|
63
|
-
const setupPayload = {
|
|
64
|
-
billingAddress,
|
|
65
|
-
deliveryAddress,
|
|
66
|
-
...options.money,
|
|
67
|
-
_raw: token,
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
rebillyInstruments.mock.data({
|
|
71
|
-
previewPurchase: {
|
|
72
|
-
currency: 'USD',
|
|
73
|
-
total: 30,
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
await rebillyInstruments.setup(setupPayload);
|
|
78
|
-
|
|
79
|
-
expect(spyCreatePaymentInstrument).toBeCalledTimes(1);
|
|
80
|
-
expect(spyCreatePaymentInstrument).toBeCalledWith(
|
|
81
|
-
expect.objectContaining({
|
|
82
|
-
data: expect.objectContaining({
|
|
83
|
-
token: token.id,
|
|
84
|
-
}),
|
|
85
|
-
}),
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
expect(spySetupPaymentInstrument).toBeCalledTimes(1);
|
|
89
|
-
expect(spySetupPaymentInstrument).toBeCalledWith(
|
|
90
|
-
expect.objectContaining({
|
|
91
|
-
id: expect.stringContaining(paymentInstrumentFields.id),
|
|
92
|
-
data: expect.objectContaining({
|
|
93
|
-
websiteId: rebillyInstruments.state.options.websiteId,
|
|
94
|
-
currency: 'USD',
|
|
95
|
-
amount: 30,
|
|
96
|
-
}),
|
|
97
|
-
}),
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
expect(spyDispatchSetupCompleted).toBeCalledTimes(1);
|
|
101
|
-
|
|
102
|
-
expect(setupCompletedListener).toBeCalledTimes(1);
|
|
103
|
-
expect(setupCompletedListener).toBeCalledWith(
|
|
104
|
-
expect.objectContaining({
|
|
105
|
-
instrument: paymentInstrumentFields,
|
|
106
|
-
transaction: paymentInstrumentSetupFields,
|
|
107
|
-
}),
|
|
108
|
-
);
|
|
109
|
-
await avoidUnhandledPromises();
|
|
110
|
-
});
|
|
111
|
-
});
|
package/src/functions/show.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { mountConfirmation } from '../views/confirmation';
|
|
2
|
-
import { mountResult } from '../views/result';
|
|
3
|
-
import { hideExtraUI as hideMethodSelectorUI } from '../views/method-selector';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
@typedef ShowParams
|
|
7
|
-
@type {Object}
|
|
8
|
-
@property {string} componentName - The name of the component to render to the form.
|
|
9
|
-
@property {object} payload - The extra data to provide the component.
|
|
10
|
-
@property {object} state - The global state.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Register events that will be triggered
|
|
15
|
-
* @param {ShowParams} params
|
|
16
|
-
*/
|
|
17
|
-
export async function show({ componentName, payload }) {
|
|
18
|
-
switch (componentName) {
|
|
19
|
-
case 'result':
|
|
20
|
-
hideMethodSelectorUI();
|
|
21
|
-
mountResult({ payload });
|
|
22
|
-
break;
|
|
23
|
-
case 'confirmation':
|
|
24
|
-
hideMethodSelectorUI();
|
|
25
|
-
mountConfirmation({ payload });
|
|
26
|
-
break;
|
|
27
|
-
default:
|
|
28
|
-
throw new Error(`'${componentName}' not a supported component`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import * as result from '@/views/result';
|
|
2
|
-
import * as confirmation from '@/views/confirmation';
|
|
3
|
-
import { RebillyInstrumentsInstance } from '@/instance';
|
|
4
|
-
import iframes from '@/state/iframes';
|
|
5
|
-
|
|
6
|
-
const iframeMock = { destroy: vi.fn() };
|
|
7
|
-
|
|
8
|
-
describe('RebillyInstruments show', () => {
|
|
9
|
-
it('should show result component', async () => {
|
|
10
|
-
const mountResult = vi
|
|
11
|
-
.spyOn(result, 'mountResult')
|
|
12
|
-
.mockReturnValue(Promise.resolve());
|
|
13
|
-
|
|
14
|
-
const instance = new RebillyInstrumentsInstance();
|
|
15
|
-
|
|
16
|
-
const payload = {
|
|
17
|
-
test: 'value',
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
await instance.show('result', payload);
|
|
21
|
-
|
|
22
|
-
expect(mountResult).toBeCalledTimes(1);
|
|
23
|
-
expect(mountResult).toBeCalledWith(
|
|
24
|
-
expect.objectContaining({ payload }),
|
|
25
|
-
);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should show confirmation component', async () => {
|
|
29
|
-
const mountConfirmation = vi
|
|
30
|
-
.spyOn(confirmation, 'mountConfirmation')
|
|
31
|
-
.mockReturnValue(Promise.resolve());
|
|
32
|
-
|
|
33
|
-
const instance = new RebillyInstrumentsInstance();
|
|
34
|
-
iframes.form = iframeMock;
|
|
35
|
-
|
|
36
|
-
const payload = {
|
|
37
|
-
test: 'value',
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
await instance.show('confirmation', payload);
|
|
41
|
-
|
|
42
|
-
expect(mountConfirmation).toBeCalledTimes(1);
|
|
43
|
-
expect(mountConfirmation).toBeCalledWith(
|
|
44
|
-
expect.objectContaining({ payload }),
|
|
45
|
-
);
|
|
46
|
-
expect(iframes.form).toEqual(iframeMock);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('should fail for non supported component', async () => {
|
|
50
|
-
const rebillyInstruments = new RebillyInstrumentsInstance();
|
|
51
|
-
|
|
52
|
-
let error;
|
|
53
|
-
try {
|
|
54
|
-
await rebillyInstruments.show('not-a-component', 'any payload');
|
|
55
|
-
} catch (e) {
|
|
56
|
-
error = e;
|
|
57
|
-
}
|
|
58
|
-
expect(error.toString()).toBe(
|
|
59
|
-
`Error: 'not-a-component' not a supported component`,
|
|
60
|
-
);
|
|
61
|
-
});
|
|
62
|
-
});
|
package/src/functions/update.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import merge from 'lodash.merge';
|
|
2
|
-
import state from '../state';
|
|
3
|
-
import { destroy } from './destroy';
|
|
4
|
-
import { mount } from './mount';
|
|
5
|
-
|
|
6
|
-
export async function update({ newOptions = {} }) {
|
|
7
|
-
if (!state.hasMounted) {
|
|
8
|
-
throw Error(
|
|
9
|
-
'Update method cannot be called before mounting instruments',
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Framepay locale option is almost but not fully updatable yet:
|
|
15
|
-
* https://github.com/Rebilly/framepay/issues/450
|
|
16
|
-
* That's why this toggle disables real time locale update until that issue is fixed.
|
|
17
|
-
*/
|
|
18
|
-
// const updatingJustLocale =
|
|
19
|
-
// newOptions?.options && isEqual(Object.keys(newOptions), ['locale']);
|
|
20
|
-
// if (updatingJustLocale) {
|
|
21
|
-
// const updatedOptions = merge(state.options, newOptions);
|
|
22
|
-
// const newLocale = newOptions?.locale;
|
|
23
|
-
// state.options = updatedOptions;
|
|
24
|
-
// state.translate.updateTranslationsToNewLocale(newLocale);
|
|
25
|
-
// state.iframeComponents.forEach((iframe) =>
|
|
26
|
-
// iframe.component.call('changeLocale', newLocale)
|
|
27
|
-
// );
|
|
28
|
-
// return;
|
|
29
|
-
// }
|
|
30
|
-
|
|
31
|
-
const updatedOptions = merge({ ...state.options }, newOptions);
|
|
32
|
-
|
|
33
|
-
await destroy();
|
|
34
|
-
|
|
35
|
-
mount({
|
|
36
|
-
form: state.form,
|
|
37
|
-
summary: state.summary,
|
|
38
|
-
...updatedOptions,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { RenderMockRebillyInstruments } from 'tests/mocks/rebilly-instruments-mock';
|
|
2
|
-
import { avoidUnhandledPromises } from 'tests/async-utilities';
|
|
3
|
-
import iframes from '@/state/iframes';
|
|
4
|
-
|
|
5
|
-
describe('RebillyInstruments Update', () => {
|
|
6
|
-
it('should throw an error when methods are not mounted', async () => {
|
|
7
|
-
const rebillyInstruments = await RenderMockRebillyInstruments();
|
|
8
|
-
|
|
9
|
-
rebillyInstruments.state.hasMounted = false;
|
|
10
|
-
|
|
11
|
-
let error;
|
|
12
|
-
try {
|
|
13
|
-
await rebillyInstruments.update();
|
|
14
|
-
} catch (e) {
|
|
15
|
-
error = e;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
expect(error).toEqual(
|
|
19
|
-
new Error(
|
|
20
|
-
'Update method cannot be called before mounting instruments',
|
|
21
|
-
),
|
|
22
|
-
);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
// TODO: Un skip this test when we activate real time update (currently disabled by feature toggle in update.js)
|
|
26
|
-
it.skip('should call changeLocale when updating locale options', async () => {
|
|
27
|
-
const rebillyInstruments = await RenderMockRebillyInstruments();
|
|
28
|
-
|
|
29
|
-
const call = vi.fn();
|
|
30
|
-
// Simulate mounted iframe
|
|
31
|
-
const fakeIFrameComponent = {
|
|
32
|
-
destroy: vi.fn(),
|
|
33
|
-
component: {
|
|
34
|
-
call,
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
iframes.form = fakeIFrameComponent;
|
|
38
|
-
|
|
39
|
-
await rebillyInstruments.update({ locale: 'ja' });
|
|
40
|
-
|
|
41
|
-
expect(call).toBeCalledWith('changeLocale', 'ja');
|
|
42
|
-
// It would be better to match real UI instead of implementation state
|
|
43
|
-
expect(rebillyInstruments.state.options.locale).toBe('ja');
|
|
44
|
-
expect(rebillyInstruments.state.translate.locale).toBe('ja');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should destroy and update when updating options different than locale', async () => {
|
|
48
|
-
const rebillyInstruments = await RenderMockRebillyInstruments();
|
|
49
|
-
const formElement = document.querySelector('.form-selector');
|
|
50
|
-
const summaryElement = document.querySelector('.summary-selector');
|
|
51
|
-
|
|
52
|
-
expect(formElement.innerHTML).not.toEqual('');
|
|
53
|
-
expect(summaryElement.innerHTML).not.toEqual('');
|
|
54
|
-
|
|
55
|
-
const call = vi.fn();
|
|
56
|
-
// Simulate mounted iframe
|
|
57
|
-
const fakeIFrameComponent = {
|
|
58
|
-
destroy: vi.fn(),
|
|
59
|
-
component: {
|
|
60
|
-
call,
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
iframes.form = fakeIFrameComponent;
|
|
64
|
-
|
|
65
|
-
await rebillyInstruments.update({
|
|
66
|
-
countryCode: 'ES',
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
expect(rebillyInstruments.state.options.countryCode).toEqual('ES');
|
|
70
|
-
await avoidUnhandledPromises();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should replace the items with different options', async () => {
|
|
74
|
-
const rebillyInstruments = await RenderMockRebillyInstruments();
|
|
75
|
-
const formElement = document.querySelector('.form-selector');
|
|
76
|
-
const summaryElement = document.querySelector('.summary-selector');
|
|
77
|
-
|
|
78
|
-
expect(formElement.innerHTML).not.toEqual('');
|
|
79
|
-
expect(summaryElement.innerHTML).not.toEqual('');
|
|
80
|
-
|
|
81
|
-
const call = vi.fn();
|
|
82
|
-
// Simulate mounted iframe
|
|
83
|
-
const fakeIFrameComponent = {
|
|
84
|
-
destroy: vi.fn(),
|
|
85
|
-
component: {
|
|
86
|
-
call,
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
iframes.form = fakeIFrameComponent;
|
|
91
|
-
|
|
92
|
-
await rebillyInstruments.update({
|
|
93
|
-
items: [
|
|
94
|
-
{
|
|
95
|
-
planId: 'test-plan-id-1',
|
|
96
|
-
quantity: 5,
|
|
97
|
-
},
|
|
98
|
-
],
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
expect(rebillyInstruments.state.options.items[0].quantity).toEqual(5);
|
|
102
|
-
await avoidUnhandledPromises();
|
|
103
|
-
});
|
|
104
|
-
});
|