@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,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = mountGooglePay;
|
|
7
|
+
|
|
8
|
+
var _iframe = require("../../common/iframe");
|
|
9
|
+
|
|
10
|
+
async function mountGooglePay({
|
|
11
|
+
state,
|
|
12
|
+
METHOD_ID
|
|
13
|
+
}) {
|
|
14
|
+
const container = document.querySelector(`.rebilly-instruments-${METHOD_ID}-method`);
|
|
15
|
+
const {
|
|
16
|
+
paymentMethodsUrl
|
|
17
|
+
} = state.options._computed;
|
|
18
|
+
const model = {
|
|
19
|
+
options: state.options
|
|
20
|
+
};
|
|
21
|
+
const iframe = await new _iframe.MethodIframe({
|
|
22
|
+
name: METHOD_ID,
|
|
23
|
+
url: `${paymentMethodsUrl}/${METHOD_ID}`,
|
|
24
|
+
container,
|
|
25
|
+
model
|
|
26
|
+
});
|
|
27
|
+
iframe.bindEventListeners({
|
|
28
|
+
loader: state.loader
|
|
29
|
+
});
|
|
30
|
+
state.iframeComponents.push(iframe);
|
|
31
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = mountPaypal;
|
|
7
|
+
|
|
8
|
+
async function mountPaypal({
|
|
9
|
+
state,
|
|
10
|
+
METHOD_ID,
|
|
11
|
+
METHOD_TYPE
|
|
12
|
+
}) {
|
|
13
|
+
console.log('PayPal - work in progress');
|
|
14
|
+
const container = document.querySelector(`.rebilly-instruments-${METHOD_ID}-method`);
|
|
15
|
+
container.style.display = 'none';
|
|
16
|
+
state.loader.stopLoading({
|
|
17
|
+
id: `${METHOD_TYPE}-express`
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.generateDigitalWallet = generateDigitalWallet;
|
|
7
|
+
|
|
8
|
+
var _getMethodData = require("./get-method-data");
|
|
9
|
+
|
|
10
|
+
function generateDigitalWallet({
|
|
11
|
+
state,
|
|
12
|
+
EXPRESS_METHODS
|
|
13
|
+
}) {
|
|
14
|
+
var _state$data;
|
|
15
|
+
|
|
16
|
+
const output = {};
|
|
17
|
+
const {
|
|
18
|
+
paymentInstruments
|
|
19
|
+
} = state.options;
|
|
20
|
+
const transactionData = {
|
|
21
|
+
countryCode: state.options.countryCode,
|
|
22
|
+
label: state.options.websiteId
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
if ((_state$data = state.data) !== null && _state$data !== void 0 && _state$data.amountAndCurrency) {
|
|
26
|
+
const {
|
|
27
|
+
amount,
|
|
28
|
+
currency
|
|
29
|
+
} = state.data.amountAndCurrency;
|
|
30
|
+
transactionData.amount = amount;
|
|
31
|
+
transactionData.currency = currency;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
EXPRESS_METHODS.forEach(method => {
|
|
35
|
+
var _method$feature, _method$feature2;
|
|
36
|
+
|
|
37
|
+
const {
|
|
38
|
+
METHOD_TYPE
|
|
39
|
+
} = (0, _getMethodData.getMethodData)(method);
|
|
40
|
+
|
|
41
|
+
if (((_method$feature = method.feature) === null || _method$feature === void 0 ? void 0 : _method$feature.name) === 'Google Pay') {
|
|
42
|
+
output[METHOD_TYPE] = {
|
|
43
|
+
transactionData,
|
|
44
|
+
merchantConfig: {
|
|
45
|
+
merchantName: method.feature.merchantName,
|
|
46
|
+
merchantOrigin: method.feature.merchantOrigin
|
|
47
|
+
},
|
|
48
|
+
googlePayDisplayOptions: paymentInstruments.googlePay.displayOptions
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (((_method$feature2 = method.feature) === null || _method$feature2 === void 0 ? void 0 : _method$feature2.name) === 'Apple Pay') {
|
|
53
|
+
var _paymentInstruments$a, _paymentInstruments$a2;
|
|
54
|
+
|
|
55
|
+
output[METHOD_TYPE] = {
|
|
56
|
+
transactionData,
|
|
57
|
+
merchantConfig: {
|
|
58
|
+
merchantName: (_paymentInstruments$a = paymentInstruments.applePay) === null || _paymentInstruments$a === void 0 ? void 0 : (_paymentInstruments$a2 = _paymentInstruments$a.merchantConfig) === null || _paymentInstruments$a2 === void 0 ? void 0 : _paymentInstruments$a2.merchantName,
|
|
59
|
+
// Apple Pay code cannot run in an iframe, and the merchant origin must be
|
|
60
|
+
// registered as a merchant domain, so we can just send the current URL.
|
|
61
|
+
merchantOrigin: window.location.hostname
|
|
62
|
+
},
|
|
63
|
+
applePayDisplayOptions: paymentInstruments.applePay.displayOptions
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return output;
|
|
68
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _generateDigitalWallet = require("./generate-digital-wallet");
|
|
4
|
+
|
|
5
|
+
var _readyToPayModel = _interopRequireDefault(require("../../storefront/models/ready-to-pay-model"));
|
|
6
|
+
|
|
7
|
+
var _summaryModel = _interopRequireDefault(require("../../storefront/models/summary-model"));
|
|
8
|
+
|
|
9
|
+
var _fetchData = require("../../functions/mount/fetch-data");
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
|
|
13
|
+
describe('generateDigitalWallet', () => {
|
|
14
|
+
class TestInstance {
|
|
15
|
+
constructor({
|
|
16
|
+
options = {}
|
|
17
|
+
} = {}) {
|
|
18
|
+
this.options = options;
|
|
19
|
+
this.data = new _fetchData.DataInstance({
|
|
20
|
+
state: {
|
|
21
|
+
options
|
|
22
|
+
},
|
|
23
|
+
previewPurchase: {
|
|
24
|
+
total: 1,
|
|
25
|
+
currency: 'USD'
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const summary = new _summaryModel.default({
|
|
33
|
+
currency: 'USD',
|
|
34
|
+
total: 1
|
|
35
|
+
});
|
|
36
|
+
const options = {
|
|
37
|
+
websiteId: 'test-website-id',
|
|
38
|
+
countryCode: 'US',
|
|
39
|
+
paymentInstruments: {
|
|
40
|
+
googlePay: {
|
|
41
|
+
displayOptions: {
|
|
42
|
+
buttonColor: 'black',
|
|
43
|
+
buttonType: 'short',
|
|
44
|
+
buttonHeight: '44px'
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
applePay: {
|
|
48
|
+
displayOptions: {
|
|
49
|
+
buttonColor: 'black',
|
|
50
|
+
buttonType: 'buy',
|
|
51
|
+
buttonHeight: '44px'
|
|
52
|
+
},
|
|
53
|
+
merchantConfig: {
|
|
54
|
+
merchantName: 'Test Store Name'
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
it('should generate the correct digital wallet config for Google pay', () => {
|
|
60
|
+
const expressMethods = [new _readyToPayModel.default({
|
|
61
|
+
method: 'payment-card',
|
|
62
|
+
feature: {
|
|
63
|
+
name: 'Google Pay',
|
|
64
|
+
merchantName: 'google-pay-merchant-name',
|
|
65
|
+
merchantOrigin: 'google-pay-merchant-origin'
|
|
66
|
+
},
|
|
67
|
+
brands: ['Visa']
|
|
68
|
+
})];
|
|
69
|
+
const output = (0, _generateDigitalWallet.generateDigitalWallet)({
|
|
70
|
+
state: new TestInstance({
|
|
71
|
+
options
|
|
72
|
+
}),
|
|
73
|
+
EXPRESS_METHODS: expressMethods,
|
|
74
|
+
summary
|
|
75
|
+
});
|
|
76
|
+
const expectedOutput = {
|
|
77
|
+
googlePay: {
|
|
78
|
+
transactionData: {
|
|
79
|
+
amount: 1,
|
|
80
|
+
currency: 'USD',
|
|
81
|
+
countryCode: 'US',
|
|
82
|
+
label: 'test-website-id'
|
|
83
|
+
},
|
|
84
|
+
merchantConfig: {
|
|
85
|
+
merchantName: 'google-pay-merchant-name',
|
|
86
|
+
merchantOrigin: 'google-pay-merchant-origin'
|
|
87
|
+
},
|
|
88
|
+
googlePayDisplayOptions: {
|
|
89
|
+
buttonColor: 'black',
|
|
90
|
+
buttonType: 'short',
|
|
91
|
+
buttonHeight: '44px'
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
expect(output).toMatchObject(expectedOutput);
|
|
96
|
+
});
|
|
97
|
+
it('should generate the correct digital wallet config for Apple pay', () => {
|
|
98
|
+
delete window.location;
|
|
99
|
+
window.location = new URL('https://rebilly-apple-pay-test-tunnel.ngrok.io/');
|
|
100
|
+
const expressMethods = [new _readyToPayModel.default({
|
|
101
|
+
method: 'payment-card',
|
|
102
|
+
feature: {
|
|
103
|
+
name: 'Apple Pay'
|
|
104
|
+
},
|
|
105
|
+
brands: ['Visa']
|
|
106
|
+
})];
|
|
107
|
+
const output = (0, _generateDigitalWallet.generateDigitalWallet)({
|
|
108
|
+
state: new TestInstance({
|
|
109
|
+
options
|
|
110
|
+
}),
|
|
111
|
+
EXPRESS_METHODS: expressMethods,
|
|
112
|
+
summary
|
|
113
|
+
});
|
|
114
|
+
const expectedOutput = {
|
|
115
|
+
applePay: {
|
|
116
|
+
transactionData: {
|
|
117
|
+
amount: 1,
|
|
118
|
+
currency: 'USD',
|
|
119
|
+
countryCode: 'US',
|
|
120
|
+
label: 'test-website-id'
|
|
121
|
+
},
|
|
122
|
+
merchantConfig: {
|
|
123
|
+
merchantName: 'Test Store Name',
|
|
124
|
+
merchantOrigin: 'rebilly-apple-pay-test-tunnel.ngrok.io'
|
|
125
|
+
},
|
|
126
|
+
applePayDisplayOptions: {
|
|
127
|
+
buttonColor: 'black',
|
|
128
|
+
buttonType: 'buy',
|
|
129
|
+
buttonHeight: '44px'
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
expect(output).toMatchObject(expectedOutput);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -5,8 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getPaymentMethods = getPaymentMethods;
|
|
7
7
|
|
|
8
|
+
var _getMethodData = require("./get-method-data");
|
|
9
|
+
|
|
8
10
|
/* eslint-disable no-unused-expressions, arrow-body-style */
|
|
9
|
-
const SUPPORTED_EXPRESS_METHODS = ['Google Pay'];
|
|
11
|
+
const SUPPORTED_EXPRESS_METHODS = ['Google Pay', 'Apple Pay', 'paypal'];
|
|
10
12
|
const SUPPORTED_METHODS = ['payment-card'];
|
|
11
13
|
|
|
12
14
|
const isExpressMethod = ({
|
|
@@ -20,27 +22,45 @@ const isSupportedMethod = ({
|
|
|
20
22
|
method
|
|
21
23
|
}) => {
|
|
22
24
|
return SUPPORTED_METHODS.includes(method);
|
|
23
|
-
};
|
|
25
|
+
}; // TODO: just loader is used. We could simplify signature
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
|
|
28
|
+
function getPaymentMethods({
|
|
29
|
+
state
|
|
30
|
+
}) {
|
|
26
31
|
const result = {
|
|
27
32
|
EXPRESS_METHODS: [],
|
|
28
33
|
METHODS: []
|
|
29
34
|
};
|
|
30
|
-
|
|
35
|
+
state.data.readyToPay.forEach(method => {
|
|
31
36
|
if (isExpressMethod(method)) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
const {
|
|
38
|
+
METHOD_TYPE
|
|
39
|
+
} = (0, _getMethodData.getMethodData)(method); // Add loader entry per express method
|
|
40
|
+
|
|
41
|
+
state.loader.startLoading({
|
|
42
|
+
id: `${METHOD_TYPE}-express`
|
|
35
43
|
});
|
|
36
44
|
result.EXPRESS_METHODS.push(method);
|
|
37
45
|
} else if (isSupportedMethod(method)) {
|
|
38
46
|
// Add loader entry per method
|
|
39
|
-
|
|
47
|
+
state.loader.startLoading({
|
|
40
48
|
id: method.method
|
|
41
49
|
});
|
|
42
50
|
result.METHODS.push(method);
|
|
43
51
|
}
|
|
44
52
|
});
|
|
53
|
+
|
|
54
|
+
if (!window.ApplePaySession) {
|
|
55
|
+
result.EXPRESS_METHODS = result.EXPRESS_METHODS.filter(method => {
|
|
56
|
+
var _method$feature;
|
|
57
|
+
|
|
58
|
+
return (method === null || method === void 0 ? void 0 : (_method$feature = method.feature) === null || _method$feature === void 0 ? void 0 : _method$feature.name) !== 'Apple Pay';
|
|
59
|
+
});
|
|
60
|
+
state.loader.stopLoading({
|
|
61
|
+
id: 'applePay-express'
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
45
65
|
return result;
|
|
46
66
|
}
|
|
@@ -2,45 +2,44 @@
|
|
|
2
2
|
|
|
3
3
|
var _getPaymentMethods = require("./get-payment-methods");
|
|
4
4
|
|
|
5
|
-
var _readyToPayModel = _interopRequireDefault(require("
|
|
5
|
+
var _readyToPayModel = _interopRequireDefault(require("../../storefront/models/ready-to-pay-model"));
|
|
6
6
|
|
|
7
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
8
|
|
|
9
9
|
class TestInstance {
|
|
10
10
|
constructor() {
|
|
11
11
|
this.loader = {
|
|
12
|
-
startLoading: jest.fn()
|
|
12
|
+
startLoading: jest.fn(),
|
|
13
|
+
stopLoading: jest.fn()
|
|
14
|
+
};
|
|
15
|
+
this.data = {
|
|
16
|
+
readyToPay: [new _readyToPayModel.default({
|
|
17
|
+
method: 'payment-card',
|
|
18
|
+
feature: {
|
|
19
|
+
name: 'Google Pay',
|
|
20
|
+
merchantName: 'google-pay-merchant-name',
|
|
21
|
+
merchantOrigin: 'google-pay-merchant-origin'
|
|
22
|
+
},
|
|
23
|
+
brands: ['Visa'],
|
|
24
|
+
filters: []
|
|
25
|
+
}), new _readyToPayModel.default({
|
|
26
|
+
method: 'bitcoin',
|
|
27
|
+
filters: []
|
|
28
|
+
}), new _readyToPayModel.default({
|
|
29
|
+
method: 'payment-card',
|
|
30
|
+
brands: ['Visa'],
|
|
31
|
+
filters: []
|
|
32
|
+
})]
|
|
13
33
|
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
_getPaymentMethods() {
|
|
17
|
-
return _getPaymentMethods.getPaymentMethods.apply(this, arguments);
|
|
18
34
|
}
|
|
19
35
|
|
|
20
36
|
}
|
|
21
37
|
|
|
22
38
|
it('should only return the allowed methods', () => {
|
|
23
39
|
const instance = new TestInstance();
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
name: 'Google Pay',
|
|
28
|
-
merchantName: 'google-pay-merchant-name',
|
|
29
|
-
merchantOrigin: 'google-pay-merchant-origin'
|
|
30
|
-
},
|
|
31
|
-
brands: ['Visa'],
|
|
32
|
-
filters: []
|
|
33
|
-
}), new _readyToPayModel.default({
|
|
34
|
-
method: 'bitcoin',
|
|
35
|
-
filters: []
|
|
36
|
-
}), new _readyToPayModel.default({
|
|
37
|
-
method: 'payment-card',
|
|
38
|
-
brands: ['Visa'],
|
|
39
|
-
filters: []
|
|
40
|
-
})];
|
|
41
|
-
|
|
42
|
-
const results = instance._getPaymentMethods(methods);
|
|
43
|
-
|
|
40
|
+
const results = (0, _getPaymentMethods.getPaymentMethods)({
|
|
41
|
+
state: instance
|
|
42
|
+
});
|
|
44
43
|
expect(results.hasOwnProperty('EXPRESS_METHODS')).toEqual(true);
|
|
45
44
|
expect(results['EXPRESS_METHODS'].length).toEqual(1);
|
|
46
45
|
expect(results['METHODS'].length).toEqual(1);
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
6
|
+
exports.mountMethodSelector = mountMethodSelector;
|
|
7
|
+
exports.updateMethodSelector = updateMethodSelector;
|
|
8
8
|
exports.baseMethodSelectorHTML = void 0;
|
|
9
9
|
|
|
10
10
|
var _riskDataCollector = require("@rebilly/risk-data-collector");
|
|
@@ -13,22 +13,19 @@ var _getPaymentMethods = require("./get-payment-methods");
|
|
|
13
13
|
|
|
14
14
|
var _mountExpressMethods = require("./mount-express-methods");
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _generateDigitalWallet = require("./generate-digital-wallet");
|
|
17
17
|
|
|
18
18
|
var _mountMethods = require("./mount-methods");
|
|
19
19
|
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
var _events = _interopRequireDefault(require("../../events"));
|
|
23
|
-
|
|
24
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
+
var _fetchData = require("../../functions/mount/fetch-data");
|
|
25
21
|
|
|
26
22
|
/* eslint-disable no-undef */
|
|
27
23
|
const baseMethodSelectorHTML = compactExpressInstruments => `
|
|
28
24
|
<div class="rebilly-instruments-content">
|
|
29
|
-
<div class="rebilly-instruments-method-selector">
|
|
25
|
+
<div class="rebilly-instruments-method-selector ${compactExpressInstruments ? 'has-express-compact' : ''}">
|
|
30
26
|
<div class="rebilly-instruments-express-methods ${compactExpressInstruments ? 'is-compact' : ''}">
|
|
31
27
|
<span data-rebilly-i18n="form.expressCheckout" class="rebilly-instruments-express-methods-label">Express checkout</span>
|
|
28
|
+
<div class="rebilly-instruments-express-methods-container"></div>
|
|
32
29
|
</div>
|
|
33
30
|
<div class="rebilly-instruments-divider">
|
|
34
31
|
<span class="rebilly-instruments-divider-label" data-rebilly-i18n="form.or">Or</span>
|
|
@@ -40,114 +37,86 @@ const baseMethodSelectorHTML = compactExpressInstruments => `
|
|
|
40
37
|
|
|
41
38
|
exports.baseMethodSelectorHTML = baseMethodSelectorHTML;
|
|
42
39
|
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
plans,
|
|
47
|
-
products,
|
|
48
|
-
mainStyle
|
|
49
|
-
} = {}) {
|
|
40
|
+
function mountMethodSelector({
|
|
41
|
+
state
|
|
42
|
+
}) {
|
|
50
43
|
const {
|
|
51
44
|
EXPRESS_METHODS,
|
|
52
45
|
METHODS
|
|
53
|
-
} = _getPaymentMethods.getPaymentMethods
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
46
|
+
} = (0, _getPaymentMethods.getPaymentMethods)({
|
|
47
|
+
state
|
|
48
|
+
});
|
|
49
|
+
state.form.innerHTML += baseMethodSelectorHTML(state.options.paymentInstruments.compactExpressInstruments && EXPRESS_METHODS.length);
|
|
50
|
+
const EXPRESS_METHODS_CONTAINER = document.querySelector('.rebilly-instruments-express-methods-container');
|
|
57
51
|
const METHODS_DIVIDER = document.querySelector('.rebilly-instruments-divider');
|
|
58
52
|
METHODS_DIVIDER.style.display = METHODS.length && EXPRESS_METHODS.length ? 'block' : 'none';
|
|
59
53
|
const METHODS_CONTAINER = document.querySelector('.rebilly-instruments-methods');
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
countryCode: this.options.intent.countryCode,
|
|
65
|
-
label: this.configs.websiteId
|
|
66
|
-
},
|
|
67
|
-
...(0, _processDigitalWalletOptions.processDigitalWalletOptions)(this.options, EXPRESS_METHODS)
|
|
68
|
-
};
|
|
69
|
-
this.configs = { ...this.configs,
|
|
70
|
-
digitalWallet
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
function initializeFramepay() {
|
|
74
|
-
if (Rebilly.initialized) {
|
|
75
|
-
_mountExpressMethods.mountExpressMethods.call(this, {
|
|
76
|
-
EXPRESS_METHODS,
|
|
77
|
-
EXPRESS_METHODS_CONTAINER
|
|
78
|
-
});
|
|
79
|
-
} else {
|
|
80
|
-
Rebilly.initialize({
|
|
81
|
-
publishableKey: this.configs.publishableKey,
|
|
82
|
-
organizationId: this.configs.organizationId,
|
|
83
|
-
digitalWallet
|
|
84
|
-
});
|
|
85
|
-
Rebilly.on('ready', () => {
|
|
86
|
-
_mountExpressMethods.mountExpressMethods.call(this, {
|
|
87
|
-
EXPRESS_METHODS,
|
|
88
|
-
EXPRESS_METHODS_CONTAINER
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
Rebilly.on('token-ready', data => {
|
|
92
|
-
_events.default.instrumentReady.dispatch(data);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
54
|
+
state.options.digitalWallet = (0, _generateDigitalWallet.generateDigitalWallet)({
|
|
55
|
+
state,
|
|
56
|
+
EXPRESS_METHODS
|
|
57
|
+
});
|
|
96
58
|
|
|
97
59
|
if (METHODS.length) {
|
|
98
|
-
_mountMethods.MountMethods
|
|
60
|
+
(0, _mountMethods.MountMethods)({
|
|
61
|
+
state,
|
|
99
62
|
METHODS_CONTAINER,
|
|
100
|
-
METHODS
|
|
101
|
-
mainStyle,
|
|
102
|
-
plans,
|
|
103
|
-
products
|
|
63
|
+
METHODS
|
|
104
64
|
});
|
|
105
65
|
} else {
|
|
106
66
|
METHODS_CONTAINER.style.display = 'none';
|
|
107
67
|
}
|
|
108
68
|
|
|
109
|
-
if (
|
|
110
|
-
|
|
69
|
+
if (EXPRESS_METHODS.length) {
|
|
70
|
+
(0, _mountExpressMethods.mountExpressMethods)({
|
|
71
|
+
state,
|
|
72
|
+
EXPRESS_METHODS,
|
|
73
|
+
EXPRESS_METHODS_CONTAINER
|
|
74
|
+
});
|
|
111
75
|
} else {
|
|
112
|
-
EXPRESS_METHODS_CONTAINER.style.display = 'none';
|
|
76
|
+
EXPRESS_METHODS_CONTAINER.parentNode.style.display = 'none';
|
|
113
77
|
}
|
|
114
78
|
|
|
115
|
-
|
|
116
|
-
|
|
79
|
+
if (!METHODS.length && !EXPRESS_METHODS.length) {
|
|
80
|
+
state.form.innerHTML = `
|
|
81
|
+
<p data-rebilly-i18n="form.error.noPaymentMethods">
|
|
82
|
+
No payment methods available for this transaction, please contact support.
|
|
83
|
+
<p>
|
|
84
|
+
`;
|
|
85
|
+
state.form.style.minHeight = 'auto';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
state.translate.translateItems();
|
|
89
|
+
state.loader.stopLoading({
|
|
117
90
|
id: 'initForm'
|
|
118
91
|
});
|
|
119
92
|
}
|
|
120
93
|
|
|
121
|
-
|
|
94
|
+
async function updateMethodSelector({
|
|
95
|
+
state
|
|
96
|
+
}) {
|
|
97
|
+
var _state$data$transacti;
|
|
122
98
|
|
|
123
|
-
|
|
124
|
-
mainStyle
|
|
125
|
-
} = {}) {
|
|
126
|
-
this.loader.startLoading({
|
|
99
|
+
state.loader.startLoading({
|
|
127
100
|
id: 'initForm'
|
|
128
101
|
});
|
|
129
102
|
const {
|
|
130
103
|
riskMetadata
|
|
131
104
|
} = await (0, _riskDataCollector.collectData)();
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
summary: summaryData,
|
|
135
|
-
plans,
|
|
136
|
-
products
|
|
137
|
-
} = await _fetchSummaryData.FetchSummaryData.call(this, {
|
|
105
|
+
state.data = await (0, _fetchData.fetchData)({
|
|
106
|
+
state,
|
|
138
107
|
riskMetadata
|
|
139
108
|
});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
};
|
|
147
|
-
this.form.querySelectorAll(':not(.rebilly-instruments-confirmation)').forEach(element => {
|
|
109
|
+
|
|
110
|
+
if (state.data.transaction && ((_state$data$transacti = state.data.transaction) === null || _state$data$transacti === void 0 ? void 0 : _state$data$transacti.type) === 'setup') {
|
|
111
|
+
state.options.transactionType = 'setup';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
state.form.querySelectorAll(':not(.rebilly-instruments-confirmation)').forEach(element => {
|
|
148
115
|
if (!element.classList.contains('rebilly-instruments-loader') && !element.classList.contains('rebilly-instruments-loader-spinner')) {
|
|
149
116
|
element.remove();
|
|
150
117
|
}
|
|
151
118
|
});
|
|
152
|
-
|
|
119
|
+
mountMethodSelector({
|
|
120
|
+
state
|
|
121
|
+
});
|
|
153
122
|
}
|