@rebilly/instruments 3.1.0-beta.0 → 3.1.4-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/dist/index.js +88 -107
- package/dist/index.min.js +88 -0
- package/package.json +17 -6
- package/rollup.config.js +84 -0
- package/src/functions/mount/fetch-data.js +13 -1
- package/src/functions/mount/index.js +6 -42
- package/src/functions/mount/setup-framepay-theme.js +2 -2
- package/src/functions/mount/setup-options.js +3 -0
- package/src/functions/mount/setup-user-flow.js +49 -0
- package/src/functions/purchase.js +1 -1
- package/src/functions/setup.js +1 -1
- package/src/functions/show.spec.js +1 -1
- package/src/i18n/en.json +3 -0
- package/src/index.js +1 -61
- package/src/instance.js +65 -0
- package/src/{index.spec.js → instance.spec.js} +2 -1
- package/src/loader/index.js +21 -1
- package/src/storefront/models/ready-to-pay-model.js +13 -2
- package/src/storefront/plans.js +8 -4
- package/src/storefront/plans.spec.js +8 -2
- package/src/storefront/products.js +8 -4
- package/src/storefront/products.spec.js +8 -2
- package/src/storefront/ready-to-pay.js +5 -4
- package/src/style/components/button.js +1 -0
- package/src/style/components/loader.js +2 -1
- package/src/style/payment-instruments/payment-card.js +2 -1
- package/src/style/utils/remove-empty-null.js +9 -9
- package/src/style/vendor/postmate.js +13 -0
- package/src/style/views/confirmation.js +2 -1
- package/src/views/common/iframe/base-iframe.js +2 -0
- package/src/views/common/iframe/event-listeners.js +10 -0
- package/src/views/common/iframe/method-iframe.js +3 -1
- package/src/views/confirmation.js +1 -0
- package/src/views/method-selector/express-methods/{google-pay.js → index.js} +3 -2
- package/src/views/method-selector/mount-express-methods.js +6 -18
- package/src/views/result.js +1 -0
- package/tests/mocks/rebilly-instruments-mock.js +2 -2
- package/dist/events/base-event.js +0 -66
- package/dist/events/events.spec.js +0 -18
- package/dist/events/index.js +0 -22
- package/dist/functions/destroy.js +0 -34
- package/dist/functions/destroy.spec.js +0 -69
- package/dist/functions/mount/fetch-data.js +0 -187
- package/dist/functions/mount/fetch-data.spec.js +0 -189
- package/dist/functions/mount/index.js +0 -218
- package/dist/functions/mount/mount.spec.js +0 -64
- package/dist/functions/mount/setup-element.js +0 -40
- package/dist/functions/mount/setup-framepay-theme.js +0 -95
- package/dist/functions/mount/setup-framepay.js +0 -46
- package/dist/functions/mount/setup-i18n.js +0 -33
- package/dist/functions/mount/setup-options.js +0 -99
- package/dist/functions/mount/setup-options.spec.js +0 -66
- package/dist/functions/mount/setup-storefront.js +0 -34
- package/dist/functions/mount/setup-styles.js +0 -43
- package/dist/functions/on.js +0 -40
- package/dist/functions/on.spec.js +0 -55
- package/dist/functions/purchase.js +0 -158
- package/dist/functions/purchase.spec.js +0 -74
- package/dist/functions/setup.js +0 -85
- package/dist/functions/setup.spec.js +0 -87
- package/dist/functions/show.js +0 -55
- package/dist/functions/show.spec.js +0 -61
- package/dist/functions/update.js +0 -74
- package/dist/functions/update.spec.js +0 -86
- package/dist/i18n/en.json +0 -22
- package/dist/i18n/es.json +0 -22
- package/dist/i18n/i18n.spec.js +0 -22
- package/dist/i18n/index.js +0 -72
- package/dist/index.spec.js +0 -35
- package/dist/loader/index.js +0 -94
- package/dist/loader/loader.spec.js +0 -69
- package/dist/storefront/index.js +0 -73
- package/dist/storefront/invoices.js +0 -27
- package/dist/storefront/models/base-model.js +0 -18
- package/dist/storefront/models/invoice-model.js +0 -14
- package/dist/storefront/models/plan-model.js +0 -14
- package/dist/storefront/models/product-model.js +0 -14
- package/dist/storefront/models/ready-to-pay-model.js +0 -46
- package/dist/storefront/models/summary-model.js +0 -79
- package/dist/storefront/models/transaction-model.js +0 -31
- package/dist/storefront/payment-instruments.js +0 -47
- package/dist/storefront/payment-instruments.spec.js +0 -55
- package/dist/storefront/plans.js +0 -37
- package/dist/storefront/plans.spec.js +0 -64
- package/dist/storefront/products.js +0 -40
- package/dist/storefront/products.spec.js +0 -65
- package/dist/storefront/purchase.js +0 -43
- package/dist/storefront/purchase.spec.js +0 -48
- package/dist/storefront/ready-to-pay.js +0 -58
- package/dist/storefront/ready-to-pay.spec.js +0 -69
- package/dist/storefront/storefront.spec.js +0 -15
- package/dist/storefront/summary.js +0 -55
- package/dist/storefront/summary.spec.js +0 -124
- package/dist/storefront/transactions.js +0 -27
- package/dist/style/base/__snapshots__/theme.spec.js.snap +0 -227
- package/dist/style/base/default-theme.js +0 -804
- package/dist/style/base/index.js +0 -104
- package/dist/style/base/theme.js +0 -41
- package/dist/style/base/theme.spec.js +0 -19
- package/dist/style/browserslist.js +0 -8
- package/dist/style/components/address.js +0 -64
- package/dist/style/components/button.js +0 -87
- package/dist/style/components/divider.js +0 -48
- package/dist/style/components/forms/checkbox.js +0 -86
- package/dist/style/components/forms/field.js +0 -65
- package/dist/style/components/forms/form.js +0 -28
- package/dist/style/components/forms/input.js +0 -86
- package/dist/style/components/forms/label.js +0 -64
- package/dist/style/components/forms/select.js +0 -95
- package/dist/style/components/forms/validation.js +0 -81
- package/dist/style/components/icons.js +0 -22
- package/dist/style/components/index.js +0 -57
- package/dist/style/components/loader.js +0 -50
- package/dist/style/components/methods.js +0 -108
- package/dist/style/components/overlay.js +0 -33
- package/dist/style/helpers/index.js +0 -59
- package/dist/style/index.js +0 -50
- package/dist/style/payment-instruments/content.js +0 -17
- package/dist/style/payment-instruments/index.js +0 -20
- package/dist/style/payment-instruments/payment-card.js +0 -35
- package/dist/style/utils/border.js +0 -47
- package/dist/style/utils/color-values.js +0 -58
- package/dist/style/utils/remove-empty-null.js +0 -20
- package/dist/style/vendor/framepay.js +0 -37
- package/dist/style/vendor/postmate.js +0 -17
- package/dist/style/views/confirmation.js +0 -85
- package/dist/style/views/index.js +0 -29
- package/dist/style/views/method-selector.js +0 -20
- package/dist/style/views/modal.js +0 -93
- package/dist/style/views/result.js +0 -61
- package/dist/style/views/summary.js +0 -127
- package/dist/utils/add-dom-element.js +0 -26
- package/dist/utils/format-currency.js +0 -15
- package/dist/utils/has-valid-css-selector.js +0 -11
- package/dist/utils/index.js +0 -55
- package/dist/utils/is-dom-element.js +0 -10
- package/dist/utils/process-property-as-dom-element.js +0 -38
- package/dist/utils/sleep.js +0 -10
- package/dist/views/__snapshots__/summary.spec.js.snap +0 -246
- package/dist/views/common/iframe/base-iframe.js +0 -59
- package/dist/views/common/iframe/event-listeners.js +0 -50
- package/dist/views/common/iframe/index.js +0 -19
- package/dist/views/common/iframe/method-iframe.js +0 -33
- package/dist/views/common/iframe/modal-iframe.js +0 -84
- package/dist/views/common/iframe/view-iframe.js +0 -31
- package/dist/views/common/render-utilities.js +0 -11
- package/dist/views/confirmation.js +0 -92
- package/dist/views/method-selector/__snapshots__/method-selector.spec.js.snap +0 -3
- package/dist/views/method-selector/express-methods/apple-pay.js +0 -92
- package/dist/views/method-selector/express-methods/google-pay.js +0 -31
- package/dist/views/method-selector/express-methods/paypal.js +0 -19
- package/dist/views/method-selector/generate-digital-wallet.js +0 -68
- package/dist/views/method-selector/generate-digital-wallet.spec.js +0 -135
- package/dist/views/method-selector/get-method-data.js +0 -25
- package/dist/views/method-selector/get-payment-methods.js +0 -66
- package/dist/views/method-selector/get-payment-methods.spec.js +0 -46
- package/dist/views/method-selector/index.js +0 -122
- package/dist/views/method-selector/method-selector.spec.js +0 -124
- package/dist/views/method-selector/mount-express-methods.js +0 -69
- package/dist/views/method-selector/mount-methods.js +0 -74
- package/dist/views/modal.js +0 -88
- package/dist/views/result.js +0 -40
- package/dist/views/summary.js +0 -215
- package/dist/views/summary.spec.js +0 -134
- package/src/views/method-selector/express-methods/paypal.js +0 -7
|
@@ -1,189 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.mount = mount;
|
|
7
|
-
|
|
8
|
-
var _summary = require("../../views/summary");
|
|
9
|
-
|
|
10
|
-
var _methodSelector = require("../../views/method-selector");
|
|
11
|
-
|
|
12
|
-
var _fetchData = require("./fetch-data");
|
|
13
|
-
|
|
14
|
-
var _show = require("../show");
|
|
15
|
-
|
|
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"));
|
|
31
|
-
|
|
32
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
33
|
-
|
|
34
|
-
/* eslint-disable max-len */
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @typedef {object} Item
|
|
38
|
-
* @property {string} planId - The Rebilly id of the plan.
|
|
39
|
-
* @property {number} quantity - The number of the plans to be purchased.
|
|
40
|
-
* @property {string} thumbnail - The source img for the product. Recommend 100px by 100px.
|
|
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
|
-
*
|
|
65
|
-
* @typedef {object} Address
|
|
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
|
-
*
|
|
72
|
-
* @typedef {object} PaymentInstruments
|
|
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
|
|
82
|
-
*/
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Mount library with configurations.
|
|
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
|
|
97
|
-
*/
|
|
98
|
-
async function mount({
|
|
99
|
-
state,
|
|
100
|
-
...options
|
|
101
|
-
} = {}) {
|
|
102
|
-
try {
|
|
103
|
-
var _state$data$transacti;
|
|
104
|
-
|
|
105
|
-
state.data = {};
|
|
106
|
-
state.options = {}; // Setup DOM
|
|
107
|
-
|
|
108
|
-
state.form = (0, _setupElement.default)({
|
|
109
|
-
element: 'form',
|
|
110
|
-
options
|
|
111
|
-
});
|
|
112
|
-
state.summary = (0, _setupElement.default)({
|
|
113
|
-
element: 'summary',
|
|
114
|
-
options
|
|
115
|
-
}); // Setup loader
|
|
116
|
-
|
|
117
|
-
state.loader.addDOMElement({
|
|
118
|
-
el: state.form
|
|
119
|
-
});
|
|
120
|
-
state.loader.addDOMElement({
|
|
121
|
-
section: 'summary',
|
|
122
|
-
el: state.summary
|
|
123
|
-
});
|
|
124
|
-
state.loader.startLoading({
|
|
125
|
-
section: 'summary',
|
|
126
|
-
id: 'initSummary'
|
|
127
|
-
});
|
|
128
|
-
state.loader.startLoading({
|
|
129
|
-
id: 'initForm'
|
|
130
|
-
}); // Setup state
|
|
131
|
-
|
|
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
|
|
153
|
-
});
|
|
154
|
-
|
|
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
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (state.form) {
|
|
161
|
-
(0, _methodSelector.mountMethodSelector)({
|
|
162
|
-
state
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (state.summary) {
|
|
167
|
-
(0, _summary.mountSummary)({
|
|
168
|
-
state
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
i18n({
|
|
173
|
-
state
|
|
174
|
-
});
|
|
175
|
-
state.hasMounted = true;
|
|
176
|
-
} catch (error) {
|
|
177
|
-
throw error;
|
|
178
|
-
}
|
|
179
|
-
|
|
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
|
-
}
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
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
|
-
}
|
|
204
|
-
});
|
|
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
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _rebillyInstrumentsMock = require("../../../tests/mocks/rebilly-instruments-mock");
|
|
4
|
-
|
|
5
|
-
var _instruments = require("@rebilly/instruments");
|
|
6
|
-
|
|
7
|
-
var _mswWhenThen = require("msw-when-then");
|
|
8
|
-
|
|
9
|
-
var _server = require("../../../tests/msw/server");
|
|
10
|
-
|
|
11
|
-
var _storefrontApiMock = require("../../../tests/mocks/storefront-api-mock");
|
|
12
|
-
|
|
13
|
-
var _planModel = _interopRequireDefault(require("../../storefront/models/plan-model"));
|
|
14
|
-
|
|
15
|
-
var _productModel = _interopRequireDefault(require("../../storefront/models/product-model"));
|
|
16
|
-
|
|
17
|
-
var _summaryModel = _interopRequireDefault(require("../../storefront/models/summary-model"));
|
|
18
|
-
|
|
19
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
-
|
|
21
|
-
describe('RebillyInstruments instance', () => {
|
|
22
|
-
it("should inject HTML to the merchant's website", async () => {
|
|
23
|
-
const framePayScriptUrl = 'https://framepay.rebilly.com/rebilly.js';
|
|
24
|
-
const framePayStyleUrl = 'https://dev.framepay.rebilly.com/rebilly.css';
|
|
25
|
-
const options = {
|
|
26
|
-
form: '.form-selector',
|
|
27
|
-
summary: '.summary-selector',
|
|
28
|
-
locale: 'auto',
|
|
29
|
-
items: [{
|
|
30
|
-
planId: 'test-plan-id-1',
|
|
31
|
-
quantity: 1
|
|
32
|
-
}],
|
|
33
|
-
theme: {
|
|
34
|
-
colorBackground: '#000'
|
|
35
|
-
},
|
|
36
|
-
css: `
|
|
37
|
-
.rebilly-instruments-summary-line-item-synopsis-title {
|
|
38
|
-
color: rgb(0, 68, 212);
|
|
39
|
-
}
|
|
40
|
-
`,
|
|
41
|
-
_dev: {
|
|
42
|
-
framePayStyleLink: framePayStyleUrl
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)(options); // Mounts form and summary
|
|
46
|
-
|
|
47
|
-
const summarySelector = document.querySelector('.summary-selector');
|
|
48
|
-
expect(summarySelector.innerHTML).toMatch('My Product'); // Theme config overrides initial styles
|
|
49
|
-
|
|
50
|
-
const SUMMARY_CONTAINER = summarySelector.querySelector('.rebilly-instruments-content');
|
|
51
|
-
expect(getComputedStyle(SUMMARY_CONTAINER).getPropertyValue('--rebilly-colorBackground')).toEqual('#000'); // CSS config property overrides initial styles
|
|
52
|
-
|
|
53
|
-
const LINE_ITEM_TITLE = document.querySelector('.rebilly-instruments-summary-line-item-synopsis-title');
|
|
54
|
-
expect(getComputedStyle(LINE_ITEM_TITLE).color).toEqual('rgb(0, 68, 212)'); // Mounts default FramePay script
|
|
55
|
-
|
|
56
|
-
const SCRIPTS = [...document.querySelectorAll('head script')];
|
|
57
|
-
const FRAMEPAY_SCRIPT = SCRIPTS.find(script => script.src === framePayScriptUrl);
|
|
58
|
-
expect(FRAMEPAY_SCRIPT.src).toEqual(framePayScriptUrl); // Mounts _dev FramePay style
|
|
59
|
-
|
|
60
|
-
const STYLE_LINKS = [...document.querySelectorAll('head link')];
|
|
61
|
-
const FRAMEPAY_STYLE = STYLE_LINKS.find(script => script.href === framePayStyleUrl);
|
|
62
|
-
expect(FRAMEPAY_STYLE.href).toEqual(framePayStyleUrl);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _utils = require("../../utils");
|
|
9
|
-
|
|
10
|
-
var _default = ({
|
|
11
|
-
element = '',
|
|
12
|
-
options = {}
|
|
13
|
-
}) => {
|
|
14
|
-
if (element !== 'form' && element !== 'summary') {
|
|
15
|
-
throw new Error('element must be "form" or "summary"');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const getProp = () => {
|
|
19
|
-
if (options[element]) {
|
|
20
|
-
return options[element];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
switch (element) {
|
|
24
|
-
case 'summary':
|
|
25
|
-
return '.rebilly-instruments-summary';
|
|
26
|
-
|
|
27
|
-
case 'form':
|
|
28
|
-
default:
|
|
29
|
-
return '.rebilly-instruments';
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
return (0, _utils.processPropertyAsDOMElement)({
|
|
34
|
-
prop: getProp(),
|
|
35
|
-
propName: element,
|
|
36
|
-
isRequired: ['form'].includes(element)
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
exports.default = _default;
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _css = _interopRequireDefault(require("css"));
|
|
9
|
-
|
|
10
|
-
var _postcss = _interopRequireDefault(require("postcss"));
|
|
11
|
-
|
|
12
|
-
var _postcssCustomProperties = _interopRequireDefault(require("postcss-custom-properties"));
|
|
13
|
-
|
|
14
|
-
var _lodash = _interopRequireDefault(require("lodash.camelcase"));
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
const resolveCssVars = async rawCss => (0, _postcss.default)([(0, _postcssCustomProperties.default)({
|
|
19
|
-
preserve: false
|
|
20
|
-
})]).process(rawCss, {
|
|
21
|
-
from: undefined
|
|
22
|
-
}).then(output => output.css);
|
|
23
|
-
|
|
24
|
-
const getStyleProps = (ast, selector) => {
|
|
25
|
-
const {
|
|
26
|
-
rules
|
|
27
|
-
} = ast.stylesheet;
|
|
28
|
-
const output = {
|
|
29
|
-
color: null,
|
|
30
|
-
fontFamily: null,
|
|
31
|
-
fontSize: null,
|
|
32
|
-
lineHeight: null,
|
|
33
|
-
fontWeight: null,
|
|
34
|
-
background: null
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
for (let i = 0; i < rules.length; i += 1) {
|
|
38
|
-
const rule = rules[i];
|
|
39
|
-
|
|
40
|
-
if (rule.type === 'rule' && rule.selectors.includes(selector)) {
|
|
41
|
-
rule.declarations.forEach(decl => {
|
|
42
|
-
const propName = (0, _lodash.default)(decl.property);
|
|
43
|
-
|
|
44
|
-
if (typeof output[propName] !== 'undefined') {
|
|
45
|
-
output[propName] = decl.value;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return output;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
var _default = async ({
|
|
55
|
-
state,
|
|
56
|
-
options = {}
|
|
57
|
-
}) => {
|
|
58
|
-
const fullCss = `
|
|
59
|
-
${state.mainStyle}
|
|
60
|
-
${options.css || ''}
|
|
61
|
-
`;
|
|
62
|
-
const resolvedCss = await resolveCssVars(fullCss);
|
|
63
|
-
|
|
64
|
-
const cssAst = _css.default.parse(resolvedCss);
|
|
65
|
-
|
|
66
|
-
const cssSelectors = {
|
|
67
|
-
base: '.rebilly-instruments-form-field-input',
|
|
68
|
-
baseHover: '.rebilly-instruments-form-field-input:hover',
|
|
69
|
-
baseFocus: '.rebilly-instruments-form-field-input:focus',
|
|
70
|
-
basePlaceholder: '.rebilly-instruments-form-field-input::placeholder',
|
|
71
|
-
baseSelection: '.rebilly-instruments-form-field-input::selection',
|
|
72
|
-
invalid: '.rebilly-instruments-form-field.is-error .rebilly-instruments-form-field-input',
|
|
73
|
-
invalidHover: '.rebilly-instruments-form-field.is-error .rebilly-instruments-form-field-input:hover',
|
|
74
|
-
invalidFocus: '.rebilly-instruments-form-field.is-error .rebilly-instruments-form-field-input:focus',
|
|
75
|
-
invalidPlaceholder: '.rebilly-instruments-form-field.is-error .rebilly-instruments-form-field-input::placeholder',
|
|
76
|
-
invalidSelection: '.rebilly-instruments-form-field.is-error .rebilly-instruments-form-field-input::selection'
|
|
77
|
-
};
|
|
78
|
-
const framepayStyle = {
|
|
79
|
-
base: { ...getStyleProps(cssAst, cssSelectors.base),
|
|
80
|
-
':hover': getStyleProps(cssAst, cssSelectors.baseHover),
|
|
81
|
-
':focus': getStyleProps(cssAst, cssSelectors.baseFocus),
|
|
82
|
-
'::placeholder': getStyleProps(cssAst, cssSelectors.basePlaceholder),
|
|
83
|
-
'::selection': getStyleProps(cssAst, cssSelectors.baseSelection)
|
|
84
|
-
},
|
|
85
|
-
invalid: { ...getStyleProps(cssAst, cssSelectors.invalid),
|
|
86
|
-
':hover': getStyleProps(cssAst, cssSelectors.invalidHover),
|
|
87
|
-
':focus': getStyleProps(cssAst, cssSelectors.invalidFocus),
|
|
88
|
-
'::placeholder': getStyleProps(cssAst, cssSelectors.invalidPlaceholder),
|
|
89
|
-
'::selection': getStyleProps(cssAst, cssSelectors.invalidSelection)
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
return framepayStyle;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
exports.default = _default;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _utils = require("../../utils");
|
|
9
|
-
|
|
10
|
-
var _default = ({
|
|
11
|
-
state: {
|
|
12
|
-
options: {
|
|
13
|
-
_dev
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
} = {}) => {
|
|
17
|
-
const framePayUrls = {
|
|
18
|
-
script: _dev ? _dev.framePayScriptLink || 'https://framepay.rebilly.com/rebilly.js' : 'https://framepay.rebilly.com/rebilly.js',
|
|
19
|
-
style: _dev ? _dev.framePayStyleLink || 'https://framepay.rebilly.com/rebilly.css' : 'https://framepay.rebilly.com/rebilly.css'
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
if (!document.querySelectorAll('[framepay*="script"]').length) {
|
|
23
|
-
(0, _utils.addDOMElement)({
|
|
24
|
-
element: 'script',
|
|
25
|
-
attributes: {
|
|
26
|
-
framepay: 'script',
|
|
27
|
-
src: framePayUrls.script
|
|
28
|
-
},
|
|
29
|
-
target: 'head'
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (!document.querySelectorAll('[framepay*="stylesheet"]').length) {
|
|
34
|
-
(0, _utils.addDOMElement)({
|
|
35
|
-
element: 'link',
|
|
36
|
-
attributes: {
|
|
37
|
-
framepay: 'stylesheet',
|
|
38
|
-
href: framePayUrls.style,
|
|
39
|
-
rel: 'stylesheet'
|
|
40
|
-
},
|
|
41
|
-
target: 'head'
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
exports.default = _default;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
const triggerTranslations = ({
|
|
9
|
-
state
|
|
10
|
-
}) => {
|
|
11
|
-
state.translate.init(state.options.locale, state.options.i18n);
|
|
12
|
-
state.translate.translateItems();
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
var _default = ({
|
|
16
|
-
state = {}
|
|
17
|
-
}) => {
|
|
18
|
-
var _state$data$riskMetad, _state$data$riskMetad2;
|
|
19
|
-
|
|
20
|
-
if (state.options.locale === 'auto' && (_state$data$riskMetad = state.data.riskMetadata) !== null && _state$data$riskMetad !== void 0 && (_state$data$riskMetad2 = _state$data$riskMetad.browserData) !== null && _state$data$riskMetad2 !== void 0 && _state$data$riskMetad2.language) {
|
|
21
|
-
const {
|
|
22
|
-
browserData: {
|
|
23
|
-
language
|
|
24
|
-
}
|
|
25
|
-
} = state.data.riskMetadata;
|
|
26
|
-
state.options.locale = language;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
state.translate.init(state.options.locale, state.options.i18n);
|
|
30
|
-
return triggerTranslations;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
exports.default = _default;
|