@rebilly/instruments 4.5.0 → 4.7.0
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/.babelrc +24 -26
- package/CHANGELOG.md +14 -0
- package/dist/index.js +8 -8
- package/dist/index.min.js +8 -8
- package/package.json +14 -3
- package/project.json +9 -0
- package/rollup.config.mjs +21 -26
- package/src/data/options-schema/index.js +94 -78
- package/src/data/options-schema/schemas/options-schema.js +419 -411
- package/src/events/base-event.js +34 -34
- package/src/events/events.spec.js +6 -6
- package/src/events/index.js +5 -5
- package/src/functions/destroy.js +19 -19
- package/src/functions/destroy.spec.js +41 -41
- package/src/functions/mount/fetch-data.js +200 -193
- package/src/functions/mount/fetch-data.spec.js +287 -285
- package/src/functions/mount/get-lead-source-data.js +31 -31
- package/src/functions/mount/get-lead-source-data.spec.js +19 -19
- package/src/functions/mount/index.js +73 -65
- package/src/functions/mount/mount.spec.js +77 -66
- package/src/functions/mount/setup-element.js +23 -23
- package/src/functions/mount/setup-framepay-theme.js +86 -68
- package/src/functions/mount/setup-framepay.js +9 -5
- package/src/functions/mount/setup-i18n.js +15 -15
- package/src/functions/mount/setup-options.js +74 -74
- package/src/functions/mount/setup-options.spec.js +323 -287
- package/src/functions/mount/setup-storefront.js +15 -20
- package/src/functions/mount/setup-styles-vars.js +19 -22
- package/src/functions/mount/setup-user-flow.js +51 -47
- package/src/functions/on.js +5 -5
- package/src/functions/on.spec.js +60 -51
- package/src/functions/purchase.js +151 -146
- package/src/functions/purchase.spec.js +59 -56
- package/src/functions/setup.js +53 -53
- package/src/functions/setup.spec.js +88 -75
- package/src/functions/show.js +13 -14
- package/src/functions/show.spec.js +53 -53
- package/src/functions/update.js +30 -28
- package/src/functions/update.spec.js +94 -93
- package/src/i18n/en.json +32 -32
- package/src/i18n/es.json +29 -29
- package/src/i18n/i18n.spec.js +18 -18
- package/src/i18n/index.js +48 -48
- package/src/instance.js +36 -36
- package/src/instance.spec.js +29 -27
- package/src/loader/index.js +95 -70
- package/src/loader/loader.spec.js +63 -63
- package/src/state/iframes.js +21 -21
- package/src/state/index.js +56 -54
- package/src/storefront/account-and-website.js +10 -8
- package/src/storefront/account-and-website.spec.js +55 -55
- package/src/storefront/deposit-requests.js +6 -6
- package/src/storefront/fetch-plans-from-addons-bumpOffer.js +21 -19
- package/src/storefront/fetch-products-from-plans.js +52 -51
- package/src/storefront/fetch-products-from-plans.spec.js +90 -87
- package/src/storefront/index.js +56 -49
- package/src/storefront/invoices.js +15 -15
- package/src/storefront/invoices.spec.js +69 -65
- package/src/storefront/models/account-model.js +29 -32
- package/src/storefront/models/base-model.js +6 -9
- package/src/storefront/models/deposit-request-model.js +22 -13
- package/src/storefront/models/invoice-model.js +16 -16
- package/src/storefront/models/payment-metadata.js +4 -4
- package/src/storefront/models/plan-model.js +73 -64
- package/src/storefront/models/ready-to-pay-model.js +59 -59
- package/src/storefront/models/summary-model.js +43 -46
- package/src/storefront/models/transaction-model.js +11 -14
- package/src/storefront/payment-instruments.js +38 -35
- package/src/storefront/payment-instruments.spec.js +81 -62
- package/src/storefront/purchase.js +50 -44
- package/src/storefront/purchase.spec.js +40 -40
- package/src/storefront/ready-to-pay.js +75 -77
- package/src/storefront/ready-to-pay.spec.js +59 -54
- package/src/storefront/storefront.spec.js +9 -9
- package/src/storefront/summary.js +93 -67
- package/src/storefront/summary.spec.js +108 -106
- package/src/storefront/transactions.js +6 -6
- package/src/style/base/default-theme.js +928 -923
- package/src/style/base/theme.js +21 -21
- package/src/style/base/theme.spec.js +13 -13
- package/src/style/index.js +3 -3
- package/src/style/utils/border.js +40 -27
- package/src/style/utils/color-values.js +18 -18
- package/src/style/utils/minifyCss.js +6 -6
- package/src/utils/add-dom-element.js +14 -14
- package/src/utils/format-currency.js +6 -5
- package/src/utils/has-valid-css-selector.js +2 -2
- package/src/utils/index.js +6 -6
- package/src/utils/is-dom-element.js +1 -1
- package/src/utils/process-property-as-dom-element.js +22 -22
- package/src/utils/quantity.js +26 -28
- package/src/utils/sleep.js +3 -1
- package/src/views/amount-selector.js +37 -36
- package/src/views/common/iframe/base-iframe.js +53 -52
- package/src/views/common/iframe/events/change-iframe-src-handler.js +5 -5
- package/src/views/common/iframe/events/dispatch-event-handler.js +4 -4
- package/src/views/common/iframe/events/resize-component-handler.js +8 -8
- package/src/views/common/iframe/events/show-error-handler.js +2 -2
- package/src/views/common/iframe/events/stop-loader-handler.js +8 -8
- package/src/views/common/iframe/events/update-addons-handler.js +20 -13
- package/src/views/common/iframe/events/update-coupons-handler.js +9 -9
- package/src/views/common/iframe/events/update-items-handler.js +26 -22
- package/src/views/common/iframe/modal-iframe.js +67 -56
- package/src/views/common/iframe/view-iframe.js +11 -11
- package/src/views/common/render-utilities.js +2 -2
- package/src/views/confirmation.js +33 -30
- package/src/views/errors.js +89 -79
- package/src/views/form.js +41 -37
- package/src/views/method-selector/express-methods.js +46 -46
- package/src/views/method-selector/generate-digital-wallet.js +46 -45
- package/src/views/method-selector/generate-digital-wallet.spec.js +104 -102
- package/src/views/method-selector/generate-framepay-config.js +53 -51
- package/src/views/method-selector/generate-framepay-config.spec.js +197 -173
- package/src/views/method-selector/get-method-data.js +5 -6
- package/src/views/method-selector/get-payment-methods.js +18 -16
- package/src/views/method-selector/get-payment-methods.spec.js +29 -27
- package/src/views/method-selector/index.js +154 -139
- package/src/views/method-selector/method-selector.spec.js +13 -13
- package/src/views/method-selector/mount-bump-offer.js +65 -49
- package/src/views/method-selector/mount-express-methods.js +89 -85
- package/src/views/modal.js +74 -67
- package/src/views/result.js +14 -14
- package/src/views/summary.js +25 -26
- package/tests/async-utilities.js +13 -13
- package/tests/mocks/framepay-mock.js +9 -8
- package/tests/mocks/rebilly-api-mock.js +5 -3
- package/tests/mocks/rebilly-instruments-mock.js +121 -117
- package/tests/mocks/storefront-api-mock.js +55 -48
- package/tests/mocks/storefront-mock.js +10 -14
- package/tests/msw/server.js +6 -6
- package/tests/setup-test.js +14 -16
- package/vitest.config.js +14 -14
- package/.eslintrc.js +0 -34
- package/.prettierrc.js +0 -11
|
@@ -1,317 +1,353 @@
|
|
|
1
1
|
import { RebillyInstrumentsConfigError } from '../../data/options-schema';
|
|
2
2
|
import setupOptions, {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
handleComputedProperty,
|
|
4
|
+
handleNestedPropertiesDefaultValues,
|
|
5
|
+
handleJwtDestructuring,
|
|
6
6
|
} from './setup-options';
|
|
7
7
|
|
|
8
8
|
describe('Setup options function', () => {
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
});
|
|
9
|
+
it.skip('should throw error when options are invalid', () => {
|
|
10
|
+
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
22
11
|
|
|
23
|
-
|
|
24
|
-
apiMode: 'sandbox',
|
|
25
|
-
items: [{
|
|
26
|
-
planId: 'plan_TEST',
|
|
27
|
-
quantity: 1
|
|
28
|
-
}],
|
|
29
|
-
money: {
|
|
30
|
-
amount: 1.99,
|
|
31
|
-
currency: 'USD'
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
expect(() => setupOptions({options})).toThrow(RebillyInstrumentsConfigError);
|
|
35
|
-
expect(errorLogs.length).toEqual(1);
|
|
36
|
-
expect(errorLogs[0]).toEqual('options must match exactly one schema in oneOf, see schemas below.');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should validate and inject default values', () => {
|
|
40
|
-
const testJwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJqd3RfVEVTVC1BIiwiZXhwIjoxNzE0ODQwNDg5LCJpYXQiOjE2ODMyMTY1ODkuNTYwMjU2LCJhY2wiOlt7InNjb3BlIjp7Im9yZ2FuaXphdGlvbklkIjpbIm9yZ19URVNULUEiXSwiaW52b2ljZUlkIjpbImluX1RFU1QtQSJdLCJjdXN0b21GaWVsZE5hbWUiOlsiU0lOTGFzdDQiXX0sInBlcm1pc3Npb25zIjpbMjg0LDI4Niw0MTQsNDE1LDQzNCw0MTIsNDI0LDQyNSw0MjYsNDI3LDQyOCw0MjksNDA5LDQxMCw0MDEsNDAyLDQzMyw0MzFdfV0sImNsYWltcyI6eyJ3ZWJzaXRlSWQiOiJ3ZWJfVEVTVC1BIiwiaW52b2ljZUlkIjoiaW5fVEVTVC1BIiwicGF5bWVudE1ldGhvZHMiOltdfSwibWVyY2hhbnQiOiJNRVJDSEFOVC1URVNULUlELUEiLCJjdXN0b21lciI6eyJpZCI6ImN1c19URVNULUEiLCJuYW1lIjoiQ2FyZCBIb2xkZXIgTmFtZSIsImNyZWF0ZWRUaW1lIjoiMjAyMi0wOS0yMVQxODo1MDoyMiswMDowMCJ9fQ.tm33uioGUSpEedHeYufDGm-p1YW40eufNovppcU6-xg';
|
|
41
|
-
const options = {
|
|
42
|
-
jwt: testJwt,
|
|
43
|
-
apiMode: 'sandbox',
|
|
44
|
-
items: [{
|
|
45
|
-
planId: 'plan_TEST',
|
|
46
|
-
quantity: {},
|
|
47
|
-
}]
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const results = setupOptions({options});
|
|
51
|
-
|
|
52
|
-
expect(results).toEqual({
|
|
53
|
-
jwt: testJwt,
|
|
54
|
-
apiMode: 'sandbox',
|
|
55
|
-
items: [{
|
|
56
|
-
planId: 'plan_TEST',
|
|
57
|
-
quantity: {
|
|
58
|
-
minimum: 1,
|
|
59
|
-
maximum: Number.MAX_SAFE_INTEGER,
|
|
60
|
-
multipleOf: 1
|
|
61
|
-
}
|
|
62
|
-
}],
|
|
63
|
-
form: '.rebilly-instruments',
|
|
64
|
-
summary: '.rebilly-instruments-summary',
|
|
65
|
-
addons: [],
|
|
66
|
-
bumpOffer: [],
|
|
67
|
-
transactionType: 'purchase',
|
|
68
|
-
theme: { labels: 'stacked' },
|
|
69
|
-
countryCode: 'US',
|
|
70
|
-
locale: 'auto',
|
|
71
|
-
paymentInstruments: {
|
|
72
|
-
compactExpressInstruments: false,
|
|
73
|
-
address: {
|
|
74
|
-
name: 'default',
|
|
75
|
-
region: 'default',
|
|
76
|
-
show: [],
|
|
77
|
-
hide: [],
|
|
78
|
-
require: []
|
|
79
|
-
},
|
|
80
|
-
paypal: { buttonHeight: 48 },
|
|
81
|
-
googlePay: {
|
|
82
|
-
displayOptions: {
|
|
83
|
-
buttonColor: 'black',
|
|
84
|
-
buttonHeight: '48px',
|
|
85
|
-
buttonType: 'plain'
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
applePay: {
|
|
89
|
-
displayOptions: {
|
|
90
|
-
buttonColor: 'black',
|
|
91
|
-
buttonHeight: '48px',
|
|
92
|
-
buttonType: 'plain'
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
paymentCard: { popup: false }
|
|
96
|
-
},
|
|
97
|
-
features: { autoConfirmation: true, autoResult: true, fullPageRedirect: false },
|
|
98
|
-
_computed: { paymentMethodsUrl: 'https://forms.secure-payments.app' },
|
|
99
|
-
organizationId: 'MERCHANT-TEST-ID-A',
|
|
100
|
-
invoiceId: 'in_TEST-A',
|
|
101
|
-
websiteId: 'web_TEST-A'
|
|
102
|
-
});
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
it.skip ('should throw error for missing purchase data', () => {
|
|
106
|
-
const errorLogs = [];
|
|
107
|
-
vi.spyOn(console, 'error').mockImplementation((error) => {
|
|
108
|
-
if (typeof error === 'string') {
|
|
109
|
-
errorLogs.push(error);
|
|
110
|
-
}
|
|
12
|
+
expect(() => setupOptions()).toThrow(RebillyInstrumentsConfigError);
|
|
111
13
|
});
|
|
112
14
|
|
|
113
|
-
expect(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
+
);
|
|
141
43
|
});
|
|
142
44
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
transactionId: 'txn_TEST'
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
deposit: {
|
|
152
|
-
depositRequestId: 'cash_req_TEST'
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
]
|
|
156
|
-
|
|
157
|
-
expectJwtTests.forEach(test => {
|
|
158
|
-
const key = Object.keys(test)[0];
|
|
159
|
-
it.skip(`should expect jwt with ${key}`, () => {
|
|
45
|
+
it('should validate and inject default values', () => {
|
|
46
|
+
const testJwt =
|
|
47
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJqd3RfVEVTVC1BIiwiZXhwIjoxNzE0ODQwNDg5LCJpYXQiOjE2ODMyMTY1ODkuNTYwMjU2LCJhY2wiOlt7InNjb3BlIjp7Im9yZ2FuaXphdGlvbklkIjpbIm9yZ19URVNULUEiXSwiaW52b2ljZUlkIjpbImluX1RFU1QtQSJdLCJjdXN0b21GaWVsZE5hbWUiOlsiU0lOTGFzdDQiXX0sInBlcm1pc3Npb25zIjpbMjg0LDI4Niw0MTQsNDE1LDQzNCw0MTIsNDI0LDQyNSw0MjYsNDI3LDQyOCw0MjksNDA5LDQxMCw0MDEsNDAyLDQzMyw0MzFdfV0sImNsYWltcyI6eyJ3ZWJzaXRlSWQiOiJ3ZWJfVEVTVC1BIiwiaW52b2ljZUlkIjoiaW5fVEVTVC1BIiwicGF5bWVudE1ldGhvZHMiOltdfSwibWVyY2hhbnQiOiJNRVJDSEFOVC1URVNULUlELUEiLCJjdXN0b21lciI6eyJpZCI6ImN1c19URVNULUEiLCJuYW1lIjoiQ2FyZCBIb2xkZXIgTmFtZSIsImNyZWF0ZWRUaW1lIjoiMjAyMi0wOS0yMVQxODo1MDoyMiswMDowMCJ9fQ.tm33uioGUSpEedHeYufDGm-p1YW40eufNovppcU6-xg';
|
|
160
48
|
const options = {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
+
});
|
|
164
121
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
+
});
|
|
169
195
|
});
|
|
170
|
-
});
|
|
171
196
|
});
|
|
172
197
|
|
|
173
198
|
describe('Setup options handleComputedProperty function', () => {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
+
});
|
|
177
222
|
|
|
178
|
-
|
|
179
|
-
|
|
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
|
+
);
|
|
180
232
|
});
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('should set paymentMethodsUrl from _dev configuration', () => {
|
|
184
|
-
const options = {
|
|
185
|
-
_dev: {
|
|
186
|
-
paymentMethodsUrl: 'https://www.example.com'
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
const result = handleComputedProperty(options);
|
|
190
|
-
|
|
191
|
-
expect(result._computed.paymentMethodsUrl).toEqual('https://www.example.com');
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('should default paymentMethodsUrl from empty _dev configuration', () => {
|
|
195
|
-
const options = {
|
|
196
|
-
_dev: {}
|
|
197
|
-
}
|
|
198
|
-
const result = handleComputedProperty(options);
|
|
199
|
-
|
|
200
|
-
expect(result._computed.paymentMethodsUrl).toEqual('https://forms.secure-payments.app');
|
|
201
|
-
});
|
|
202
233
|
});
|
|
203
234
|
|
|
204
235
|
describe('Setup options handleNestedPropertiesDefaultValues function', () => {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
+
});
|
|
225
257
|
});
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
+
});
|
|
240
272
|
});
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
+
});
|
|
261
297
|
});
|
|
262
|
-
})
|
|
263
298
|
});
|
|
264
299
|
|
|
265
300
|
describe('Setup options handleJwtDestructuring function', () => {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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
|
+
});
|
|
279
316
|
});
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
+
});
|
|
298
335
|
});
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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
|
+
});
|
|
315
352
|
});
|
|
316
|
-
|
|
317
|
-
});
|
|
353
|
+
});
|