@rebilly/instruments 1.0.2-beta.9 → 3.0.0-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 +187 -0
- package/dist/functions/mount/fetch-data.spec.js +189 -0
- package/dist/functions/mount/index.js +164 -251
- package/dist/functions/mount/mount.spec.js +25 -124
- package/dist/functions/mount/setup-element.js +40 -0
- package/dist/functions/mount/setup-framepay-theme.js +95 -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 +99 -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 +5 -2
- 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/__snapshots__/theme.spec.js.snap +188 -45
- package/dist/style/base/default-theme.js +699 -0
- package/dist/style/base/index.js +48 -16
- package/dist/style/base/theme.js +15 -48
- package/dist/style/base/theme.spec.js +4 -15
- package/dist/style/components/address.js +3 -3
- package/dist/style/components/button.js +32 -22
- package/dist/style/components/divider.js +9 -9
- package/dist/style/components/forms/checkbox.js +12 -9
- package/dist/style/components/forms/field.js +18 -6
- package/dist/style/components/forms/form.js +2 -2
- package/dist/style/components/forms/input.js +54 -13
- package/dist/style/components/forms/label.js +44 -18
- package/dist/style/components/forms/select.js +54 -22
- package/dist/style/components/forms/validation.js +53 -6
- package/dist/style/components/icons.js +4 -4
- package/dist/style/components/loader.js +5 -3
- package/dist/style/components/methods.js +52 -48
- package/dist/style/components/overlay.js +5 -5
- package/dist/style/helpers/index.js +46 -46
- package/dist/style/index.js +3 -1
- package/dist/style/payment-instruments/payment-card.js +4 -4
- package/dist/style/utils/border.js +47 -0
- package/dist/style/utils/color-values.js +37 -3
- package/dist/style/utils/remove-empty-null.js +20 -0
- package/dist/style/vendor/framepay.js +11 -8
- package/dist/style/vendor/postmate.js +2 -2
- package/dist/style/views/confirmation.js +13 -13
- package/dist/style/views/method-selector.js +3 -3
- package/dist/style/views/modal.js +8 -6
- package/dist/style/views/result.js +4 -4
- package/dist/style/views/summary.js +26 -22
- 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 +72 -118
- package/dist/views/common/iframe/base-iframe.js +10 -2
- package/dist/views/common/iframe/modal-iframe.js +50 -4
- 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 +27 -7
- 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 +18 -12
- package/dist/views/result.js +13 -16
- package/dist/views/summary.js +176 -114
- package/dist/views/summary.spec.js +72 -76
- package/package.json +7 -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 +152 -0
- package/src/functions/mount/fetch-data.spec.js +238 -0
- package/src/functions/mount/index.js +131 -244
- package/src/functions/mount/mount.spec.js +35 -141
- package/src/functions/mount/setup-element.js +26 -0
- package/src/functions/mount/setup-framepay-theme.js +82 -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 +103 -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 +5 -2
- 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/__snapshots__/theme.spec.js.snap +188 -45
- package/src/style/base/default-theme.js +674 -0
- package/src/style/base/index.js +48 -16
- package/src/style/base/theme.js +20 -48
- package/src/style/base/theme.spec.js +5 -15
- package/src/style/browserslist.js +1 -3
- package/src/style/components/address.js +3 -3
- package/src/style/components/button.js +32 -22
- package/src/style/components/divider.js +9 -9
- package/src/style/components/forms/checkbox.js +11 -9
- package/src/style/components/forms/field.js +18 -6
- package/src/style/components/forms/form.js +2 -2
- package/src/style/components/forms/input.js +54 -13
- package/src/style/components/forms/label.js +44 -18
- package/src/style/components/forms/select.js +54 -22
- package/src/style/components/forms/validation.js +53 -6
- package/src/style/components/icons.js +4 -4
- package/src/style/components/index.js +1 -1
- package/src/style/components/loader.js +4 -3
- package/src/style/components/methods.js +52 -48
- package/src/style/components/overlay.js +5 -5
- package/src/style/helpers/index.js +46 -46
- package/src/style/index.js +4 -2
- package/src/style/payment-instruments/payment-card.js +4 -4
- package/src/style/utils/border.js +34 -0
- package/src/style/utils/color-values.js +30 -4
- package/src/style/utils/remove-empty-null.js +10 -0
- package/src/style/vendor/framepay.js +12 -9
- package/src/style/vendor/postmate.js +3 -3
- package/src/style/views/confirmation.js +13 -13
- package/src/style/views/index.js +1 -1
- package/src/style/views/method-selector.js +3 -3
- package/src/style/views/modal.js +9 -7
- package/src/style/views/result.js +4 -4
- package/src/style/views/summary.js +26 -22
- 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 +72 -118
- 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 +48 -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 -31
- 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 +36 -22
- package/src/views/result.js +12 -15
- package/src/views/summary.js +175 -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,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _fetchData = require("./fetch-data");
|
|
4
|
+
|
|
5
|
+
var _transactionModel = _interopRequireDefault(require("../../storefront/models/transaction-model"));
|
|
6
|
+
|
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
+
|
|
9
|
+
describe('fetchData function', () => {
|
|
10
|
+
it('Should use correct invoice id for invoiceId', async () => {
|
|
11
|
+
const mockFetchInvoice = jest.fn();
|
|
12
|
+
const invoiceId = 'test-invoice-id';
|
|
13
|
+
const invoiceState = {
|
|
14
|
+
options: {
|
|
15
|
+
invoiceId
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
(0, _fetchData.fetchData)({
|
|
19
|
+
state: invoiceState,
|
|
20
|
+
fetchInvoice: mockFetchInvoice
|
|
21
|
+
});
|
|
22
|
+
expect(mockFetchInvoice).toBeCalledTimes(1);
|
|
23
|
+
expect(mockFetchInvoice).toBeCalledWith(expect.objectContaining({
|
|
24
|
+
data: {
|
|
25
|
+
id: invoiceId
|
|
26
|
+
}
|
|
27
|
+
}));
|
|
28
|
+
});
|
|
29
|
+
it('Should use correct invoice id for transaction with invoiceIds', async () => {
|
|
30
|
+
const mockFetchInvoice = jest.fn();
|
|
31
|
+
const invoiceId = 'test-invoice-id';
|
|
32
|
+
const invoiceState = {
|
|
33
|
+
options: {},
|
|
34
|
+
data: {
|
|
35
|
+
transaction: new _transactionModel.default({
|
|
36
|
+
invoiceIds: [invoiceId]
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
(0, _fetchData.fetchData)({
|
|
41
|
+
state: invoiceState,
|
|
42
|
+
fetchInvoice: mockFetchInvoice
|
|
43
|
+
});
|
|
44
|
+
expect(mockFetchInvoice).toBeCalledTimes(1);
|
|
45
|
+
expect(mockFetchInvoice).toBeCalledWith(expect.objectContaining({
|
|
46
|
+
data: {
|
|
47
|
+
id: invoiceId
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
});
|
|
51
|
+
it('Should not fetch invoice for transaction with no invoice Ids', async () => {
|
|
52
|
+
const mockFetchInvoice = jest.fn();
|
|
53
|
+
const invoiceState = {
|
|
54
|
+
options: {},
|
|
55
|
+
data: {
|
|
56
|
+
transaction: new _transactionModel.default({
|
|
57
|
+
invoiceIds: []
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
(0, _fetchData.fetchData)({
|
|
62
|
+
state: invoiceState,
|
|
63
|
+
fetchInvoice: mockFetchInvoice
|
|
64
|
+
});
|
|
65
|
+
expect(mockFetchInvoice).toBeCalledTimes(0);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe('DataInstance', () => {
|
|
69
|
+
it('Should correctly determine amountAndCurrency', () => {
|
|
70
|
+
const expectedAmountAndCurrency = {
|
|
71
|
+
amount: 10,
|
|
72
|
+
currency: 'USD'
|
|
73
|
+
};
|
|
74
|
+
let fetchedData = new _fetchData.DataInstance({
|
|
75
|
+
state: {
|
|
76
|
+
options: {
|
|
77
|
+
money: { ...expectedAmountAndCurrency
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
expect(fetchedData.amountAndCurrency).toEqual(expect.objectContaining(expectedAmountAndCurrency));
|
|
83
|
+
fetchedData = new _fetchData.DataInstance({
|
|
84
|
+
previewPurchase: {
|
|
85
|
+
total: expectedAmountAndCurrency.amount,
|
|
86
|
+
currency: expectedAmountAndCurrency.currency
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
expect(fetchedData.amountAndCurrency).toEqual(expect.objectContaining(expectedAmountAndCurrency));
|
|
90
|
+
fetchedData = new _fetchData.DataInstance({
|
|
91
|
+
invoice: { ...expectedAmountAndCurrency
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
expect(fetchedData.amountAndCurrency).toEqual(expect.objectContaining(expectedAmountAndCurrency));
|
|
95
|
+
fetchedData = new _fetchData.DataInstance({
|
|
96
|
+
transaction: { ...expectedAmountAndCurrency
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
expect(fetchedData.amountAndCurrency).toEqual(expect.objectContaining(expectedAmountAndCurrency));
|
|
100
|
+
fetchedData = new _fetchData.DataInstance();
|
|
101
|
+
expect(fetchedData.amountAndCurrency).toEqual(expect.objectContaining({
|
|
102
|
+
amount: undefined,
|
|
103
|
+
currency: undefined
|
|
104
|
+
}));
|
|
105
|
+
});
|
|
106
|
+
it('Should correctly determine isPayment', () => {
|
|
107
|
+
let fetchedData = new _fetchData.DataInstance({
|
|
108
|
+
state: {
|
|
109
|
+
options: {
|
|
110
|
+
money: true
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
expect(fetchedData.isPayment).toBeTruthy();
|
|
115
|
+
fetchedData = new _fetchData.DataInstance({
|
|
116
|
+
invoice: true
|
|
117
|
+
});
|
|
118
|
+
expect(fetchedData.isPayment).toBeTruthy();
|
|
119
|
+
fetchedData = new _fetchData.DataInstance({
|
|
120
|
+
transaction: true
|
|
121
|
+
});
|
|
122
|
+
expect(fetchedData.isPayment).toBeTruthy();
|
|
123
|
+
fetchedData = new _fetchData.DataInstance({
|
|
124
|
+
previewPurchase: true
|
|
125
|
+
});
|
|
126
|
+
expect(fetchedData.isPayment).toBeFalsy();
|
|
127
|
+
fetchedData = new _fetchData.DataInstance({});
|
|
128
|
+
expect(fetchedData.isPayment).toBeFalsy();
|
|
129
|
+
});
|
|
130
|
+
it('Should correctly determine isPurchase', () => {
|
|
131
|
+
let fetchedData = new _fetchData.DataInstance({
|
|
132
|
+
previewPurchase: true
|
|
133
|
+
});
|
|
134
|
+
expect(fetchedData.isPurchase).toBeTruthy();
|
|
135
|
+
fetchedData = new _fetchData.DataInstance({
|
|
136
|
+
state: {
|
|
137
|
+
options: {
|
|
138
|
+
money: true
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
expect(fetchedData.isPurchase).toBeFalsy();
|
|
143
|
+
fetchedData = new _fetchData.DataInstance({
|
|
144
|
+
invoice: true
|
|
145
|
+
});
|
|
146
|
+
expect(fetchedData.isPurchase).toBeFalsy();
|
|
147
|
+
fetchedData = new _fetchData.DataInstance({
|
|
148
|
+
transaction: true
|
|
149
|
+
});
|
|
150
|
+
expect(fetchedData.isPurchase).toBeFalsy();
|
|
151
|
+
fetchedData = new _fetchData.DataInstance({});
|
|
152
|
+
expect(fetchedData.isPurchase).toBeFalsy();
|
|
153
|
+
});
|
|
154
|
+
it('Should get summaryItems', () => {
|
|
155
|
+
const expectedSummaryItems = {
|
|
156
|
+
discountsAmount: 1,
|
|
157
|
+
shippingAmount: 2,
|
|
158
|
+
subtotalAmount: 3,
|
|
159
|
+
taxAmount: 4
|
|
160
|
+
};
|
|
161
|
+
let fetchedData = new _fetchData.DataInstance({
|
|
162
|
+
previewPurchase: { ...expectedSummaryItems
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
expect(fetchedData.summaryItems).toEqual(expect.objectContaining(expectedSummaryItems));
|
|
166
|
+
fetchedData = new _fetchData.DataInstance({
|
|
167
|
+
invoice: { ...expectedSummaryItems
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
expect(fetchedData.summaryItems).toEqual(expect.objectContaining(expectedSummaryItems));
|
|
171
|
+
});
|
|
172
|
+
it('Should get summaryLineItems', () => {
|
|
173
|
+
const expectedSummaryLineItems = [{
|
|
174
|
+
line: 'item'
|
|
175
|
+
}];
|
|
176
|
+
let fetchedData = new _fetchData.DataInstance({
|
|
177
|
+
previewPurchase: {
|
|
178
|
+
lineItems: expectedSummaryLineItems
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
expect(fetchedData.summaryLineItems).toEqual(expectedSummaryLineItems);
|
|
182
|
+
fetchedData = new _fetchData.DataInstance({
|
|
183
|
+
invoice: {
|
|
184
|
+
items: expectedSummaryLineItems
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
expect(fetchedData.summaryLineItems).toEqual(expectedSummaryLineItems);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
@@ -3,17 +3,31 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.mount = mount;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _summary = require("../../views/summary");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _methodSelector = require("../../views/method-selector");
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _fetchData = require("./fetch-data");
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _show = require("../show");
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _on = require("../on");
|
|
17
|
+
|
|
18
|
+
var _setupElement = _interopRequireDefault(require("./setup-element"));
|
|
19
|
+
|
|
20
|
+
var _setupStorefront = _interopRequireDefault(require("./setup-storefront"));
|
|
21
|
+
|
|
22
|
+
var _setupOptions = _interopRequireDefault(require("./setup-options"));
|
|
23
|
+
|
|
24
|
+
var _setupFramepay = _interopRequireDefault(require("./setup-framepay"));
|
|
25
|
+
|
|
26
|
+
var _setupStyles = _interopRequireDefault(require("./setup-styles"));
|
|
27
|
+
|
|
28
|
+
var _setupI18n = _interopRequireDefault(require("./setup-i18n"));
|
|
29
|
+
|
|
30
|
+
var _setupFramepayTheme = _interopRequireDefault(require("./setup-framepay-theme"));
|
|
17
31
|
|
|
18
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
33
|
|
|
@@ -24,282 +38,181 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
24
38
|
* @property {string} planId - The Rebilly id of the plan.
|
|
25
39
|
* @property {number} quantity - The number of the plans to be purchased.
|
|
26
40
|
* @property {string} thumbnail - The source img for the product. Recommend 100px by 100px.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* @
|
|
31
|
-
* @property {
|
|
32
|
-
*
|
|
33
|
-
* @
|
|
34
|
-
* @property {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* @typedef {
|
|
39
|
-
* @
|
|
40
|
-
*
|
|
41
|
-
* @
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* @
|
|
47
|
-
*
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
* @typedef {object} PaymentCard
|
|
52
|
-
* @param {boolean} popup - default: false. Show method as a button with a form popup
|
|
53
|
-
* <br>Otherwise the form will be mounted inline.
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
/**
|
|
41
|
+
*
|
|
42
|
+
* @typedef {object} GooglePayDisplayOptions
|
|
43
|
+
* @property {"back" | "white"} [buttonColor=black] - Color of google pay button
|
|
44
|
+
* @property {"short" | "long"} [buttonType=short] - The length of the button
|
|
45
|
+
* @property {string} [buttonHeight=44px] - The value and units of the button to match other payment buttons
|
|
46
|
+
*
|
|
47
|
+
* @typedef {object} ApplePayDisplayOptions
|
|
48
|
+
* @property {"back" | "white"} [buttonColor=black] - Color of apple pay button
|
|
49
|
+
* @property {"short" | "long"} [buttonType=short] - The length of the button
|
|
50
|
+
* @property {string} [buttonHeight=44px] - The value and units of the button to match other payment buttons
|
|
51
|
+
*
|
|
52
|
+
* @typedef {object} ApplePayMerchantOptions
|
|
53
|
+
* @property {string} merchantName - The name of the merchant store.
|
|
54
|
+
*
|
|
55
|
+
* @typedef {object} GooglePay
|
|
56
|
+
* @property {GooglePayDisplayOptions} displayOptions - display options for google pay instrument
|
|
57
|
+
*
|
|
58
|
+
* @typedef {object} ApplePay
|
|
59
|
+
* @property {ApplePayDisplayOptions} displayOptions - display options for apple pay instrument
|
|
60
|
+
* @property {ApplePayMerchantOptions} merchantOptions - merchant options for apple pay instrument
|
|
61
|
+
*
|
|
62
|
+
* @typedef {object} PaymentCard
|
|
63
|
+
* @property {boolean} [popup=true] - Show method as a button with a form popup. Otherwise the form will be mounted inline.
|
|
64
|
+
*
|
|
57
65
|
* @typedef {object} Address
|
|
58
|
-
* @
|
|
59
|
-
* @
|
|
60
|
-
* @
|
|
61
|
-
* @
|
|
62
|
-
* @
|
|
63
|
-
*
|
|
64
|
-
* <br>First name and last name are always required. Country is always required if the products require shipping.
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
/**
|
|
66
|
+
* @property {string} [name=default] - One of default, combined, or stacked.
|
|
67
|
+
* @property {string} [region=default] - One of default, split, or stacked.
|
|
68
|
+
* @property {Array.<"organization" | "phoneNumber">} show - Show extra fields listed.
|
|
69
|
+
* @property {Array.<"address" | "address2" | "email | "country" | "region" | "postalCode"">} hide - Hide the listed fields.
|
|
70
|
+
* @property {Array.<"organization" | "address" | "address2" | "email" | "phoneNumber" | "country" | "region" | "postalCode">} require - Require the listed fields.
|
|
71
|
+
*
|
|
68
72
|
* @typedef {object} PaymentInstruments
|
|
69
|
-
* @
|
|
70
|
-
*
|
|
71
|
-
* @
|
|
72
|
-
* @
|
|
73
|
-
* @
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
* @
|
|
78
|
-
* @param {boolean} autoConfirmation - default: true. Will mount the confirmation screen after `instrument-ready`
|
|
79
|
-
* <br>event is triggered. Will need to trigger purchase manually if set to false.
|
|
80
|
-
* <br>Can use RebillyInstruments.show('confirmation', options) to mount defautl component
|
|
81
|
-
* @param {boolean} autoResult - default: true. Show results of transaction after `purchase-completed` event is triggered
|
|
82
|
-
* <br>Will need to handle purchase result manually if set to false.
|
|
83
|
-
* <br>Can use RebillyInstruments.show('result', options) to display default component
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* @typedef {object} Options
|
|
88
|
-
* @property {Intent} intent - The information required for purchaseing or vaulting an instrument
|
|
89
|
-
* @property {PaymentInstruments} paymentInstruments - settings for various payment instruments
|
|
90
|
-
* @property {Features} features - flags to enable and disable different features
|
|
91
|
-
* @property {string} locale - default: auto. Language to render component text
|
|
73
|
+
* @property {boolean} [compactExpressInstruments=true] - Show express methods as inline pill buttons, or list of full width button.
|
|
74
|
+
* @property {PaymentCard} paymentCard - settings for payment card instruments
|
|
75
|
+
* @property {GooglePay} googlePay - settings for google pay instruments
|
|
76
|
+
* @property {ApplePay} applePay - settings for apple pay instruments
|
|
77
|
+
* @property {Address} address - customization for address components for all payment instruments.
|
|
78
|
+
*
|
|
79
|
+
* @typedef {object} Features
|
|
80
|
+
* @property {boolean} [autoConfirmation=true] - Will mount the confirmation screen after `instrument-ready` event is triggered.
|
|
81
|
+
* @property {boolean} [autoResult=true] - Show results of transaction after `purchase-completed` event is triggered
|
|
92
82
|
*/
|
|
93
83
|
|
|
94
84
|
/**
|
|
95
85
|
* Mount library with configurations.
|
|
96
|
-
* @param {
|
|
97
|
-
* @param {
|
|
98
|
-
* @param {
|
|
86
|
+
* @param {object} options - The options object
|
|
87
|
+
* @param {object} options.state - Global state
|
|
88
|
+
* @param {string | HTMLElement} options.form - The CSS class or HTML element were the form will be mounted.
|
|
89
|
+
* @param {string | HTMLElement} options.summary - The CSS class or HTML element were the summary will be mounted.
|
|
90
|
+
* @param {Item[]} options.items - Which plans the customer is purchasing.
|
|
91
|
+
* @param {string} options.invoiceId - The Rebilly id of the invoice used for purchasing.
|
|
92
|
+
* @param {string} options.customerJwt - The customer token to access the invoice.
|
|
93
|
+
* @param {string} [options.countryCode=USD] - The country code for the transaction
|
|
94
|
+
* @param {PaymentInstruments} options.paymentInstruments - settings for various payment instruments
|
|
95
|
+
* @param {Features} options.features - flags to enable and disable different features
|
|
96
|
+
* @param {string} options.locale - default: auto. Language to render component text
|
|
99
97
|
*/
|
|
100
|
-
async function
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
options = {},
|
|
104
|
-
_dev = null
|
|
98
|
+
async function mount({
|
|
99
|
+
state,
|
|
100
|
+
...options
|
|
105
101
|
} = {}) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
this.form = form;
|
|
109
|
-
this.summary = summary;
|
|
110
|
-
this.mainStyle = null;
|
|
111
|
-
this._dev = _dev;
|
|
112
|
-
const framePayUrls = {
|
|
113
|
-
script: _dev ? _dev.framePayScriptLink || 'https://framepay.rebilly.com/rebilly.js' : 'https://framepay.rebilly.com/rebilly.js',
|
|
114
|
-
style: _dev ? _dev.framePayStyleLink || 'https://framepay.rebilly.com/rebilly.css' : 'https://framepay.rebilly.com/rebilly.css'
|
|
115
|
-
};
|
|
116
|
-
const _computed = {
|
|
117
|
-
paymentMethodsUrl: _dev ? _dev.paymentMethodsUrl || 'https://forms.local.rebilly.dev:3000' : 'https://forms.secure-payments.app'
|
|
118
|
-
};
|
|
119
|
-
const OPTIONS_DEFAULTS = {
|
|
120
|
-
intent: {
|
|
121
|
-
countryCode: 'US'
|
|
122
|
-
},
|
|
123
|
-
locale: 'auto',
|
|
124
|
-
paymentInstruments: {
|
|
125
|
-
address: {
|
|
126
|
-
name: 'default',
|
|
127
|
-
region: 'default',
|
|
128
|
-
hide: [],
|
|
129
|
-
show: [],
|
|
130
|
-
require: []
|
|
131
|
-
},
|
|
132
|
-
compactExpressInstruments: true,
|
|
133
|
-
googlePay: {
|
|
134
|
-
displayOptions: {
|
|
135
|
-
buttonColor: 'black',
|
|
136
|
-
buttonType: 'short',
|
|
137
|
-
buttonHeight: '44px'
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
paymentCard: {
|
|
141
|
-
popup: false
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
features: {
|
|
145
|
-
autoConfirmation: true,
|
|
146
|
-
autoResult: true
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
const combinedOptions = { ...options,
|
|
150
|
-
_computed
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
if (_dev) {
|
|
154
|
-
combinedOptions._dev = _dev;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
this.options = (0, _lodash.default)(OPTIONS_DEFAULTS, combinedOptions);
|
|
158
|
-
this.form = (0, _utils.processPropertyAsDOMElement)({
|
|
159
|
-
prop: this.form,
|
|
160
|
-
propName: 'form'
|
|
161
|
-
});
|
|
162
|
-
this.summary = (0, _utils.processPropertyAsDOMElement)({
|
|
163
|
-
prop: this.summary,
|
|
164
|
-
propName: 'summary',
|
|
165
|
-
isRequired: false
|
|
166
|
-
}); // Setup loader
|
|
167
|
-
|
|
168
|
-
this.loader.addDOMElement({
|
|
169
|
-
el: this.form
|
|
170
|
-
});
|
|
171
|
-
this.loader.addDOMElement({
|
|
172
|
-
section: 'summary',
|
|
173
|
-
el: this.summary
|
|
174
|
-
}); // Adds base stylesheet
|
|
102
|
+
try {
|
|
103
|
+
var _state$data$transacti;
|
|
175
104
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
element: 'style',
|
|
179
|
-
attributes: {
|
|
180
|
-
type: 'text/css'
|
|
181
|
-
},
|
|
182
|
-
content: this.mainStyle,
|
|
183
|
-
target: 'head'
|
|
184
|
-
}); // Adds configs CSS to override any styles
|
|
105
|
+
state.data = {};
|
|
106
|
+
state.options = {}; // Setup DOM
|
|
185
107
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
attributes: {
|
|
190
|
-
type: 'text/css'
|
|
191
|
-
},
|
|
192
|
-
content: this.configs.css,
|
|
193
|
-
target: 'head'
|
|
108
|
+
state.form = (0, _setupElement.default)({
|
|
109
|
+
element: 'form',
|
|
110
|
+
options
|
|
194
111
|
});
|
|
195
|
-
|
|
196
|
-
|
|
112
|
+
state.summary = (0, _setupElement.default)({
|
|
113
|
+
element: 'summary',
|
|
114
|
+
options
|
|
115
|
+
}); // Setup loader
|
|
197
116
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
element: 'script',
|
|
201
|
-
attributes: {
|
|
202
|
-
'framepay': 'script',
|
|
203
|
-
src: framePayUrls.script
|
|
204
|
-
},
|
|
205
|
-
target: 'head'
|
|
117
|
+
state.loader.addDOMElement({
|
|
118
|
+
el: state.form
|
|
206
119
|
});
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
(0, _utils.addDOMElement)({
|
|
211
|
-
element: 'link',
|
|
212
|
-
attributes: {
|
|
213
|
-
'framepay': 'stylesheet',
|
|
214
|
-
href: framePayUrls.style,
|
|
215
|
-
rel: 'stylesheet'
|
|
216
|
-
},
|
|
217
|
-
target: 'head'
|
|
120
|
+
state.loader.addDOMElement({
|
|
121
|
+
section: 'summary',
|
|
122
|
+
el: state.summary
|
|
218
123
|
});
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
try {
|
|
222
|
-
var _riskMetadata$browser, _this$configs2;
|
|
223
|
-
|
|
224
|
-
this.loader.startLoading({
|
|
124
|
+
state.loader.startLoading({
|
|
225
125
|
section: 'summary',
|
|
226
126
|
id: 'initSummary'
|
|
227
127
|
});
|
|
228
|
-
|
|
128
|
+
state.loader.startLoading({
|
|
229
129
|
id: 'initForm'
|
|
230
|
-
});
|
|
231
|
-
const {
|
|
232
|
-
riskMetadata
|
|
233
|
-
} = await (0, _riskDataCollector.collectData)();
|
|
234
|
-
|
|
235
|
-
if (this.options.locale === 'auto' && riskMetadata !== null && riskMetadata !== void 0 && (_riskMetadata$browser = riskMetadata.browserData) !== null && _riskMetadata$browser !== void 0 && _riskMetadata$browser.language) {
|
|
236
|
-
const {
|
|
237
|
-
browserData: {
|
|
238
|
-
language
|
|
239
|
-
}
|
|
240
|
-
} = riskMetadata;
|
|
241
|
-
this.options.locale = language;
|
|
242
|
-
}
|
|
130
|
+
}); // Setup state
|
|
243
131
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
132
|
+
state.storefront = (0, _setupStorefront.default)({
|
|
133
|
+
options
|
|
134
|
+
});
|
|
135
|
+
state.options = (0, _setupOptions.default)({
|
|
136
|
+
options
|
|
137
|
+
});
|
|
138
|
+
state.mainStyle = await (0, _setupStyles.default)({
|
|
139
|
+
options
|
|
140
|
+
});
|
|
141
|
+
state.data = await (0, _fetchData.fetchData)({
|
|
142
|
+
state
|
|
143
|
+
});
|
|
144
|
+
state.options.themeFramepay = await (0, _setupFramepayTheme.default)({
|
|
145
|
+
state,
|
|
146
|
+
options
|
|
147
|
+
});
|
|
148
|
+
const i18n = (0, _setupI18n.default)({
|
|
149
|
+
state
|
|
150
|
+
});
|
|
151
|
+
(0, _setupFramepay.default)({
|
|
152
|
+
state
|
|
253
153
|
});
|
|
254
|
-
this.hasMounted = true;
|
|
255
154
|
|
|
256
|
-
if (
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
mainStyle: this.mainStyle,
|
|
260
|
-
readyToPay,
|
|
261
|
-
plans,
|
|
262
|
-
products
|
|
263
|
-
};
|
|
155
|
+
if (state.data.transaction && ((_state$data$transacti = state.data.transaction) === null || _state$data$transacti === void 0 ? void 0 : _state$data$transacti.type) === 'setup') {
|
|
156
|
+
state.options.transactionType = 'setup';
|
|
157
|
+
} // Mount content
|
|
264
158
|
|
|
265
|
-
this._mountMethodSelector(this.formOptions);
|
|
266
|
-
}
|
|
267
159
|
|
|
268
|
-
if (
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
products
|
|
274
|
-
};
|
|
160
|
+
if (state.form) {
|
|
161
|
+
(0, _methodSelector.mountMethodSelector)({
|
|
162
|
+
state
|
|
163
|
+
});
|
|
164
|
+
}
|
|
275
165
|
|
|
276
|
-
|
|
166
|
+
if (state.summary) {
|
|
167
|
+
(0, _summary.mountSummary)({
|
|
168
|
+
state
|
|
169
|
+
});
|
|
277
170
|
}
|
|
171
|
+
|
|
172
|
+
i18n({
|
|
173
|
+
state
|
|
174
|
+
});
|
|
175
|
+
state.hasMounted = true;
|
|
278
176
|
} catch (error) {
|
|
279
177
|
throw error;
|
|
280
178
|
}
|
|
281
179
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
180
|
+
if (state.options.features.autoConfirmation) {
|
|
181
|
+
(0, _on.on)({
|
|
182
|
+
eventName: 'instrument-ready',
|
|
183
|
+
callback: payload => {
|
|
184
|
+
(0, _show.show)({
|
|
185
|
+
componentName: 'confirmation',
|
|
186
|
+
payload,
|
|
187
|
+
state
|
|
188
|
+
});
|
|
189
|
+
}
|
|
292
190
|
});
|
|
293
191
|
}
|
|
294
192
|
|
|
295
|
-
if (
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
193
|
+
if (state.options.features.autoResult) {
|
|
194
|
+
if (state.options.transactionType === 'setup') {
|
|
195
|
+
(0, _on.on)({
|
|
196
|
+
eventName: 'setup-completed',
|
|
197
|
+
callback: payload => {
|
|
198
|
+
(0, _show.show)({
|
|
199
|
+
componentName: 'result',
|
|
200
|
+
payload,
|
|
201
|
+
state
|
|
202
|
+
});
|
|
203
|
+
}
|
|
300
204
|
});
|
|
301
|
-
}
|
|
205
|
+
} else {
|
|
206
|
+
(0, _on.on)({
|
|
207
|
+
eventName: 'purchase-completed',
|
|
208
|
+
callback: payload => {
|
|
209
|
+
(0, _show.show)({
|
|
210
|
+
componentName: 'result',
|
|
211
|
+
payload,
|
|
212
|
+
state
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
302
217
|
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
;
|
|
218
|
+
}
|