@rebilly/instruments 1.0.2-beta.8 → 2.1.1-beta.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 +13 -4
- package/.eslintrc.js +3 -0
- package/.prettierrc.js +11 -0
- package/README.md +15 -314
- package/dist/events/base-event.js +6 -9
- package/dist/events/events.spec.js +4 -4
- package/dist/events/index.js +2 -1
- package/dist/functions/destroy.js +12 -14
- package/dist/functions/destroy.spec.js +3 -3
- package/dist/functions/mount/fetch-data.js +183 -0
- package/dist/functions/mount/fetch-data.spec.js +189 -0
- package/dist/functions/mount/index.js +158 -251
- package/dist/functions/mount/mount.spec.js +24 -121
- package/dist/functions/mount/setup-element.js +40 -0
- package/dist/functions/mount/setup-framepay.js +46 -0
- package/dist/functions/mount/setup-i18n.js +33 -0
- package/dist/functions/mount/setup-options.js +96 -0
- package/dist/functions/mount/setup-options.spec.js +66 -0
- package/dist/functions/mount/setup-storefront.js +34 -0
- package/dist/functions/mount/setup-styles.js +43 -0
- package/dist/functions/on.js +13 -4
- package/dist/functions/on.spec.js +19 -5
- package/dist/functions/purchase.js +139 -22
- package/dist/functions/purchase.spec.js +23 -19
- package/dist/functions/setup.js +85 -0
- package/dist/functions/setup.spec.js +87 -0
- package/dist/functions/show.js +31 -14
- package/dist/functions/show.spec.js +47 -18
- package/dist/functions/update.js +53 -27
- package/dist/functions/update.spec.js +40 -21
- package/dist/i18n/en.json +4 -1
- package/dist/i18n/es.json +4 -1
- package/dist/index.js +67 -56
- package/dist/index.spec.js +7 -27
- package/dist/loader/index.js +4 -3
- package/dist/storefront/index.js +33 -0
- package/dist/storefront/invoices.js +27 -0
- package/dist/storefront/models/base-model.js +18 -0
- package/dist/storefront/models/invoice-model.js +14 -0
- package/dist/storefront/models/plan-model.js +4 -35
- package/dist/storefront/models/product-model.js +4 -23
- package/dist/storefront/models/summary-model.js +12 -25
- package/dist/storefront/models/transaction-model.js +31 -0
- package/dist/storefront/payment-instruments.js +47 -0
- package/dist/storefront/payment-instruments.spec.js +55 -0
- package/dist/storefront/plans.js +15 -24
- package/dist/storefront/plans.spec.js +17 -44
- package/dist/storefront/products.js +16 -20
- package/dist/storefront/products.spec.js +25 -49
- package/dist/storefront/purchase.js +28 -16
- package/dist/storefront/purchase.spec.js +4 -22
- package/dist/storefront/ready-to-pay.js +26 -22
- package/dist/storefront/ready-to-pay.spec.js +25 -54
- package/dist/storefront/storefront.spec.js +1 -1
- package/dist/storefront/summary.js +27 -24
- package/dist/storefront/summary.spec.js +44 -86
- package/dist/storefront/transactions.js +27 -0
- package/dist/style/base/theme.js +3 -3
- package/dist/style/components/methods.js +43 -42
- package/dist/style/utils/color-values.js +1 -3
- package/dist/style/views/confirmation.js +0 -4
- package/dist/style/views/method-selector.js +1 -1
- package/dist/style/views/modal.js +3 -1
- package/dist/style/views/summary.js +5 -1
- package/dist/utils/format-currency.js +4 -2
- package/dist/utils/has-valid-css-selector.js +1 -1
- package/dist/utils/process-property-as-dom-element.js +0 -2
- package/dist/views/__snapshots__/summary.spec.js.snap +103 -113
- package/dist/views/common/iframe/base-iframe.js +10 -2
- package/dist/views/common/iframe/modal-iframe.js +44 -3
- package/dist/views/confirmation.js +44 -20
- package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
- package/dist/views/method-selector/express-methods/google-pay.js +31 -0
- package/dist/views/method-selector/express-methods/paypal.js +19 -0
- package/dist/views/method-selector/generate-digital-wallet.js +68 -0
- package/dist/views/method-selector/generate-digital-wallet.spec.js +135 -0
- package/dist/views/method-selector/get-payment-methods.js +28 -8
- package/dist/views/method-selector/get-payment-methods.spec.js +25 -26
- package/dist/views/method-selector/index.js +55 -86
- package/dist/views/method-selector/method-selector.spec.js +80 -69
- package/dist/views/method-selector/mount-express-methods.js +38 -62
- package/dist/views/method-selector/mount-methods.js +18 -18
- package/dist/views/modal.js +21 -15
- package/dist/views/result.js +13 -16
- package/dist/views/summary.js +170 -114
- package/dist/views/summary.spec.js +72 -76
- package/package.json +5 -4
- package/src/events/base-event.js +15 -17
- package/src/events/events.spec.js +6 -4
- package/src/events/index.js +6 -3
- package/src/functions/destroy.js +12 -13
- package/src/functions/destroy.spec.js +30 -31
- package/src/functions/mount/fetch-data.js +148 -0
- package/src/functions/mount/fetch-data.spec.js +238 -0
- package/src/functions/mount/index.js +129 -244
- package/src/functions/mount/mount.spec.js +35 -139
- package/src/functions/mount/setup-element.js +26 -0
- package/src/functions/mount/setup-framepay.js +41 -0
- package/src/functions/mount/setup-i18n.js +19 -0
- package/src/functions/mount/setup-options.js +100 -0
- package/src/functions/mount/setup-options.spec.js +60 -0
- package/src/functions/mount/setup-storefront.js +24 -0
- package/src/functions/mount/setup-styles.js +30 -0
- package/src/functions/on.js +13 -8
- package/src/functions/on.spec.js +30 -17
- package/src/functions/purchase.js +101 -19
- package/src/functions/purchase.spec.js +18 -18
- package/src/functions/setup.js +48 -0
- package/src/functions/setup.spec.js +98 -0
- package/src/functions/show.js +20 -10
- package/src/functions/show.spec.js +43 -22
- package/src/functions/update.js +50 -27
- package/src/functions/update.spec.js +57 -22
- package/src/i18n/en.json +4 -1
- package/src/i18n/es.json +4 -1
- package/src/i18n/i18n.spec.js +6 -4
- package/src/i18n/index.js +14 -11
- package/src/index.js +41 -52
- package/src/index.spec.js +8 -37
- package/src/loader/index.js +51 -47
- package/src/loader/loader.spec.js +26 -19
- package/src/storefront/index.js +37 -7
- package/src/storefront/invoices.js +11 -0
- package/src/storefront/models/base-model.js +10 -0
- package/src/storefront/models/invoice-model.js +3 -0
- package/src/storefront/models/plan-model.js +3 -35
- package/src/storefront/models/product-model.js +3 -23
- package/src/storefront/models/ready-to-pay-model.js +3 -3
- package/src/storefront/models/summary-model.js +15 -29
- package/src/storefront/models/transaction-model.js +19 -0
- package/src/storefront/payment-instruments.js +30 -0
- package/src/storefront/payment-instruments.spec.js +69 -0
- package/src/storefront/plans.js +16 -23
- package/src/storefront/plans.spec.js +25 -54
- package/src/storefront/products.js +18 -22
- package/src/storefront/products.spec.js +23 -54
- package/src/storefront/purchase.js +14 -14
- package/src/storefront/purchase.spec.js +17 -29
- package/src/storefront/ready-to-pay.js +26 -23
- package/src/storefront/ready-to-pay.spec.js +41 -71
- package/src/storefront/storefront.spec.js +1 -1
- package/src/storefront/summary.js +26 -22
- package/src/storefront/summary.spec.js +60 -109
- package/src/storefront/transactions.js +11 -0
- package/src/style/base/theme.js +10 -8
- package/src/style/base/theme.spec.js +4 -2
- package/src/style/browserslist.js +1 -3
- package/src/style/components/button.js +3 -1
- package/src/style/components/forms/checkbox.js +3 -1
- package/src/style/components/index.js +1 -1
- package/src/style/components/loader.js +3 -1
- package/src/style/components/methods.js +43 -42
- package/src/style/helpers/index.js +1 -1
- package/src/style/index.js +2 -1
- package/src/style/utils/color-values.js +4 -4
- package/src/style/vendor/framepay.js +1 -1
- package/src/style/vendor/postmate.js +1 -1
- package/src/style/views/confirmation.js +0 -4
- package/src/style/views/index.js +1 -1
- package/src/style/views/method-selector.js +1 -1
- package/src/style/views/modal.js +4 -2
- package/src/style/views/summary.js +5 -1
- package/src/utils/add-dom-element.js +12 -13
- package/src/utils/format-currency.js +6 -2
- package/src/utils/has-valid-css-selector.js +2 -2
- package/src/utils/is-dom-element.js +1 -1
- package/src/utils/process-property-as-dom-element.js +27 -24
- package/src/utils/sleep.js +1 -1
- package/src/views/__snapshots__/summary.spec.js.snap +103 -113
- package/src/views/common/iframe/base-iframe.js +12 -4
- package/src/views/common/iframe/event-listeners.js +6 -6
- package/src/views/common/iframe/index.js +1 -1
- package/src/views/common/iframe/method-iframe.js +3 -6
- package/src/views/common/iframe/modal-iframe.js +42 -6
- package/src/views/common/iframe/view-iframe.js +3 -5
- package/src/views/common/render-utilities.js +3 -3
- package/src/views/confirmation.js +34 -25
- package/src/views/method-selector/express-methods/apple-pay.js +78 -0
- package/src/views/method-selector/express-methods/google-pay.js +24 -0
- package/src/views/method-selector/express-methods/paypal.js +7 -0
- package/src/views/method-selector/generate-digital-wallet.js +51 -0
- package/src/views/method-selector/generate-digital-wallet.spec.js +135 -0
- package/src/views/method-selector/get-method-data.js +7 -4
- package/src/views/method-selector/get-payment-methods.js +38 -29
- package/src/views/method-selector/get-payment-methods.spec.js +26 -33
- package/src/views/method-selector/index.js +70 -99
- package/src/views/method-selector/method-selector.spec.js +88 -78
- package/src/views/method-selector/mount-express-methods.js +36 -60
- package/src/views/method-selector/mount-methods.js +32 -21
- package/src/views/modal.js +37 -23
- package/src/views/result.js +12 -15
- package/src/views/summary.js +169 -101
- package/src/views/summary.spec.js +99 -74
- package/tests/async-utilities.js +22 -0
- package/tests/mocks/rebilly-instruments-mock.js +89 -77
- package/tests/mocks/storefront-api-mock.js +8 -0
- package/tests/mocks/storefront-mock.js +17 -0
- package/dist/events/purchase-completed.js +0 -24
- package/dist/functions/initialize.js +0 -82
- package/dist/functions/initialize.spec.js +0 -34
- package/dist/functions/mount/fetch-summary-data.js +0 -31
- package/dist/functions/mount/fetch-summary-data.spec.js +0 -45
- package/dist/views/method-selector/process-digital-wallet-options.js +0 -35
- package/dist/views/method-selector/process-digital-wallet-options.spec.js +0 -80
- package/src/events/purchase-completed.js +0 -11
- package/src/functions/initialize.js +0 -74
- package/src/functions/initialize.spec.js +0 -38
- package/src/functions/mount/fetch-summary-data.js +0 -26
- package/src/functions/mount/fetch-summary-data.spec.js +0 -46
- package/src/views/method-selector/process-digital-wallet-options.js +0 -16
- package/src/views/method-selector/process-digital-wallet-options.spec.js +0 -94
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { sleep } from '@/utils'
|
|
2
|
+
|
|
3
|
+
export async function avoidUnhandledPromises() {
|
|
4
|
+
// We need this sleep to avoid unhandled promises.
|
|
5
|
+
// This hack will be removed if we refactor the current design.
|
|
6
|
+
await sleep(100)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {Promise} promise
|
|
11
|
+
*/
|
|
12
|
+
export async function expectConfigurationError(promise) {
|
|
13
|
+
const NoConfigOrOptionsError =
|
|
14
|
+
'Could not use Rebilly Instruments mount options to fetch Rebilly data'
|
|
15
|
+
let error = null
|
|
16
|
+
try {
|
|
17
|
+
await promise
|
|
18
|
+
} catch (e) {
|
|
19
|
+
error = e
|
|
20
|
+
}
|
|
21
|
+
expect(error.message).toBe(NoConfigOrOptionsError)
|
|
22
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RebillyInstrumentsInstance } from '@rebilly/instruments';
|
|
2
2
|
import { createFramepayMock } from 'tests/mocks/framepay-mock';
|
|
3
3
|
import { get, ok, post } from 'msw-when-then';
|
|
4
4
|
import { when } from 'tests/msw/server';
|
|
@@ -6,29 +6,43 @@ import { storefrontURL } from 'tests/mocks/storefront-api-mock';
|
|
|
6
6
|
import PlanModel from '@/storefront/models/plan-model';
|
|
7
7
|
import ProductModel from '@/storefront/models/product-model';
|
|
8
8
|
import SummaryModel from '@/storefront/models/summary-model';
|
|
9
|
+
import InvoiceModel from '@/storefront/models/invoice-model';
|
|
9
10
|
import merge from 'lodash.merge';
|
|
11
|
+
import { DataInstance } from '../../src/functions/mount/fetch-data';
|
|
10
12
|
|
|
11
|
-
export async function RenderMockRebillyInstruments(
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
export async function RenderMockRebillyInstruments(options = {}) {
|
|
14
|
+
const testInvoice = new InvoiceModel({
|
|
15
|
+
id: 'test-invoice-id'
|
|
16
|
+
});
|
|
17
|
+
const testPlan = new PlanModel({ name: 'Test Plan', id: 'test-plan-id-1' });
|
|
18
|
+
const testProduct = new ProductModel({
|
|
19
|
+
description: 'My Awesome Product',
|
|
20
|
+
id: 'test-product-1',
|
|
21
|
+
name: 'My Product'
|
|
22
|
+
});
|
|
23
|
+
const testSummary = new SummaryModel({
|
|
24
|
+
currency: 'USD',
|
|
25
|
+
lineItems: [
|
|
15
26
|
{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
planId: 'test-plan-id-1',
|
|
21
|
-
productId: 'test-product-1',
|
|
22
|
-
quantity: 1,
|
|
23
|
-
}
|
|
24
|
-
]
|
|
27
|
+
description: 'test-plan-id-1',
|
|
28
|
+
planId: 'test-plan-id-1',
|
|
29
|
+
productId: 'test-product-1',
|
|
30
|
+
quantity: 1
|
|
25
31
|
}
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
]
|
|
33
|
+
});
|
|
34
|
+
const framePayStyleUrl = 'https://dev.framepay.rebilly.com/rebilly.css';
|
|
28
35
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
when(get(`${storefrontURL}/invoices/*`)).thenReturn(
|
|
37
|
+
(() => {
|
|
38
|
+
return ok(testInvoice);
|
|
39
|
+
})()
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
when(post(`${storefrontURL}/ready-to-pay`)).thenReturn(
|
|
43
|
+
(() => {
|
|
44
|
+
return ok([
|
|
45
|
+
{
|
|
32
46
|
method: 'payment-card',
|
|
33
47
|
feature: {
|
|
34
48
|
name: 'Google Pay',
|
|
@@ -37,77 +51,75 @@ export async function RenderMockRebillyInstruments(configs = {}, options = {}) {
|
|
|
37
51
|
},
|
|
38
52
|
brands: ['Visa', 'MasterCard', 'American Express', 'Discover'],
|
|
39
53
|
filters: []
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
})()
|
|
54
|
+
}
|
|
55
|
+
]);
|
|
56
|
+
})()
|
|
57
|
+
);
|
|
43
58
|
|
|
44
|
-
|
|
59
|
+
when(post(`${storefrontURL}/preview-purchase`)).thenReturn(
|
|
60
|
+
(() => {
|
|
45
61
|
return ok(testSummary);
|
|
46
|
-
})()
|
|
62
|
+
})()
|
|
63
|
+
);
|
|
47
64
|
|
|
48
|
-
|
|
65
|
+
when(get(`${storefrontURL}/plans`)).thenReturn(
|
|
66
|
+
(() => {
|
|
49
67
|
return ok([testPlan]);
|
|
50
|
-
})()
|
|
68
|
+
})()
|
|
69
|
+
);
|
|
51
70
|
|
|
52
|
-
|
|
71
|
+
when(get(`${storefrontURL}/products`)).thenReturn(
|
|
72
|
+
(() => {
|
|
53
73
|
return ok([testProduct]);
|
|
54
|
-
})()
|
|
55
|
-
|
|
56
|
-
document.body.innerHTML =
|
|
57
|
-
`
|
|
58
|
-
<div class="form-selector"></div>
|
|
59
|
-
<div class="summary-selector"></div>
|
|
60
|
-
`;
|
|
74
|
+
})()
|
|
75
|
+
);
|
|
61
76
|
|
|
62
|
-
|
|
77
|
+
const defaultOptions = {
|
|
78
|
+
form: '.form-selector',
|
|
79
|
+
summary: '.summary-selector',
|
|
80
|
+
locale: 'auto',
|
|
81
|
+
_dev: {
|
|
82
|
+
framePayStyleLink: framePayStyleUrl
|
|
83
|
+
},
|
|
84
|
+
};
|
|
63
85
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
planId: 'test-plan-id-1',
|
|
76
|
-
quantity: 1
|
|
77
|
-
}
|
|
78
|
-
]
|
|
79
|
-
}
|
|
86
|
+
const hasPurchaseData = [
|
|
87
|
+
'items',
|
|
88
|
+
'invoiceId',
|
|
89
|
+
'transactionId',
|
|
90
|
+
'money'
|
|
91
|
+
].some(key => Object.keys(options).includes(key))
|
|
92
|
+
if(!hasPurchaseData) {
|
|
93
|
+
defaultOptions.items = [
|
|
94
|
+
{
|
|
95
|
+
planId: 'test-plan-id-1',
|
|
96
|
+
quantity: 1
|
|
80
97
|
}
|
|
81
|
-
|
|
82
|
-
|
|
98
|
+
];
|
|
99
|
+
}
|
|
83
100
|
|
|
84
|
-
|
|
85
|
-
global.Rebilly = framepayMock;
|
|
101
|
+
const mergedOptions = merge({...defaultOptions}, options);
|
|
86
102
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return rebillyInstruments;
|
|
90
|
-
}
|
|
103
|
+
const framepayMock = createFramepayMock();
|
|
104
|
+
global.Rebilly = framepayMock;
|
|
91
105
|
|
|
92
|
-
|
|
93
|
-
const initializeConfig = {
|
|
94
|
-
organizationId: 'test-organization-id',
|
|
95
|
-
publishableKey: 'test-api-key',
|
|
96
|
-
websiteId: 'test-website-id',
|
|
97
|
-
apiMode: 'live',
|
|
98
|
-
...config
|
|
99
|
-
}
|
|
106
|
+
const rebillyInstruments = new RebillyInstrumentsInstance();
|
|
100
107
|
|
|
101
|
-
|
|
108
|
+
document.body.innerHTML = `
|
|
109
|
+
<div class="${mergedOptions.form.replace('.', '')}"></div>
|
|
110
|
+
<div class="${mergedOptions.summary.replace('.', '')}"></div>
|
|
111
|
+
`;
|
|
102
112
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
113
|
+
await rebillyInstruments.mount(mergedOptions);
|
|
114
|
+
|
|
115
|
+
rebillyInstruments.mock = {
|
|
116
|
+
data: (data) => {
|
|
117
|
+
rebillyInstruments.state.data = new DataInstance({
|
|
118
|
+
state: rebillyInstruments.state,
|
|
119
|
+
...data
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
};
|
|
111
123
|
|
|
112
|
-
return
|
|
124
|
+
return rebillyInstruments;
|
|
113
125
|
}
|
|
@@ -18,4 +18,12 @@ export const initStoreFrontApiMocks = (when) => {
|
|
|
18
18
|
when(get(`${storefrontURL}/products`)).thenReturn((() => {
|
|
19
19
|
return ok([])
|
|
20
20
|
})());
|
|
21
|
+
|
|
22
|
+
when(post(`${storefrontURL}/payment-instruments`)).thenReturn((() => {
|
|
23
|
+
return ok([])
|
|
24
|
+
})());
|
|
25
|
+
|
|
26
|
+
when(post(`${storefrontURL}/payment-instruments/*/setup`)).thenReturn((() => {
|
|
27
|
+
return ok([])
|
|
28
|
+
})());
|
|
21
29
|
};
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import Storefront from '@/storefront';
|
|
2
|
+
import { DataInstance } from '@/functions/mount/fetch-data';
|
|
2
3
|
|
|
3
4
|
export function MockStorefront(config = {}) {
|
|
4
5
|
return Storefront(config);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function StorefontTestingInstance({
|
|
9
|
+
MockStorefrontConfig = {},
|
|
10
|
+
options = {},
|
|
11
|
+
data = {}
|
|
12
|
+
} = {}) {
|
|
13
|
+
class TestInstance {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.options = options;
|
|
16
|
+
this.storefront = MockStorefront(MockStorefrontConfig);
|
|
17
|
+
this.data = new DataInstance({state: {options}, ...data});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return new TestInstance();
|
|
5
22
|
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.PurchaseCompletedEventName = void 0;
|
|
7
|
-
|
|
8
|
-
var _baseEvent = _interopRequireDefault(require("./base-event"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
const PurchaseCompletedEventName = 'rebilly-instruments-purchase-complete';
|
|
13
|
-
exports.PurchaseCompletedEventName = PurchaseCompletedEventName;
|
|
14
|
-
|
|
15
|
-
class PurchaseCompletedEvent extends _baseEvent.default {
|
|
16
|
-
constructor({
|
|
17
|
-
name = PurchaseCompletedEventName
|
|
18
|
-
} = {}) {
|
|
19
|
-
super(name);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
exports.default = PurchaseCompletedEvent;
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Initialize = Initialize;
|
|
7
|
-
|
|
8
|
-
var _storefront = _interopRequireDefault(require("../storefront"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @typedef {Object} Typeography
|
|
14
|
-
* @param {string} fontFamily - Same as CSS property "font-family". Will be used thoughout the library ui
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @typedef {Object} Color
|
|
19
|
-
* @param {string} primary - CSS hexcode or color name, used to draw user attention
|
|
20
|
-
* @param {string} errorText - CSS hexcode or color name, used to display error messages
|
|
21
|
-
* @param {string} text - CSS hexcode or color name, used to display font color
|
|
22
|
-
* @param {string} buttonText - CSS hexcode or color name, used for buttons text, primary will be it's background
|
|
23
|
-
* @param {string} background - CSS hexcode or color name, the color used for the background of the forms
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @typedef {Object} Theme
|
|
28
|
-
* @param {Color} color - object with color properties
|
|
29
|
-
* @param {Typeography} typography - object with typography options
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @typedef {object} Configs
|
|
34
|
-
* @property {string} organizationId - The Rebilly organization id that all api requests will be associated with.
|
|
35
|
-
* @property {string} publishableKey - The Rebilly publishable api key used to access the storefront api's.
|
|
36
|
-
* @property {string} websiteId - The Rebilly website api.
|
|
37
|
-
* @property {"live" | "sandbox"} apiMode - default "live". The mode for the Rebilly api. default "live".
|
|
38
|
-
* @property {string} css - CSS string that overrides any styles.
|
|
39
|
-
* @property {Theme} theme - CSS string that overrides any styles.
|
|
40
|
-
* @property {object} i18n - object containing the language defintions. (or overrides for existing languages)
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Initialize library with configurations.
|
|
45
|
-
* @param {Configs} configs - The configurations that are to be passed to the library for use.
|
|
46
|
-
*/
|
|
47
|
-
function Initialize(configs = {}) {
|
|
48
|
-
const {
|
|
49
|
-
organizationId,
|
|
50
|
-
publishableKey,
|
|
51
|
-
websiteId,
|
|
52
|
-
apiMode = 'live',
|
|
53
|
-
i18n,
|
|
54
|
-
theme,
|
|
55
|
-
css,
|
|
56
|
-
_dev = null
|
|
57
|
-
} = configs;
|
|
58
|
-
this.configs = {
|
|
59
|
-
organizationId,
|
|
60
|
-
publishableKey,
|
|
61
|
-
websiteId,
|
|
62
|
-
apiMode,
|
|
63
|
-
i18n,
|
|
64
|
-
theme,
|
|
65
|
-
css
|
|
66
|
-
};
|
|
67
|
-
const storefront = {
|
|
68
|
-
publishableKey: this.configs.publishableKey,
|
|
69
|
-
orgnizationId: this.configs.orgnizationId,
|
|
70
|
-
mode: this.configs.apiMode || 'live'
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
if (_dev) {
|
|
74
|
-
this.configs._dev = _dev;
|
|
75
|
-
storefront.liveUrl = _dev.liveUrl || 'https://api.local.rebilly.dev';
|
|
76
|
-
storefront.sandboxUrl = _dev.sandboxUrl || 'https://api-sandbox.local.rebilly.dev';
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
this.storefront = (0, _storefront.default)(storefront);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _rebillyInstrumentsMock = require("tests/mocks/rebilly-instruments-mock");
|
|
4
|
-
|
|
5
|
-
describe('RebillyInstruments instance', () => {
|
|
6
|
-
it('should should set configs', () => {
|
|
7
|
-
const testConfigs = {
|
|
8
|
-
apiMode: 'live',
|
|
9
|
-
organizationId: 'test-organization-id',
|
|
10
|
-
publishableKey: 'test-publishable-key',
|
|
11
|
-
websiteId: 'test-website-id',
|
|
12
|
-
_dev: {
|
|
13
|
-
liveUrl: null,
|
|
14
|
-
sandboxUrl: null
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)(testConfigs);
|
|
18
|
-
expect(rebillyInstruments.configs).toEqual(testConfigs);
|
|
19
|
-
});
|
|
20
|
-
it('should setup api instance', () => {
|
|
21
|
-
const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)();
|
|
22
|
-
expect(rebillyInstruments.storefront).toHaveProperty('setPublishableKey');
|
|
23
|
-
});
|
|
24
|
-
it('should have the right developer settings', () => {
|
|
25
|
-
const devOptions = {
|
|
26
|
-
_dev: {
|
|
27
|
-
liveUrl: 'https://api.rebilly.com',
|
|
28
|
-
sandboxUrl: 'https://api-sandbox.rebilly.com'
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)(devOptions);
|
|
32
|
-
expect(rebillyInstruments.configs._dev).toEqual(devOptions._dev);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.FetchSummaryData = FetchSummaryData;
|
|
7
|
-
|
|
8
|
-
async function FetchSummaryData({
|
|
9
|
-
riskMetadata,
|
|
10
|
-
summaryPayload = null
|
|
11
|
-
} = {}) {
|
|
12
|
-
if (!riskMetadata) {
|
|
13
|
-
throw new Error('riskMetadata is required for FetchSummaryData');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const [readyToPay, summary] = await Promise.all([this._fetchReadyToPay(riskMetadata), this._fetchSummary({
|
|
17
|
-
data: summaryPayload
|
|
18
|
-
})]);
|
|
19
|
-
const plans = await this._fetchPlans({
|
|
20
|
-
data: summary
|
|
21
|
-
});
|
|
22
|
-
const products = await this._fetchProducts({
|
|
23
|
-
data: plans
|
|
24
|
-
});
|
|
25
|
-
return {
|
|
26
|
-
readyToPay,
|
|
27
|
-
summary,
|
|
28
|
-
plans,
|
|
29
|
-
products
|
|
30
|
-
};
|
|
31
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _fetchSummaryData = require("./fetch-summary-data");
|
|
4
|
-
|
|
5
|
-
describe('Fetch Summary Data function helper', () => {
|
|
6
|
-
class TestInstance {
|
|
7
|
-
constructor() {
|
|
8
|
-
this._fetchReadyToPay = jest.fn();
|
|
9
|
-
this._fetchSummary = jest.fn(() => {
|
|
10
|
-
return new Promise(resolve => resolve({}));
|
|
11
|
-
});
|
|
12
|
-
this._fetchPlans = jest.fn(() => {
|
|
13
|
-
return new Promise(resolve => resolve([{}]));
|
|
14
|
-
});
|
|
15
|
-
this._fetchProducts = jest.fn();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
_FetchSummaryData() {
|
|
19
|
-
return _fetchSummaryData.FetchSummaryData.apply(this, arguments);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
it('should fetch all the data', async () => {
|
|
25
|
-
const instance = new TestInstance();
|
|
26
|
-
await instance._FetchSummaryData({
|
|
27
|
-
riskMetadata: {}
|
|
28
|
-
});
|
|
29
|
-
expect(instance._fetchReadyToPay).toBeCalledTimes(1);
|
|
30
|
-
expect(instance._fetchSummary).toBeCalledTimes(1);
|
|
31
|
-
expect(instance._fetchPlans).toBeCalledTimes(1);
|
|
32
|
-
expect(instance._fetchProducts).toBeCalledTimes(1);
|
|
33
|
-
});
|
|
34
|
-
it('should pass riskMetadata to ready to pay', async () => {
|
|
35
|
-
const testRiskMetadata = {};
|
|
36
|
-
const instance = new TestInstance();
|
|
37
|
-
await instance._FetchSummaryData({
|
|
38
|
-
riskMetadata: testRiskMetadata
|
|
39
|
-
});
|
|
40
|
-
expect(instance._fetchReadyToPay).toBeCalledWith(testRiskMetadata);
|
|
41
|
-
expect(async () => {
|
|
42
|
-
await instance._FetchSummaryData();
|
|
43
|
-
}).rejects.toEqual(new Error('riskMetadata is required for FetchSummaryData'));
|
|
44
|
-
});
|
|
45
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.processDigitalWalletOptions = processDigitalWalletOptions;
|
|
7
|
-
|
|
8
|
-
function processDigitalWalletOptions(options, methods) {
|
|
9
|
-
const {
|
|
10
|
-
paymentInstruments
|
|
11
|
-
} = options;
|
|
12
|
-
const digitalWalletOptions = {};
|
|
13
|
-
const googlePayMethod = methods.find(method => {
|
|
14
|
-
var _method$feature;
|
|
15
|
-
|
|
16
|
-
return ((_method$feature = method.feature) === null || _method$feature === void 0 ? void 0 : _method$feature.name) === 'Google Pay';
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
if (paymentInstruments !== null && paymentInstruments !== void 0 && paymentInstruments.googlePay && googlePayMethod) {
|
|
20
|
-
const {
|
|
21
|
-
googlePay
|
|
22
|
-
} = paymentInstruments;
|
|
23
|
-
const {
|
|
24
|
-
merchantName,
|
|
25
|
-
merchantOrigin
|
|
26
|
-
} = googlePayMethod.feature;
|
|
27
|
-
digitalWalletOptions.merchantConfig = {
|
|
28
|
-
merchantName,
|
|
29
|
-
merchantOrigin
|
|
30
|
-
};
|
|
31
|
-
digitalWalletOptions.googlePayDisplayOptions = googlePay.displayOptions;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return digitalWalletOptions;
|
|
35
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _processDigitalWalletOptions = require("./process-digital-wallet-options");
|
|
4
|
-
|
|
5
|
-
var _readyToPayModel = _interopRequireDefault(require("@/storefront/models/ready-to-pay-model"));
|
|
6
|
-
|
|
7
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
-
|
|
9
|
-
describe('processDigitalWalletOptions', () => {
|
|
10
|
-
describe('Google Pay', () => {
|
|
11
|
-
it('should return the correct google pay configs when google pay is configured and the payment method is found', () => {
|
|
12
|
-
const options = {
|
|
13
|
-
paymentInstruments: {
|
|
14
|
-
googlePay: {
|
|
15
|
-
displayOptions: {
|
|
16
|
-
buttonColor: 'black',
|
|
17
|
-
buttonType: 'short',
|
|
18
|
-
buttonHeight: '44px'
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const availablePaymentMethods = [new _readyToPayModel.default({
|
|
24
|
-
method: 'payment-card',
|
|
25
|
-
feature: {
|
|
26
|
-
name: 'Google Pay',
|
|
27
|
-
merchantName: 'google-pay-merchant-name',
|
|
28
|
-
merchantOrigin: 'google-pay-merchant-origin'
|
|
29
|
-
},
|
|
30
|
-
brands: ['Visa']
|
|
31
|
-
})];
|
|
32
|
-
expect((0, _processDigitalWalletOptions.processDigitalWalletOptions)(options, availablePaymentMethods)).toMatchInlineSnapshot(`
|
|
33
|
-
Object {
|
|
34
|
-
"googlePayDisplayOptions": Object {
|
|
35
|
-
"buttonColor": "black",
|
|
36
|
-
"buttonHeight": "44px",
|
|
37
|
-
"buttonType": "short",
|
|
38
|
-
},
|
|
39
|
-
"merchantConfig": Object {
|
|
40
|
-
"merchantName": "google-pay-merchant-name",
|
|
41
|
-
"merchantOrigin": "google-pay-merchant-origin",
|
|
42
|
-
},
|
|
43
|
-
}
|
|
44
|
-
`);
|
|
45
|
-
});
|
|
46
|
-
it('should not return any google pay options if google pay is not found in the ready to pay results', () => {
|
|
47
|
-
const options = {
|
|
48
|
-
paymentInstruments: {
|
|
49
|
-
googlePay: {
|
|
50
|
-
displayOptions: {
|
|
51
|
-
buttonColor: 'black',
|
|
52
|
-
buttonType: 'short',
|
|
53
|
-
buttonHeight: '44px'
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
const availablePaymentMethods = [new _readyToPayModel.default({
|
|
59
|
-
method: 'payment-card',
|
|
60
|
-
brands: ['Visa']
|
|
61
|
-
})];
|
|
62
|
-
expect((0, _processDigitalWalletOptions.processDigitalWalletOptions)(options, availablePaymentMethods)).toEqual({});
|
|
63
|
-
});
|
|
64
|
-
it('should not return any google pay options if google pay is not configured in options', () => {
|
|
65
|
-
const options = {
|
|
66
|
-
paymentInstruments: {}
|
|
67
|
-
};
|
|
68
|
-
const availablePaymentMethods = [new _readyToPayModel.default({
|
|
69
|
-
method: 'payment-card',
|
|
70
|
-
feature: {
|
|
71
|
-
name: 'Google Pay',
|
|
72
|
-
merchantName: 'google-pay-merchant-name',
|
|
73
|
-
merchantOrigin: 'google-pay-merchant-origin'
|
|
74
|
-
},
|
|
75
|
-
brands: ['Visa']
|
|
76
|
-
})];
|
|
77
|
-
expect((0, _processDigitalWalletOptions.processDigitalWalletOptions)(options, availablePaymentMethods)).toEqual({});
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import BaseEvent from './base-event';
|
|
2
|
-
|
|
3
|
-
export const PurchaseCompletedEventName = 'rebilly-instruments-purchase-complete';
|
|
4
|
-
|
|
5
|
-
export default class PurchaseCompletedEvent extends BaseEvent {
|
|
6
|
-
constructor({
|
|
7
|
-
name = PurchaseCompletedEventName
|
|
8
|
-
} = {}) {
|
|
9
|
-
super(name);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import Storefront from '../storefront';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {Object} Typeography
|
|
5
|
-
* @param {string} fontFamily - Same as CSS property "font-family". Will be used thoughout the library ui
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @typedef {Object} Color
|
|
10
|
-
* @param {string} primary - CSS hexcode or color name, used to draw user attention
|
|
11
|
-
* @param {string} errorText - CSS hexcode or color name, used to display error messages
|
|
12
|
-
* @param {string} text - CSS hexcode or color name, used to display font color
|
|
13
|
-
* @param {string} buttonText - CSS hexcode or color name, used for buttons text, primary will be it's background
|
|
14
|
-
* @param {string} background - CSS hexcode or color name, the color used for the background of the forms
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @typedef {Object} Theme
|
|
19
|
-
* @param {Color} color - object with color properties
|
|
20
|
-
* @param {Typeography} typography - object with typography options
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @typedef {object} Configs
|
|
25
|
-
* @property {string} organizationId - The Rebilly organization id that all api requests will be associated with.
|
|
26
|
-
* @property {string} publishableKey - The Rebilly publishable api key used to access the storefront api's.
|
|
27
|
-
* @property {string} websiteId - The Rebilly website api.
|
|
28
|
-
* @property {"live" | "sandbox"} apiMode - default "live". The mode for the Rebilly api. default "live".
|
|
29
|
-
* @property {string} css - CSS string that overrides any styles.
|
|
30
|
-
* @property {Theme} theme - CSS string that overrides any styles.
|
|
31
|
-
* @property {object} i18n - object containing the language defintions. (or overrides for existing languages)
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Initialize library with configurations.
|
|
36
|
-
* @param {Configs} configs - The configurations that are to be passed to the library for use.
|
|
37
|
-
*/
|
|
38
|
-
export function Initialize (configs = {}) {
|
|
39
|
-
const {
|
|
40
|
-
organizationId,
|
|
41
|
-
publishableKey,
|
|
42
|
-
websiteId,
|
|
43
|
-
apiMode = 'live',
|
|
44
|
-
i18n,
|
|
45
|
-
theme,
|
|
46
|
-
css,
|
|
47
|
-
_dev = null,
|
|
48
|
-
} = configs;
|
|
49
|
-
|
|
50
|
-
this.configs = {
|
|
51
|
-
organizationId,
|
|
52
|
-
publishableKey,
|
|
53
|
-
websiteId,
|
|
54
|
-
apiMode,
|
|
55
|
-
i18n,
|
|
56
|
-
theme,
|
|
57
|
-
css,
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const storefront = {
|
|
61
|
-
publishableKey: this.configs.publishableKey,
|
|
62
|
-
orgnizationId: this.configs.orgnizationId,
|
|
63
|
-
mode: this.configs.apiMode || 'live'
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (_dev) {
|
|
67
|
-
this.configs._dev = _dev;
|
|
68
|
-
|
|
69
|
-
storefront.liveUrl = _dev.liveUrl || 'https://api.local.rebilly.dev';
|
|
70
|
-
storefront.sandboxUrl = _dev.sandboxUrl || 'https://api-sandbox.local.rebilly.dev';
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
this.storefront = Storefront(storefront);
|
|
74
|
-
};
|