@rebilly/instruments 3.0.0-beta.0 → 3.1.2-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/i18n/index.js +1 -1
- 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/base/__snapshots__/theme.spec.js.snap +34 -2
- package/src/style/base/default-theme.js +106 -3
- package/src/style/components/button.js +17 -1
- package/src/style/components/forms/label.js +0 -5
- 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 -195
- package/dist/style/base/default-theme.js +0 -699
- 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 -71
- 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 -69
- 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,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = mountApplePay;
|
|
7
|
-
|
|
8
|
-
var _events = _interopRequireDefault(require("../../../events"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
const browserIsSafari = () => window.ApplePaySession;
|
|
13
|
-
|
|
14
|
-
function mountApplePay({
|
|
15
|
-
state,
|
|
16
|
-
METHOD_ID,
|
|
17
|
-
METHOD_TYPE,
|
|
18
|
-
EXPRESS_METHODS,
|
|
19
|
-
EXPRESS_METHODS_CONTAINER
|
|
20
|
-
}) {
|
|
21
|
-
const container = document.querySelector(`.rebilly-instruments-${METHOD_ID}-method`);
|
|
22
|
-
const digitalWallet = state.options.digitalWallet.applePay;
|
|
23
|
-
|
|
24
|
-
function mountApplePayButton() {
|
|
25
|
-
if (!container.children.length) {
|
|
26
|
-
Rebilly.applePay.mount(`.rebilly-instruments-${METHOD_ID}-method`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
state.loader.stopLoading({
|
|
30
|
-
id: `${METHOD_TYPE}-express`
|
|
31
|
-
});
|
|
32
|
-
} // Hack: The correct way to do this is to accept the options via the framepay package
|
|
33
|
-
// Will remove once these options are added to framepay
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
function updateBtnStyling() {
|
|
37
|
-
const applePayButton = document.querySelector('#rebilly-apple-pay-button');
|
|
38
|
-
applePayButton.style.margin = '0px';
|
|
39
|
-
applePayButton.style.width = '100%';
|
|
40
|
-
applePayButton.style.height = digitalWallet.applePayDisplayOptions.buttonHeight;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (!browserIsSafari()) {
|
|
44
|
-
if (EXPRESS_METHODS.length === 1) {
|
|
45
|
-
EXPRESS_METHODS_CONTAINER.parentNode.style.display = 'none';
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
state.loader.stopLoading({
|
|
49
|
-
id: `${METHOD_TYPE}-express`
|
|
50
|
-
});
|
|
51
|
-
container.style.display = 'none';
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
container.style.height = digitalWallet.applePayDisplayOptions.buttonHeight;
|
|
56
|
-
|
|
57
|
-
if (!Rebilly.initialized) {
|
|
58
|
-
Rebilly.initialize({
|
|
59
|
-
publishableKey: state.options.publishableKey,
|
|
60
|
-
organizationId: state.options.organizationId,
|
|
61
|
-
digitalWallet
|
|
62
|
-
});
|
|
63
|
-
} else {
|
|
64
|
-
mountApplePayButton();
|
|
65
|
-
updateBtnStyling();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
Rebilly.on('ready', () => {
|
|
69
|
-
mountApplePayButton();
|
|
70
|
-
updateBtnStyling();
|
|
71
|
-
});
|
|
72
|
-
Rebilly.on('token-ready', token => {
|
|
73
|
-
const instrumentReadyPayload = {
|
|
74
|
-
websiteId: state.options.websiteId,
|
|
75
|
-
items: state.options.items,
|
|
76
|
-
paymentInstruction: {
|
|
77
|
-
token: token.id
|
|
78
|
-
},
|
|
79
|
-
billingAddress: token.billingAddress,
|
|
80
|
-
_raw: token
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
if (!token.shippingAddress) {
|
|
84
|
-
instrumentReadyPayload.deliveryAddress = token.shippingAddress;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
_events.default.instrumentReady.dispatch(instrumentReadyPayload);
|
|
88
|
-
});
|
|
89
|
-
Rebilly.on('error', error => {
|
|
90
|
-
console.error(error);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getMethodData = void 0;
|
|
7
|
-
|
|
8
|
-
var _lodash = _interopRequireDefault(require("lodash.kebabcase"));
|
|
9
|
-
|
|
10
|
-
var _lodash2 = _interopRequireDefault(require("lodash.camelcase"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
const getMethodData = method => {
|
|
15
|
-
var _method$feature, _method$feature2;
|
|
16
|
-
|
|
17
|
-
const METHOD_ID = (0, _lodash.default)(((_method$feature = method.feature) === null || _method$feature === void 0 ? void 0 : _method$feature.name) || method.method);
|
|
18
|
-
const METHOD_TYPE = (0, _lodash2.default)(((_method$feature2 = method.feature) === null || _method$feature2 === void 0 ? void 0 : _method$feature2.name) || method.method).replace('-', '');
|
|
19
|
-
return {
|
|
20
|
-
METHOD_ID,
|
|
21
|
-
METHOD_TYPE
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
exports.getMethodData = getMethodData;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getPaymentMethods = getPaymentMethods;
|
|
7
|
-
|
|
8
|
-
var _getMethodData = require("./get-method-data");
|
|
9
|
-
|
|
10
|
-
/* eslint-disable no-unused-expressions, arrow-body-style */
|
|
11
|
-
const SUPPORTED_EXPRESS_METHODS = ['Google Pay', 'Apple Pay', 'paypal'];
|
|
12
|
-
const SUPPORTED_METHODS = ['payment-card'];
|
|
13
|
-
|
|
14
|
-
const isExpressMethod = ({
|
|
15
|
-
method,
|
|
16
|
-
feature
|
|
17
|
-
}) => {
|
|
18
|
-
return SUPPORTED_EXPRESS_METHODS.includes(method) || SUPPORTED_EXPRESS_METHODS.includes(feature === null || feature === void 0 ? void 0 : feature.name);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const isSupportedMethod = ({
|
|
22
|
-
method
|
|
23
|
-
}) => {
|
|
24
|
-
return SUPPORTED_METHODS.includes(method);
|
|
25
|
-
}; // TODO: just loader is used. We could simplify signature
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
function getPaymentMethods({
|
|
29
|
-
state
|
|
30
|
-
}) {
|
|
31
|
-
const result = {
|
|
32
|
-
EXPRESS_METHODS: [],
|
|
33
|
-
METHODS: []
|
|
34
|
-
};
|
|
35
|
-
state.data.readyToPay.forEach(method => {
|
|
36
|
-
if (isExpressMethod(method)) {
|
|
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`
|
|
43
|
-
});
|
|
44
|
-
result.EXPRESS_METHODS.push(method);
|
|
45
|
-
} else if (isSupportedMethod(method)) {
|
|
46
|
-
// Add loader entry per method
|
|
47
|
-
state.loader.startLoading({
|
|
48
|
-
id: method.method
|
|
49
|
-
});
|
|
50
|
-
result.METHODS.push(method);
|
|
51
|
-
}
|
|
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
|
-
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _getPaymentMethods = require("./get-payment-methods");
|
|
4
|
-
|
|
5
|
-
var _readyToPayModel = _interopRequireDefault(require("../../storefront/models/ready-to-pay-model"));
|
|
6
|
-
|
|
7
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
-
|
|
9
|
-
class TestInstance {
|
|
10
|
-
constructor() {
|
|
11
|
-
this.loader = {
|
|
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
|
-
})]
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
it('should only return the allowed methods', () => {
|
|
39
|
-
const instance = new TestInstance();
|
|
40
|
-
const results = (0, _getPaymentMethods.getPaymentMethods)({
|
|
41
|
-
state: instance
|
|
42
|
-
});
|
|
43
|
-
expect(results.hasOwnProperty('EXPRESS_METHODS')).toEqual(true);
|
|
44
|
-
expect(results['EXPRESS_METHODS'].length).toEqual(1);
|
|
45
|
-
expect(results['METHODS'].length).toEqual(1);
|
|
46
|
-
});
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.mountMethodSelector = mountMethodSelector;
|
|
7
|
-
exports.updateMethodSelector = updateMethodSelector;
|
|
8
|
-
exports.baseMethodSelectorHTML = void 0;
|
|
9
|
-
|
|
10
|
-
var _riskDataCollector = require("@rebilly/risk-data-collector");
|
|
11
|
-
|
|
12
|
-
var _getPaymentMethods = require("./get-payment-methods");
|
|
13
|
-
|
|
14
|
-
var _mountExpressMethods = require("./mount-express-methods");
|
|
15
|
-
|
|
16
|
-
var _generateDigitalWallet = require("./generate-digital-wallet");
|
|
17
|
-
|
|
18
|
-
var _mountMethods = require("./mount-methods");
|
|
19
|
-
|
|
20
|
-
var _fetchData = require("../../functions/mount/fetch-data");
|
|
21
|
-
|
|
22
|
-
/* eslint-disable no-undef */
|
|
23
|
-
const baseMethodSelectorHTML = compactExpressInstruments => `
|
|
24
|
-
<div class="rebilly-instruments-content">
|
|
25
|
-
<div class="rebilly-instruments-method-selector ${compactExpressInstruments ? 'has-express-compact' : ''}">
|
|
26
|
-
<div class="rebilly-instruments-express-methods ${compactExpressInstruments ? 'is-compact' : ''}">
|
|
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>
|
|
29
|
-
</div>
|
|
30
|
-
<div class="rebilly-instruments-divider">
|
|
31
|
-
<span class="rebilly-instruments-divider-label" data-rebilly-i18n="form.or">Or</span>
|
|
32
|
-
</div>
|
|
33
|
-
<div class="rebilly-instruments-methods"></div>
|
|
34
|
-
</div>
|
|
35
|
-
</div>
|
|
36
|
-
`;
|
|
37
|
-
|
|
38
|
-
exports.baseMethodSelectorHTML = baseMethodSelectorHTML;
|
|
39
|
-
|
|
40
|
-
function mountMethodSelector({
|
|
41
|
-
state
|
|
42
|
-
}) {
|
|
43
|
-
const {
|
|
44
|
-
EXPRESS_METHODS,
|
|
45
|
-
METHODS
|
|
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');
|
|
51
|
-
const METHODS_DIVIDER = document.querySelector('.rebilly-instruments-divider');
|
|
52
|
-
METHODS_DIVIDER.style.display = METHODS.length && EXPRESS_METHODS.length ? 'block' : 'none';
|
|
53
|
-
const METHODS_CONTAINER = document.querySelector('.rebilly-instruments-methods');
|
|
54
|
-
state.options.digitalWallet = (0, _generateDigitalWallet.generateDigitalWallet)({
|
|
55
|
-
state,
|
|
56
|
-
EXPRESS_METHODS
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
if (METHODS.length) {
|
|
60
|
-
(0, _mountMethods.MountMethods)({
|
|
61
|
-
state,
|
|
62
|
-
METHODS_CONTAINER,
|
|
63
|
-
METHODS
|
|
64
|
-
});
|
|
65
|
-
} else {
|
|
66
|
-
METHODS_CONTAINER.style.display = 'none';
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (EXPRESS_METHODS.length) {
|
|
70
|
-
(0, _mountExpressMethods.mountExpressMethods)({
|
|
71
|
-
state,
|
|
72
|
-
EXPRESS_METHODS,
|
|
73
|
-
EXPRESS_METHODS_CONTAINER
|
|
74
|
-
});
|
|
75
|
-
} else {
|
|
76
|
-
EXPRESS_METHODS_CONTAINER.parentNode.style.display = 'none';
|
|
77
|
-
}
|
|
78
|
-
|
|
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({
|
|
90
|
-
id: 'initForm'
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async function updateMethodSelector({
|
|
95
|
-
state
|
|
96
|
-
}) {
|
|
97
|
-
var _state$data$transacti;
|
|
98
|
-
|
|
99
|
-
state.loader.startLoading({
|
|
100
|
-
id: 'initForm'
|
|
101
|
-
});
|
|
102
|
-
const {
|
|
103
|
-
riskMetadata
|
|
104
|
-
} = await (0, _riskDataCollector.collectData)();
|
|
105
|
-
state.data = await (0, _fetchData.fetchData)({
|
|
106
|
-
state,
|
|
107
|
-
riskMetadata
|
|
108
|
-
});
|
|
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 => {
|
|
115
|
-
if (!element.classList.contains('rebilly-instruments-loader') && !element.classList.contains('rebilly-instruments-loader-spinner')) {
|
|
116
|
-
element.remove();
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
mountMethodSelector({
|
|
120
|
-
state
|
|
121
|
-
});
|
|
122
|
-
}
|