@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,353 +0,0 @@
|
|
|
1
|
-
import { RebillyInstrumentsConfigError } from '../../data/options-schema';
|
|
2
|
-
import setupOptions, {
|
|
3
|
-
handleComputedProperty,
|
|
4
|
-
handleNestedPropertiesDefaultValues,
|
|
5
|
-
handleJwtDestructuring,
|
|
6
|
-
} from './setup-options';
|
|
7
|
-
|
|
8
|
-
describe('Setup options function', () => {
|
|
9
|
-
it.skip('should throw error when options are invalid', () => {
|
|
10
|
-
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
11
|
-
|
|
12
|
-
expect(() => setupOptions()).toThrow(RebillyInstrumentsConfigError);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it.skip('should expect only one purchase data', () => {
|
|
16
|
-
const errorLogs = [];
|
|
17
|
-
vi.spyOn(console, 'error').mockImplementation((error) => {
|
|
18
|
-
if (typeof error === 'object') {
|
|
19
|
-
errorLogs.push(error.message);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const options = {
|
|
24
|
-
apiMode: 'sandbox',
|
|
25
|
-
items: [
|
|
26
|
-
{
|
|
27
|
-
planId: 'plan_TEST',
|
|
28
|
-
quantity: 1,
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
money: {
|
|
32
|
-
amount: 1.99,
|
|
33
|
-
currency: 'USD',
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
expect(() => setupOptions({ options })).toThrow(
|
|
37
|
-
RebillyInstrumentsConfigError,
|
|
38
|
-
);
|
|
39
|
-
expect(errorLogs.length).toEqual(1);
|
|
40
|
-
expect(errorLogs[0]).toEqual(
|
|
41
|
-
'options must match exactly one schema in oneOf, see schemas below.',
|
|
42
|
-
);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should validate and inject default values', () => {
|
|
46
|
-
const testJwt =
|
|
47
|
-
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJqd3RfVEVTVC1BIiwiZXhwIjoxNzE0ODQwNDg5LCJpYXQiOjE2ODMyMTY1ODkuNTYwMjU2LCJhY2wiOlt7InNjb3BlIjp7Im9yZ2FuaXphdGlvbklkIjpbIm9yZ19URVNULUEiXSwiaW52b2ljZUlkIjpbImluX1RFU1QtQSJdLCJjdXN0b21GaWVsZE5hbWUiOlsiU0lOTGFzdDQiXX0sInBlcm1pc3Npb25zIjpbMjg0LDI4Niw0MTQsNDE1LDQzNCw0MTIsNDI0LDQyNSw0MjYsNDI3LDQyOCw0MjksNDA5LDQxMCw0MDEsNDAyLDQzMyw0MzFdfV0sImNsYWltcyI6eyJ3ZWJzaXRlSWQiOiJ3ZWJfVEVTVC1BIiwiaW52b2ljZUlkIjoiaW5fVEVTVC1BIiwicGF5bWVudE1ldGhvZHMiOltdfSwibWVyY2hhbnQiOiJNRVJDSEFOVC1URVNULUlELUEiLCJjdXN0b21lciI6eyJpZCI6ImN1c19URVNULUEiLCJuYW1lIjoiQ2FyZCBIb2xkZXIgTmFtZSIsImNyZWF0ZWRUaW1lIjoiMjAyMi0wOS0yMVQxODo1MDoyMiswMDowMCJ9fQ.tm33uioGUSpEedHeYufDGm-p1YW40eufNovppcU6-xg';
|
|
48
|
-
const options = {
|
|
49
|
-
jwt: testJwt,
|
|
50
|
-
apiMode: 'sandbox',
|
|
51
|
-
items: [
|
|
52
|
-
{
|
|
53
|
-
planId: 'plan_TEST',
|
|
54
|
-
quantity: {},
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const results = setupOptions({ options });
|
|
60
|
-
|
|
61
|
-
expect(results).toEqual({
|
|
62
|
-
jwt: testJwt,
|
|
63
|
-
apiMode: 'sandbox',
|
|
64
|
-
items: [
|
|
65
|
-
{
|
|
66
|
-
planId: 'plan_TEST',
|
|
67
|
-
quantity: {
|
|
68
|
-
minimum: 1,
|
|
69
|
-
maximum: Number.MAX_SAFE_INTEGER,
|
|
70
|
-
multipleOf: 1,
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
form: '.rebilly-instruments',
|
|
75
|
-
summary: '.rebilly-instruments-summary',
|
|
76
|
-
addons: [],
|
|
77
|
-
bumpOffer: [],
|
|
78
|
-
transactionType: 'purchase',
|
|
79
|
-
theme: { labels: 'stacked' },
|
|
80
|
-
countryCode: 'US',
|
|
81
|
-
locale: 'auto',
|
|
82
|
-
paymentInstruments: {
|
|
83
|
-
compactExpressInstruments: false,
|
|
84
|
-
address: {
|
|
85
|
-
name: 'default',
|
|
86
|
-
region: 'default',
|
|
87
|
-
show: [],
|
|
88
|
-
hide: [],
|
|
89
|
-
require: [],
|
|
90
|
-
},
|
|
91
|
-
paypal: { buttonHeight: 48 },
|
|
92
|
-
googlePay: {
|
|
93
|
-
displayOptions: {
|
|
94
|
-
buttonColor: 'black',
|
|
95
|
-
buttonHeight: '48px',
|
|
96
|
-
buttonType: 'plain',
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
applePay: {
|
|
100
|
-
displayOptions: {
|
|
101
|
-
buttonColor: 'black',
|
|
102
|
-
buttonHeight: '48px',
|
|
103
|
-
buttonType: 'plain',
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
paymentCard: { popup: false },
|
|
107
|
-
},
|
|
108
|
-
features: {
|
|
109
|
-
autoConfirmation: true,
|
|
110
|
-
autoResult: true,
|
|
111
|
-
fullPageRedirect: false,
|
|
112
|
-
},
|
|
113
|
-
_computed: {
|
|
114
|
-
paymentMethodsUrl: 'https://forms.secure-payments.app',
|
|
115
|
-
},
|
|
116
|
-
organizationId: 'MERCHANT-TEST-ID-A',
|
|
117
|
-
invoiceId: 'in_TEST-A',
|
|
118
|
-
websiteId: 'web_TEST-A',
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it.skip('should throw error for missing purchase data', () => {
|
|
123
|
-
const errorLogs = [];
|
|
124
|
-
vi.spyOn(console, 'error').mockImplementation((error) => {
|
|
125
|
-
if (typeof error === 'string') {
|
|
126
|
-
errorLogs.push(error);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
expect(() => setupOptions()).toThrow(RebillyInstrumentsConfigError);
|
|
131
|
-
expect(errorLogs.length).toEqual(6);
|
|
132
|
-
const expectedResults = [
|
|
133
|
-
'items',
|
|
134
|
-
'money',
|
|
135
|
-
'invoiceId',
|
|
136
|
-
'transactionId',
|
|
137
|
-
'deposit',
|
|
138
|
-
'jwt',
|
|
139
|
-
];
|
|
140
|
-
expectedResults.forEach((result) => {
|
|
141
|
-
it(`should expect required oneOf ${result}`, () => {
|
|
142
|
-
expect(
|
|
143
|
-
errorLogs.some((error) => {
|
|
144
|
-
return (
|
|
145
|
-
error.includes('required') && error.includes(result)
|
|
146
|
-
);
|
|
147
|
-
}),
|
|
148
|
-
).toEqual(true);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe('should ensure purchase data has dependant properties', () => {
|
|
154
|
-
let errorLogs = [];
|
|
155
|
-
beforeEach(() => {
|
|
156
|
-
errorLogs = [];
|
|
157
|
-
vi.spyOn(console, 'error').mockImplementation((error) => {
|
|
158
|
-
if (typeof error === 'object') {
|
|
159
|
-
errorLogs.push(error.message);
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
const expectJwtTests = [
|
|
165
|
-
{
|
|
166
|
-
invoiceId: 'in_TEST',
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
transactionId: 'txn_TEST',
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
deposit: {
|
|
173
|
-
depositRequestId: 'cash_req_TEST',
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
];
|
|
177
|
-
|
|
178
|
-
expectJwtTests.forEach((test) => {
|
|
179
|
-
const key = Object.keys(test)[0];
|
|
180
|
-
it.skip(`should expect jwt with ${key}`, () => {
|
|
181
|
-
const options = {
|
|
182
|
-
apiMode: 'sandbox',
|
|
183
|
-
...test,
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
expect(() => setupOptions({ options })).toThrow(
|
|
187
|
-
RebillyInstrumentsConfigError,
|
|
188
|
-
);
|
|
189
|
-
expect(errorLogs.length).toEqual(1);
|
|
190
|
-
expect(errorLogs[0]).toEqual(
|
|
191
|
-
`options must have property jwt when property ${key} is present`,
|
|
192
|
-
);
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
describe('Setup options handleComputedProperty function', () => {
|
|
199
|
-
it('should populate options with instrument methods url', () => {
|
|
200
|
-
const options = {};
|
|
201
|
-
const result = handleComputedProperty(options);
|
|
202
|
-
|
|
203
|
-
expect(result).toEqual({
|
|
204
|
-
_computed: {
|
|
205
|
-
paymentMethodsUrl: 'https://forms.secure-payments.app',
|
|
206
|
-
},
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it('should set paymentMethodsUrl from _dev configuration', () => {
|
|
211
|
-
const options = {
|
|
212
|
-
_dev: {
|
|
213
|
-
paymentMethodsUrl: 'https://www.example.com',
|
|
214
|
-
},
|
|
215
|
-
};
|
|
216
|
-
const result = handleComputedProperty(options);
|
|
217
|
-
|
|
218
|
-
expect(result._computed.paymentMethodsUrl).toEqual(
|
|
219
|
-
'https://www.example.com',
|
|
220
|
-
);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it('should default paymentMethodsUrl from empty _dev configuration', () => {
|
|
224
|
-
const options = {
|
|
225
|
-
_dev: {},
|
|
226
|
-
};
|
|
227
|
-
const result = handleComputedProperty(options);
|
|
228
|
-
|
|
229
|
-
expect(result._computed.paymentMethodsUrl).toEqual(
|
|
230
|
-
'https://forms.secure-payments.app',
|
|
231
|
-
);
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
describe('Setup options handleNestedPropertiesDefaultValues function', () => {
|
|
236
|
-
it.skip('should add defaults for deposits with currency configuration', () => {
|
|
237
|
-
const options = {
|
|
238
|
-
deposit: {
|
|
239
|
-
currency: 'USD',
|
|
240
|
-
},
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
const result = handleNestedPropertiesDefaultValues(options);
|
|
244
|
-
|
|
245
|
-
expect(result).toEqual({
|
|
246
|
-
deposit: {
|
|
247
|
-
editable: true,
|
|
248
|
-
buttons: [],
|
|
249
|
-
customAmount: {
|
|
250
|
-
minimum: 1,
|
|
251
|
-
maximum: 1000000000000,
|
|
252
|
-
increment: 1,
|
|
253
|
-
},
|
|
254
|
-
currency: 'USD',
|
|
255
|
-
},
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it.skip('should not inject defaults to deposit without currency', () => {
|
|
260
|
-
const options = {
|
|
261
|
-
deposit: {
|
|
262
|
-
depositRequestId: 'cash_req_TEST',
|
|
263
|
-
},
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
const result = handleNestedPropertiesDefaultValues(options);
|
|
267
|
-
expect(result).toEqual({
|
|
268
|
-
deposit: {
|
|
269
|
-
depositRequestId: 'cash_req_TEST',
|
|
270
|
-
},
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
it.skip('should add defaults to items with empty object for quantity', () => {
|
|
275
|
-
const options = {
|
|
276
|
-
items: [
|
|
277
|
-
{
|
|
278
|
-
planId: 'plan_TEST',
|
|
279
|
-
quantity: {},
|
|
280
|
-
},
|
|
281
|
-
],
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
const result = handleNestedPropertiesDefaultValues(options);
|
|
285
|
-
expect(result).toEqual({
|
|
286
|
-
items: [
|
|
287
|
-
{
|
|
288
|
-
planId: 'plan_TEST',
|
|
289
|
-
quantity: {
|
|
290
|
-
minimum: 0.1,
|
|
291
|
-
maximum: Number.MAX_SAFE_INTEGER,
|
|
292
|
-
multipleOf: 0.1,
|
|
293
|
-
},
|
|
294
|
-
},
|
|
295
|
-
],
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
describe('Setup options handleJwtDestructuring function', () => {
|
|
301
|
-
const testJwt =
|
|
302
|
-
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJqd3RfVEVTVC1BIiwiZXhwIjoxNzE0ODQwNDg5LCJpYXQiOjE2ODMyMTY1ODkuNTYwMjU2LCJhY2wiOlt7InNjb3BlIjp7Im9yZ2FuaXphdGlvbklkIjpbIm9yZ19URVNULUEiXSwiaW52b2ljZUlkIjpbImluX1RFU1QtQSJdLCJjdXN0b21GaWVsZE5hbWUiOlsiU0lOTGFzdDQiXX0sInBlcm1pc3Npb25zIjpbMjg0LDI4Niw0MTQsNDE1LDQzNCw0MTIsNDI0LDQyNSw0MjYsNDI3LDQyOCw0MjksNDA5LDQxMCw0MDEsNDAyLDQzMyw0MzFdfV0sImNsYWltcyI6eyJ3ZWJzaXRlSWQiOiJ3ZWJfVEVTVC1BIiwiaW52b2ljZUlkIjoiaW5fVEVTVC1BIiwicGF5bWVudE1ldGhvZHMiOltdfSwibWVyY2hhbnQiOiJNRVJDSEFOVC1URVNULUlELUEiLCJjdXN0b21lciI6eyJpZCI6ImN1c19URVNULUEiLCJuYW1lIjoiQ2FyZCBIb2xkZXIgTmFtZSIsImNyZWF0ZWRUaW1lIjoiMjAyMi0wOS0yMVQxODo1MDoyMiswMDowMCJ9fQ.tm33uioGUSpEedHeYufDGm-p1YW40eufNovppcU6-xg';
|
|
303
|
-
|
|
304
|
-
it('should destructure when jwt is present', () => {
|
|
305
|
-
const options = {
|
|
306
|
-
jwt: testJwt,
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
const result = handleJwtDestructuring(options);
|
|
310
|
-
expect(result).toEqual({
|
|
311
|
-
jwt: testJwt,
|
|
312
|
-
organizationId: 'MERCHANT-TEST-ID-A',
|
|
313
|
-
invoiceId: 'in_TEST-A',
|
|
314
|
-
websiteId: 'web_TEST-A',
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
it('should not destructure when publishableKey is supplied', () => {
|
|
319
|
-
const options = {
|
|
320
|
-
jwt: testJwt,
|
|
321
|
-
publishableKey: 'pk_sandbox_TEST',
|
|
322
|
-
organizationId: 'MERCHANT-TEST-ID-B',
|
|
323
|
-
invoiceId: 'in_TEST-B',
|
|
324
|
-
websiteId: 'web_TEST-B',
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
const result = handleJwtDestructuring(options);
|
|
328
|
-
expect(result).toEqual({
|
|
329
|
-
jwt: testJwt,
|
|
330
|
-
publishableKey: 'pk_sandbox_TEST',
|
|
331
|
-
organizationId: 'MERCHANT-TEST-ID-B',
|
|
332
|
-
invoiceId: 'in_TEST-B',
|
|
333
|
-
websiteId: 'web_TEST-B',
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
it('should use JWT values when publishableKey is missing', () => {
|
|
338
|
-
const options = {
|
|
339
|
-
jwt: testJwt,
|
|
340
|
-
organizationId: 'MERCHANT-TEST-ID-B',
|
|
341
|
-
invoiceId: 'in_TEST-B',
|
|
342
|
-
websiteId: 'web_TEST-B',
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
const result = handleJwtDestructuring(options);
|
|
346
|
-
expect(result).toEqual({
|
|
347
|
-
jwt: testJwt,
|
|
348
|
-
organizationId: 'MERCHANT-TEST-ID-A',
|
|
349
|
-
invoiceId: 'in_TEST-A',
|
|
350
|
-
websiteId: 'web_TEST-A',
|
|
351
|
-
});
|
|
352
|
-
});
|
|
353
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import Storefront from '../../storefront';
|
|
2
|
-
import state from '../../state';
|
|
3
|
-
|
|
4
|
-
export default () => {
|
|
5
|
-
const { publishableKey, organizationId, apiMode, _dev } = state.options;
|
|
6
|
-
|
|
7
|
-
const storefront = {
|
|
8
|
-
organizationId,
|
|
9
|
-
mode: apiMode || 'live',
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
if (publishableKey) {
|
|
13
|
-
storefront.publishableKey = publishableKey;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (_dev) {
|
|
17
|
-
storefront.liveUrl = _dev.liveUrl || 'https://api.rebilly.com';
|
|
18
|
-
storefront.sandboxUrl =
|
|
19
|
-
_dev.sandboxUrl || 'https://api-sandbox.rebilly.com';
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return Storefront(storefront);
|
|
23
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { mainStyleVars } from '../../style';
|
|
2
|
-
import { addDOMElement } from '../../utils';
|
|
3
|
-
import { minifyCss } from '../../style/utils/minifyCss';
|
|
4
|
-
import state from '../../state';
|
|
5
|
-
|
|
6
|
-
export default () => {
|
|
7
|
-
const { theme = {}, css } = state.options;
|
|
8
|
-
|
|
9
|
-
// Adds base CSS vars stylesheet
|
|
10
|
-
const styleVars = mainStyleVars(theme || {});
|
|
11
|
-
|
|
12
|
-
addDOMElement({
|
|
13
|
-
element: 'style',
|
|
14
|
-
attributes: { type: 'text/css' },
|
|
15
|
-
content: minifyCss(styleVars),
|
|
16
|
-
target: 'head',
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
// Adds options CSS to override any styles
|
|
20
|
-
if (css) {
|
|
21
|
-
addDOMElement({
|
|
22
|
-
element: 'style',
|
|
23
|
-
attributes: { type: 'text/css' },
|
|
24
|
-
content: minifyCss(css),
|
|
25
|
-
target: 'head',
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return styleVars;
|
|
30
|
-
};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { on } from '../on';
|
|
2
|
-
import { show } from '../show';
|
|
3
|
-
import { purchase } from '../purchase';
|
|
4
|
-
import { setup } from '../setup';
|
|
5
|
-
|
|
6
|
-
function showResult({ state, payload }) {
|
|
7
|
-
show({
|
|
8
|
-
componentName: 'result',
|
|
9
|
-
payload,
|
|
10
|
-
state,
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default ({ state = {} }) => {
|
|
15
|
-
if (state.options.features.autoConfirmation) {
|
|
16
|
-
on({
|
|
17
|
-
eventName: 'instrument-ready',
|
|
18
|
-
callback: (payload) => {
|
|
19
|
-
// Alternate flow for paypal.
|
|
20
|
-
if (payload._raw?.method === 'paypal') {
|
|
21
|
-
if (!state.data.isShippingRequired) {
|
|
22
|
-
if (state.options.transactionType === 'setup') {
|
|
23
|
-
setup({ state, payload });
|
|
24
|
-
} else {
|
|
25
|
-
purchase({ state, payload });
|
|
26
|
-
}
|
|
27
|
-
state.loader.startLoading({
|
|
28
|
-
state,
|
|
29
|
-
id: 'express-purchase',
|
|
30
|
-
message: 'form.loaderMessages.processingPayment',
|
|
31
|
-
});
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
show({
|
|
36
|
-
componentName: 'confirmation',
|
|
37
|
-
payload,
|
|
38
|
-
state,
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (state.options.features.autoResult) {
|
|
45
|
-
on({
|
|
46
|
-
eventName: 'purchase-completed',
|
|
47
|
-
callback: (payload) => {
|
|
48
|
-
payload = JSON.parse(JSON.stringify(payload));
|
|
49
|
-
showResult({ state, payload });
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
on({
|
|
53
|
-
eventName: 'setup-completed',
|
|
54
|
-
callback: (payload) => {
|
|
55
|
-
payload = JSON.parse(JSON.stringify(payload));
|
|
56
|
-
showResult({ state, payload });
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
};
|
package/src/functions/on.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import camelCase from 'lodash.camelcase';
|
|
2
|
-
import Events, { publicEventNames } from '../events';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
@typedef OnParams
|
|
6
|
-
@type {Object}
|
|
7
|
-
@property {string} eventName - The name of the event
|
|
8
|
-
@property {function} callback - The function that is triggered by the event.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Register events that will be triggered
|
|
13
|
-
* @param {OnParams} params
|
|
14
|
-
*/
|
|
15
|
-
export function on({ eventName, callback }) {
|
|
16
|
-
if (!publicEventNames.includes(eventName)) {
|
|
17
|
-
throw new Error(`${eventName} is not a supported event`);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const internalEventName = camelCase(eventName);
|
|
21
|
-
Events[internalEventName].addEventListener(callback);
|
|
22
|
-
}
|
package/src/functions/on.spec.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import camelCase from 'lodash.camelcase';
|
|
2
|
-
import { RenderMockRebillyInstruments } from 'tests/mocks/rebilly-instruments-mock';
|
|
3
|
-
import { RebillyInstrumentsInstance } from '@/instance';
|
|
4
|
-
import Events from '@/events';
|
|
5
|
-
import iframes from '@/state/iframes';
|
|
6
|
-
|
|
7
|
-
describe('RebillyInstruments on', () => {
|
|
8
|
-
it('should register event listeners', async () => {
|
|
9
|
-
const rebillyInstruments = await RenderMockRebillyInstruments();
|
|
10
|
-
const publicEventNames = ['instrument-ready', 'purchase-completed'];
|
|
11
|
-
|
|
12
|
-
await Promise.all(
|
|
13
|
-
publicEventNames.map(async (eventName) => {
|
|
14
|
-
const callback = vi.fn();
|
|
15
|
-
rebillyInstruments.on(eventName, callback);
|
|
16
|
-
|
|
17
|
-
const details = {
|
|
18
|
-
test: 'data',
|
|
19
|
-
};
|
|
20
|
-
Events[camelCase(eventName)].dispatch(details);
|
|
21
|
-
|
|
22
|
-
expect(callback).toBeCalledTimes(1);
|
|
23
|
-
expect(callback).toBeCalledWith(details);
|
|
24
|
-
}),
|
|
25
|
-
);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should throw error for internal namespaced events', async () => {
|
|
29
|
-
const callback = vi.fn();
|
|
30
|
-
const instance = new RebillyInstrumentsInstance();
|
|
31
|
-
const iframeMock = {
|
|
32
|
-
component: {
|
|
33
|
-
call: vi.fn(),
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
iframes.form = iframeMock;
|
|
37
|
-
|
|
38
|
-
let error;
|
|
39
|
-
try {
|
|
40
|
-
// rebilly-instruments-purchase-completed will be used internally but not available externally
|
|
41
|
-
await instance.on(
|
|
42
|
-
'rebilly-instruments-purchase-completed',
|
|
43
|
-
callback,
|
|
44
|
-
);
|
|
45
|
-
} catch (e) {
|
|
46
|
-
error = e;
|
|
47
|
-
}
|
|
48
|
-
expect(error).toEqual(
|
|
49
|
-
new Error(
|
|
50
|
-
'rebilly-instruments-purchase-completed is not a supported event',
|
|
51
|
-
),
|
|
52
|
-
);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should throw error for a non defined event', async () => {
|
|
56
|
-
const callback = vi.fn();
|
|
57
|
-
const instance = new RebillyInstrumentsInstance();
|
|
58
|
-
const iframeMock = {
|
|
59
|
-
component: {
|
|
60
|
-
call: vi.fn(),
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
iframes.form = iframeMock;
|
|
64
|
-
|
|
65
|
-
let error;
|
|
66
|
-
try {
|
|
67
|
-
await instance.on('not-an-event', callback);
|
|
68
|
-
} catch (e) {
|
|
69
|
-
error = e;
|
|
70
|
-
}
|
|
71
|
-
expect(error).toEqual(
|
|
72
|
-
new Error('not-an-event is not a supported event'),
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
});
|