@rebilly/instruments 4.4.0 → 4.5.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/CHANGELOG.md +7 -0
- package/dist/index.js +14 -40
- package/dist/index.min.js +14 -40
- package/package.json +3 -3
- package/src/data/options-schema/schemas/options-schema.js +4 -0
- package/src/functions/mount/setup-options.spec.js +5 -5
- package/src/functions/purchase.js +14 -4
- package/src/functions/setup.js +18 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebilly/instruments",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"author": "Rebilly",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"build": "yarn rollup -c --environment NODE_ENV:production",
|
|
10
10
|
"dev": "yarn rollup -c --watch --environment NODE_ENV:development",
|
|
11
11
|
"test:unit": "vitest run",
|
|
12
|
-
"test:unit:watch": "vitest
|
|
12
|
+
"test:unit:watch": "vitest"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@babel/cli": "^7.21.5",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"lodash.kebabcase": "^4.1.1",
|
|
27
27
|
"lodash.merge": "^4.6.2",
|
|
28
28
|
"popostmate": "2.0.0",
|
|
29
|
-
"rebilly-js-sdk": "
|
|
29
|
+
"rebilly-js-sdk": "*",
|
|
30
30
|
"values.js": "^2.0.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
@@ -19,7 +19,7 @@ describe('Setup options function', () => {
|
|
|
19
19
|
errorLogs.push(error.message);
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
const options = {
|
|
24
24
|
apiMode: 'sandbox',
|
|
25
25
|
items: [{
|
|
@@ -94,7 +94,7 @@ describe('Setup options function', () => {
|
|
|
94
94
|
},
|
|
95
95
|
paymentCard: { popup: false }
|
|
96
96
|
},
|
|
97
|
-
features: { autoConfirmation: true, autoResult: true },
|
|
97
|
+
features: { autoConfirmation: true, autoResult: true, fullPageRedirect: false },
|
|
98
98
|
_computed: { paymentMethodsUrl: 'https://forms.secure-payments.app' },
|
|
99
99
|
organizationId: 'MERCHANT-TEST-ID-A',
|
|
100
100
|
invoiceId: 'in_TEST-A',
|
|
@@ -109,7 +109,7 @@ describe('Setup options function', () => {
|
|
|
109
109
|
errorLogs.push(error);
|
|
110
110
|
}
|
|
111
111
|
});
|
|
112
|
-
|
|
112
|
+
|
|
113
113
|
expect(() => setupOptions()).toThrow(RebillyInstrumentsConfigError);
|
|
114
114
|
expect(errorLogs.length).toEqual(6);
|
|
115
115
|
const expectedResults = [
|
|
@@ -161,7 +161,7 @@ describe('Setup options function', () => {
|
|
|
161
161
|
apiMode: 'sandbox',
|
|
162
162
|
...test
|
|
163
163
|
}
|
|
164
|
-
|
|
164
|
+
|
|
165
165
|
expect(() => setupOptions({options})).toThrow(RebillyInstrumentsConfigError);
|
|
166
166
|
expect(errorLogs.length).toEqual(1);
|
|
167
167
|
expect(errorLogs[0]).toEqual(`options must have property jwt when property ${key} is present`);
|
|
@@ -264,7 +264,7 @@ describe('Setup options handleNestedPropertiesDefaultValues function', () => {
|
|
|
264
264
|
|
|
265
265
|
describe('Setup options handleJwtDestructuring function', () => {
|
|
266
266
|
const testJwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJqd3RfVEVTVC1BIiwiZXhwIjoxNzE0ODQwNDg5LCJpYXQiOjE2ODMyMTY1ODkuNTYwMjU2LCJhY2wiOlt7InNjb3BlIjp7Im9yZ2FuaXphdGlvbklkIjpbIm9yZ19URVNULUEiXSwiaW52b2ljZUlkIjpbImluX1RFU1QtQSJdLCJjdXN0b21GaWVsZE5hbWUiOlsiU0lOTGFzdDQiXX0sInBlcm1pc3Npb25zIjpbMjg0LDI4Niw0MTQsNDE1LDQzNCw0MTIsNDI0LDQyNSw0MjYsNDI3LDQyOCw0MjksNDA5LDQxMCw0MDEsNDAyLDQzMyw0MzFdfV0sImNsYWltcyI6eyJ3ZWJzaXRlSWQiOiJ3ZWJfVEVTVC1BIiwiaW52b2ljZUlkIjoiaW5fVEVTVC1BIiwicGF5bWVudE1ldGhvZHMiOltdfSwibWVyY2hhbnQiOiJNRVJDSEFOVC1URVNULUlELUEiLCJjdXN0b21lciI6eyJpZCI6ImN1c19URVNULUEiLCJuYW1lIjoiQ2FyZCBIb2xkZXIgTmFtZSIsImNyZWF0ZWRUaW1lIjoiMjAyMi0wOS0yMVQxODo1MDoyMiswMDowMCJ9fQ.tm33uioGUSpEedHeYufDGm-p1YW40eufNovppcU6-xg';
|
|
267
|
-
|
|
267
|
+
|
|
268
268
|
it('should destructure when jwt is present', () => {
|
|
269
269
|
const options = {
|
|
270
270
|
jwt: testJwt,
|
|
@@ -103,6 +103,13 @@ export async function makePurchase({ payload }) {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
export function handleApprovalUrl({fields, payload}) {
|
|
106
|
+
if (state.options.features.fullPageRedirect &&
|
|
107
|
+
(payload.redirectUrl || fields.transaction?.approvalUrl)
|
|
108
|
+
) {
|
|
109
|
+
window.location = payload.redirectUrl || fields.transaction?.approvalUrl;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
106
113
|
if (payload.redirectUrl || !fields.transaction?.approvalUrl) {
|
|
107
114
|
const { paymentMethodsUrl } = state.options._computed;
|
|
108
115
|
const modelSafeFields = JSON.parse(JSON.stringify(fields));
|
|
@@ -140,13 +147,16 @@ export async function purchase({ payload }) {
|
|
|
140
147
|
try {
|
|
141
148
|
let fields;
|
|
142
149
|
if (state.data.isPayment) {
|
|
143
|
-
fields = await makePayment({
|
|
150
|
+
fields = await makePayment({ payload });
|
|
144
151
|
} else {
|
|
145
|
-
fields = await makePurchase({
|
|
152
|
+
fields = await makePurchase({ payload });
|
|
146
153
|
}
|
|
147
|
-
|
|
148
154
|
if (fields.transaction?.approvalUrl && fields.transaction?.result === 'unknown') {
|
|
149
|
-
|
|
155
|
+
if (state.options.features.fullPageRedirect) {
|
|
156
|
+
window.location = fields.transaction?.approvalUrl
|
|
157
|
+
} else {
|
|
158
|
+
handleApprovalUrl({fields, payload});
|
|
159
|
+
}
|
|
150
160
|
} else {
|
|
151
161
|
Events.purchaseCompleted.dispatch(fields);
|
|
152
162
|
}
|
package/src/functions/setup.js
CHANGED
|
@@ -36,20 +36,24 @@ export async function setup({ payload }) {
|
|
|
36
36
|
state.data = new DataInstance({instrument, transaction});
|
|
37
37
|
|
|
38
38
|
if (transaction.approvalUrl && transaction.result === 'unknown') {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
if (state.options.features.fullPageRedirect) {
|
|
40
|
+
window.location = transaction.approvalUrl
|
|
41
|
+
} else {
|
|
42
|
+
const { paymentMethodsUrl } = state.options._computed;
|
|
43
|
+
mountModal({
|
|
44
|
+
name: 'rebilly-instruments-approval-url',
|
|
45
|
+
url: `${paymentMethodsUrl}/approval-url`,
|
|
46
|
+
model: {
|
|
47
|
+
setup: {transaction}
|
|
48
|
+
},
|
|
49
|
+
close: ({transaction: updatedTransaction = transaction}) => {
|
|
50
|
+
Events.setupCompleted.dispatch({
|
|
51
|
+
instrument,
|
|
52
|
+
transaction: updatedTransaction
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
53
57
|
} else {
|
|
54
58
|
Events.setupCompleted.dispatch({instrument, transaction});
|
|
55
59
|
}
|