@rebilly/instruments 1.0.1-beta → 1.0.2-beta.10
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 +23 -5
- package/.eslintrc.js +27 -0
- package/.prettierrc.js +11 -0
- package/CONTRIBUTING.md +4 -0
- package/README.md +361 -2
- package/dist/events/base-event.js +51 -37
- package/dist/events/events.spec.js +18 -0
- package/dist/events/index.js +11 -8
- package/dist/functions/destroy.js +27 -5
- package/dist/functions/destroy.spec.js +69 -0
- package/dist/functions/initialize.js +60 -41
- package/dist/functions/initialize.spec.js +13 -13
- package/dist/functions/mount/fetch-summary-data.js +46 -0
- package/dist/functions/mount/fetch-summary-data.spec.js +44 -0
- package/dist/functions/mount/index.js +346 -0
- package/dist/functions/mount/mount.spec.js +135 -0
- package/dist/functions/on.js +26 -18
- package/dist/functions/on.spec.js +45 -63
- package/dist/functions/purchase.js +41 -154
- package/dist/functions/purchase.spec.js +60 -76
- package/dist/functions/show.js +39 -43
- package/dist/functions/show.spec.js +57 -0
- package/dist/functions/update.js +60 -5
- package/dist/functions/update.spec.js +100 -0
- package/dist/i18n/en.json +19 -0
- package/dist/i18n/es.json +19 -0
- package/dist/i18n/i18n.spec.js +6 -23
- package/dist/i18n/index.js +44 -67
- package/dist/index.js +70 -71
- package/dist/index.spec.js +24 -44
- package/dist/loader/index.js +63 -62
- package/dist/loader/loader.spec.js +14 -11
- package/dist/storefront/index.js +28 -39
- package/dist/storefront/models/plan-model.js +37 -54
- package/dist/storefront/models/product-model.js +25 -36
- package/dist/storefront/models/ready-to-pay-model.js +38 -42
- package/dist/storefront/models/summary-model.js +72 -99
- package/dist/storefront/plans.js +37 -84
- package/dist/storefront/plans.spec.js +61 -151
- package/dist/storefront/products.js +35 -83
- package/dist/storefront/products.spec.js +60 -150
- package/dist/storefront/purchase.js +27 -64
- package/dist/storefront/purchase.spec.js +51 -87
- package/dist/storefront/ready-to-pay.js +45 -107
- package/dist/storefront/ready-to-pay.spec.js +72 -147
- package/dist/storefront/storefront.spec.js +6 -6
- package/dist/storefront/summary.js +37 -84
- package/dist/storefront/summary.spec.js +135 -240
- package/dist/style/base/__snapshots__/theme.spec.js.snap +52 -0
- package/dist/style/base/index.js +72 -0
- package/dist/style/base/theme.js +73 -0
- package/dist/style/base/theme.spec.js +30 -0
- package/dist/style/browserslist.js +8 -0
- package/dist/style/components/address.js +64 -0
- package/dist/style/components/button.js +61 -0
- package/dist/style/components/divider.js +48 -0
- package/dist/style/components/forms/checkbox.js +83 -0
- package/dist/style/components/forms/field.js +53 -0
- package/dist/style/components/forms/form.js +28 -0
- package/dist/style/components/forms/input.js +45 -0
- package/dist/style/components/forms/label.js +43 -0
- package/dist/style/components/forms/select.js +63 -0
- package/dist/style/components/forms/validation.js +34 -0
- package/dist/style/components/icons.js +22 -0
- package/dist/style/components/index.js +57 -0
- package/dist/style/components/loader.js +48 -0
- package/dist/style/components/methods.js +104 -0
- package/dist/style/components/overlay.js +33 -0
- package/dist/style/helpers/index.js +59 -0
- package/dist/style/index.js +48 -0
- package/dist/style/payment-instruments/content.js +17 -0
- package/dist/style/payment-instruments/index.js +20 -0
- package/dist/style/payment-instruments/payment-card.js +35 -0
- package/dist/style/utils/color-values.js +22 -0
- package/dist/style/vendor/framepay.js +34 -0
- package/dist/style/vendor/postmate.js +17 -0
- package/dist/style/views/confirmation.js +85 -0
- package/dist/style/views/index.js +29 -0
- package/dist/style/views/method-selector.js +20 -0
- package/dist/style/views/modal.js +93 -0
- package/dist/style/views/result.js +61 -0
- package/dist/style/views/summary.js +123 -0
- package/dist/utils/add-dom-element.js +12 -34
- package/dist/utils/format-currency.js +4 -4
- package/dist/utils/has-valid-css-selector.js +2 -2
- package/dist/utils/index.js +15 -31
- package/dist/utils/is-dom-element.js +1 -1
- package/dist/utils/process-property-as-dom-element.js +12 -17
- package/dist/utils/sleep.js +10 -0
- package/{src/components → dist/views}/__snapshots__/summary.spec.js.snap +7 -3
- package/dist/views/common/iframe/base-iframe.js +57 -0
- package/dist/views/common/iframe/event-listeners.js +50 -0
- package/dist/views/common/iframe/index.js +19 -0
- package/dist/views/common/iframe/method-iframe.js +33 -0
- package/dist/views/common/iframe/modal-iframe.js +38 -0
- package/dist/views/common/iframe/view-iframe.js +31 -0
- package/dist/views/common/render-utilities.js +11 -0
- package/dist/views/confirmation.js +82 -0
- package/dist/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
- package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
- package/dist/views/method-selector/express-methods/google-pay.js +32 -0
- package/dist/views/method-selector/express-methods/paypal.js +19 -0
- package/dist/views/method-selector/generate-digital-wallet.js +59 -0
- package/dist/views/method-selector/generate-digital-wallet.spec.js +132 -0
- package/dist/views/method-selector/get-method-data.js +25 -0
- package/dist/views/method-selector/get-payment-methods.js +55 -0
- package/dist/views/method-selector/get-payment-methods.spec.js +44 -0
- package/dist/views/method-selector/index.js +133 -0
- package/dist/views/method-selector/method-selector.spec.js +139 -0
- package/dist/views/method-selector/mount-express-methods.js +69 -0
- package/dist/views/method-selector/mount-methods.js +78 -0
- package/dist/views/modal.js +83 -0
- package/dist/views/result.js +42 -0
- package/dist/views/summary.js +162 -0
- package/dist/views/summary.spec.js +148 -0
- package/package.json +12 -6
- package/src/events/base-event.js +35 -12
- package/src/events/events.spec.js +11 -0
- package/src/events/index.js +12 -6
- package/src/functions/destroy.js +22 -3
- package/src/functions/destroy.spec.js +63 -0
- package/src/functions/initialize.js +43 -20
- package/src/functions/initialize.spec.js +9 -7
- package/src/functions/mount/fetch-summary-data.js +29 -0
- package/src/functions/mount/fetch-summary-data.spec.js +41 -0
- package/src/functions/mount/index.js +312 -0
- package/src/functions/mount/mount.spec.js +171 -0
- package/src/functions/on.js +17 -14
- package/src/functions/on.spec.js +39 -29
- package/src/functions/purchase.js +24 -64
- package/src/functions/purchase.spec.js +19 -17
- package/src/functions/show.js +27 -7
- package/src/functions/show.spec.js +61 -0
- package/src/functions/update.js +50 -3
- package/src/functions/update.spec.js +107 -0
- package/src/i18n/i18n.spec.js +6 -4
- package/src/i18n/index.js +20 -12
- package/src/index.js +43 -49
- package/src/index.spec.js +11 -42
- package/src/loader/index.js +55 -39
- package/src/loader/loader.spec.js +30 -23
- package/src/storefront/index.js +9 -7
- package/src/storefront/models/plan-model.js +1 -1
- package/src/storefront/models/product-model.js +1 -1
- package/src/storefront/models/ready-to-pay-model.js +10 -4
- package/src/storefront/models/summary-model.js +8 -15
- package/src/storefront/plans.js +16 -12
- package/src/storefront/plans.spec.js +29 -37
- package/src/storefront/products.js +16 -12
- package/src/storefront/products.spec.js +28 -39
- package/src/storefront/purchase.js +8 -6
- package/src/storefront/purchase.spec.js +18 -17
- package/src/storefront/ready-to-pay.js +19 -13
- package/src/storefront/ready-to-pay.spec.js +41 -41
- package/src/storefront/storefront.spec.js +1 -1
- package/src/storefront/summary.js +14 -12
- package/src/storefront/summary.spec.js +37 -50
- package/src/style/base/__snapshots__/theme.spec.js.snap +52 -0
- package/src/style/base/index.js +63 -0
- package/src/style/base/theme.js +61 -0
- package/src/style/base/theme.spec.js +32 -0
- package/src/style/browserslist.js +1 -0
- package/src/style/components/address.js +55 -0
- package/src/style/components/button.js +54 -0
- package/src/style/components/divider.js +39 -0
- package/src/style/components/forms/checkbox.js +76 -0
- package/src/style/components/forms/field.js +44 -0
- package/src/style/components/forms/form.js +19 -0
- package/src/style/components/forms/input.js +36 -0
- package/src/style/components/forms/label.js +34 -0
- package/src/style/components/forms/select.js +54 -0
- package/src/style/components/forms/validation.js +25 -0
- package/src/style/components/icons.js +13 -0
- package/src/style/components/index.js +35 -0
- package/src/style/components/loader.js +41 -0
- package/src/style/components/methods.js +93 -0
- package/src/style/components/overlay.js +24 -0
- package/src/style/helpers/index.js +51 -0
- package/src/style/index.js +30 -0
- package/src/style/payment-instruments/content.js +8 -0
- package/src/style/payment-instruments/index.js +10 -0
- package/src/style/payment-instruments/payment-card.js +26 -0
- package/src/style/utils/color-values.js +9 -0
- package/src/style/vendor/framepay.js +25 -0
- package/src/style/vendor/postmate.js +8 -0
- package/src/style/views/confirmation.js +76 -0
- package/src/style/views/index.js +16 -0
- package/src/style/views/method-selector.js +11 -0
- package/src/style/views/modal.js +84 -0
- package/src/style/views/result.js +52 -0
- package/src/style/views/summary.js +114 -0
- package/src/utils/add-dom-element.js +12 -13
- package/src/utils/format-currency.js +4 -1
- package/src/utils/has-valid-css-selector.js +2 -2
- package/src/utils/index.js +2 -6
- 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 +3 -0
- package/src/views/__snapshots__/summary.spec.js.snap +292 -0
- package/src/views/common/iframe/base-iframe.js +46 -0
- package/src/views/common/iframe/event-listeners.js +27 -0
- package/src/views/common/iframe/index.js +7 -0
- package/src/views/common/iframe/method-iframe.js +21 -0
- package/src/views/common/iframe/modal-iframe.js +27 -0
- package/src/views/common/iframe/view-iframe.js +18 -0
- package/src/views/common/render-utilities.js +4 -0
- package/src/views/confirmation.js +57 -0
- package/src/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
- package/src/views/method-selector/express-methods/apple-pay.js +78 -0
- package/src/views/method-selector/express-methods/google-pay.js +25 -0
- package/src/views/method-selector/express-methods/paypal.js +7 -0
- package/src/views/method-selector/generate-digital-wallet.js +44 -0
- package/src/views/method-selector/generate-digital-wallet.spec.js +131 -0
- package/src/{components/form → views/method-selector}/get-method-data.js +9 -5
- package/src/views/method-selector/get-payment-methods.js +40 -0
- package/src/views/method-selector/get-payment-methods.spec.js +40 -0
- package/src/views/method-selector/index.js +110 -0
- package/src/views/method-selector/method-selector.spec.js +146 -0
- package/src/views/method-selector/mount-express-methods.js +53 -0
- package/src/views/method-selector/mount-methods.js +71 -0
- package/src/views/modal.js +84 -0
- package/src/views/result.js +30 -0
- package/src/{components → views}/summary.js +90 -21
- package/src/views/summary.spec.js +170 -0
- package/tests/async-utilities.js +22 -0
- package/tests/mocks/rebilly-instruments-mock.js +105 -7
- package/dist/components/confirmation.js +0 -103
- package/dist/components/form/form.js +0 -110
- package/dist/components/form/form.spec.js +0 -135
- package/dist/components/form/get-method-data.js +0 -21
- package/dist/components/form/get-payment-methods.js +0 -42
- package/dist/components/form/method-selector.js +0 -61
- package/dist/components/form/mount-express-payment-methods.js +0 -102
- package/dist/components/form/process-digital-wallet-options.js +0 -20
- package/dist/components/form/zoid-helpers.js +0 -130
- package/dist/components/result.js +0 -66
- package/dist/components/summary.js +0 -60
- package/dist/components/summary.spec.js +0 -144
- package/dist/events/instrument-ready.js +0 -51
- package/dist/events/purchase-complete.js +0 -51
- package/dist/functions/mount.js +0 -311
- package/dist/functions/mount.spec.js +0 -203
- package/dist/styles/base-styles.js +0 -12
- package/dist/styles/flat-theme-object.js +0 -42
- package/dist/styles/framepay.js +0 -15
- package/dist/styles/main.js +0 -25
- package/dist/styles/payment-card.js +0 -12
- package/dist/styles/shade-tint-values-helper.js +0 -28
- package/dist/styles/style-variables.js +0 -43
- package/dist/utils/camel-case.js +0 -12
- package/dist/utils/kebab-case.js +0 -10
- package/dist/utils/un-kebab-case.js +0 -10
- package/src/components/confirmation.js +0 -77
- package/src/components/form/__snapshots__/form.spec.js.snap +0 -43
- package/src/components/form/form.js +0 -88
- package/src/components/form/form.spec.js +0 -109
- package/src/components/form/get-payment-methods.js +0 -32
- package/src/components/form/method-selector.js +0 -47
- package/src/components/form/mount-express-payment-methods.js +0 -84
- package/src/components/form/process-digital-wallet-options.js +0 -11
- package/src/components/form/zoid-helpers.js +0 -114
- package/src/components/result.js +0 -50
- package/src/components/summary.spec.js +0 -106
- package/src/events/instrument-ready.js +0 -11
- package/src/events/purchase-complete.js +0 -11
- package/src/functions/mount.js +0 -204
- package/src/functions/mount.spec.js +0 -172
- package/src/styles/base-styles.js +0 -741
- package/src/styles/flat-theme-object.js +0 -12
- package/src/styles/framepay.js +0 -30
- package/src/styles/main.js +0 -17
- package/src/styles/payment-card.js +0 -18
- package/src/styles/shade-tint-values-helper.js +0 -13
- package/src/styles/style-variables.js +0 -34
- package/src/utils/camel-case.js +0 -3
- package/src/utils/kebab-case.js +0 -3
- package/src/utils/un-kebab-case.js +0 -3
|
@@ -3,67 +3,30 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
throw new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
37
|
-
|
|
38
|
-
case 4:
|
|
39
|
-
_context.prev = 4;
|
|
40
|
-
|
|
41
|
-
if (data._raw) {
|
|
42
|
-
delete data._raw;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
_context.next = 8;
|
|
46
|
-
return this.storefront.purchase.purchase({
|
|
47
|
-
data: data
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
case 8:
|
|
51
|
-
resp = _context.sent;
|
|
52
|
-
return _context.abrupt("return", resp);
|
|
53
|
-
|
|
54
|
-
case 12:
|
|
55
|
-
_context.prev = 12;
|
|
56
|
-
_context.t0 = _context["catch"](4);
|
|
57
|
-
throw _context.t0;
|
|
58
|
-
|
|
59
|
-
case 15:
|
|
60
|
-
case "end":
|
|
61
|
-
return _context.stop();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}, _callee, this, [[4, 12]]);
|
|
65
|
-
}));
|
|
66
|
-
return _PostPurchase.apply(this, arguments);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
;
|
|
6
|
+
exports.postPurchase = postPurchase;
|
|
7
|
+
|
|
8
|
+
async function postPurchase({
|
|
9
|
+
data,
|
|
10
|
+
state
|
|
11
|
+
}) {
|
|
12
|
+
if (!state.storefront) {
|
|
13
|
+
throw new Error('Could not access rebilly-js-sdk instance');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (!state.configs || !state.options) {
|
|
17
|
+
throw new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
if (data._raw) {
|
|
22
|
+
delete data._raw;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const resp = await state.storefront.purchase.purchase({
|
|
26
|
+
data
|
|
27
|
+
});
|
|
28
|
+
return resp;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -1,105 +1,69 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _storefrontMock = require("tests/mocks/storefront-mock");
|
|
3
|
+
var _storefrontMock = require("../../tests/mocks/storefront-mock");
|
|
4
4
|
|
|
5
5
|
var _mswWhenThen = require("msw-when-then");
|
|
6
6
|
|
|
7
|
-
var _server = require("tests/msw/server");
|
|
7
|
+
var _server = require("../../tests/msw/server");
|
|
8
8
|
|
|
9
|
-
var _storefrontApiMock = require("tests/mocks/storefront-api-mock");
|
|
9
|
+
var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
|
|
10
10
|
|
|
11
11
|
var _purchase = require("./purchase");
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
20
|
-
|
|
21
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
22
|
-
|
|
23
|
-
describe('Storefront API Purchase', function () {
|
|
24
|
-
var TestPurchaseInstance = /*#__PURE__*/function () {
|
|
25
|
-
function TestPurchaseInstance() {
|
|
26
|
-
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
27
|
-
_ref$configs = _ref.configs,
|
|
28
|
-
configs = _ref$configs === void 0 ? {} : _ref$configs,
|
|
29
|
-
_ref$options = _ref.options,
|
|
30
|
-
options = _ref$options === void 0 ? {} : _ref$options;
|
|
31
|
-
|
|
32
|
-
_classCallCheck(this, TestPurchaseInstance);
|
|
33
|
-
|
|
13
|
+
describe('Storefront API Purchase', () => {
|
|
14
|
+
class TestPurchaseInstance {
|
|
15
|
+
constructor({
|
|
16
|
+
configs = {},
|
|
17
|
+
options = {}
|
|
18
|
+
} = {}) {
|
|
34
19
|
this.configs = configs;
|
|
35
20
|
this.options = options;
|
|
36
21
|
this.storefront = (0, _storefrontMock.MockStorefront)();
|
|
37
22
|
}
|
|
38
23
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
24
|
+
postPurchase(...args) {
|
|
25
|
+
return (0, _purchase.postPurchase)({
|
|
26
|
+
state: this,
|
|
27
|
+
data: args
|
|
28
|
+
});
|
|
29
|
+
}
|
|
45
30
|
|
|
46
|
-
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
it('can make purchase', async () => {
|
|
34
|
+
const instance = new TestPurchaseInstance();
|
|
35
|
+
const payload = {
|
|
36
|
+
websiteId: 'test-website-id',
|
|
37
|
+
items: [{
|
|
38
|
+
planId: 'test-plan-id-1',
|
|
39
|
+
quantity: 1
|
|
40
|
+
}],
|
|
41
|
+
billingAddress: {
|
|
42
|
+
firstName: 'Test',
|
|
43
|
+
lastName: 'Customer'
|
|
44
|
+
},
|
|
45
|
+
paymentInstruction: {
|
|
46
|
+
token: 'test-token'
|
|
47
47
|
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
while (1) {
|
|
57
|
-
switch (_context.prev = _context.next) {
|
|
58
|
-
case 0:
|
|
59
|
-
instance = new TestPurchaseInstance();
|
|
60
|
-
payload = {
|
|
61
|
-
websiteId: 'test-website-id',
|
|
62
|
-
items: [{
|
|
63
|
-
planId: 'test-plan-id-1',
|
|
64
|
-
quantity: 1
|
|
65
|
-
}],
|
|
66
|
-
billingAddress: {
|
|
67
|
-
firstName: 'Test',
|
|
68
|
-
lastName: 'Customer'
|
|
69
|
-
},
|
|
70
|
-
paymentInstruction: {
|
|
71
|
-
token: 'test-token'
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
fields = {
|
|
75
|
-
orderId: 'test-order-id',
|
|
76
|
-
invoice: {
|
|
77
|
-
id: 'test-invoice-id'
|
|
78
|
-
},
|
|
79
|
-
transaction: {
|
|
80
|
-
id: 'test-transaction-id'
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
(0, _server.when)((0, _mswWhenThen.post)("".concat(_storefrontApiMock.storefrontURL, "/purchase"))).thenReturn((0, _mswWhenThen.ok)(fields));
|
|
84
|
-
jest.spyOn(instance.storefront.purchase, 'purchase');
|
|
85
|
-
_context.next = 7;
|
|
86
|
-
return instance.storefront.purchase.purchase(payload);
|
|
87
|
-
|
|
88
|
-
case 7:
|
|
89
|
-
requestResponse = _context.sent;
|
|
90
|
-
expect(instance.storefront.purchase.purchase).toBeCalledTimes(1);
|
|
91
|
-
expect(instance.storefront.purchase.purchase).toBeCalledWith(payload);
|
|
92
|
-
expect(requestResponse.config).toBeInstanceOf(Object);
|
|
93
|
-
expect(requestResponse.fields).toBeInstanceOf(Object);
|
|
94
|
-
expect(requestResponse.response).toBeInstanceOf(Object);
|
|
95
|
-
expect(requestResponse.fields).toEqual(fields);
|
|
96
|
-
expect(requestResponse.fields).toMatchObject(fields);
|
|
97
|
-
|
|
98
|
-
case 15:
|
|
99
|
-
case "end":
|
|
100
|
-
return _context.stop();
|
|
101
|
-
}
|
|
48
|
+
};
|
|
49
|
+
const fields = {
|
|
50
|
+
orderId: 'test-order-id',
|
|
51
|
+
invoice: {
|
|
52
|
+
id: 'test-invoice-id'
|
|
53
|
+
},
|
|
54
|
+
transaction: {
|
|
55
|
+
id: 'test-transaction-id'
|
|
102
56
|
}
|
|
103
|
-
}
|
|
104
|
-
|
|
57
|
+
};
|
|
58
|
+
(0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/purchase`)).thenReturn((0, _mswWhenThen.ok)(fields));
|
|
59
|
+
jest.spyOn(instance.storefront.purchase, 'purchase');
|
|
60
|
+
const requestResponse = await instance.storefront.purchase.purchase(payload);
|
|
61
|
+
expect(instance.storefront.purchase.purchase).toBeCalledTimes(1);
|
|
62
|
+
expect(instance.storefront.purchase.purchase).toBeCalledWith(payload);
|
|
63
|
+
expect(requestResponse.config).toBeInstanceOf(Object);
|
|
64
|
+
expect(requestResponse.fields).toBeInstanceOf(Object);
|
|
65
|
+
expect(requestResponse.response).toBeInstanceOf(Object);
|
|
66
|
+
expect(requestResponse.fields).toEqual(fields);
|
|
67
|
+
expect(requestResponse.fields).toMatchObject(fields);
|
|
68
|
+
});
|
|
105
69
|
});
|
|
@@ -3,115 +3,53 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.fetchReadyToPay = fetchReadyToPay;
|
|
7
7
|
|
|
8
8
|
var _riskDataCollector = require("@rebilly/risk-data-collector");
|
|
9
9
|
|
|
10
10
|
var _readyToPayModel = _interopRequireDefault(require("./models/ready-to-pay-model"));
|
|
11
11
|
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
case 3:
|
|
57
|
-
if (!(!this.configs || !this.options)) {
|
|
58
|
-
_context.next = 5;
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
throw new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
63
|
-
|
|
64
|
-
case 5:
|
|
65
|
-
_context.prev = 5;
|
|
66
|
-
|
|
67
|
-
if (riskMetadata) {
|
|
68
|
-
_context.next = 12;
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
_context.next = 9;
|
|
73
|
-
return (0, _riskDataCollector.collectData)();
|
|
74
|
-
|
|
75
|
-
case 9:
|
|
76
|
-
_yield$collectData = _context.sent;
|
|
77
|
-
_data = _yield$collectData.riskMetadata;
|
|
78
|
-
riskMetadata = _data;
|
|
79
|
-
|
|
80
|
-
case 12:
|
|
81
|
-
websiteId = ((_this$configs = this.configs) === null || _this$configs === void 0 ? void 0 : _this$configs.websiteId) || null;
|
|
82
|
-
items = ((_this$options = this.options) === null || _this$options === void 0 ? void 0 : (_this$options$intent = _this$options.intent) === null || _this$options$intent === void 0 ? void 0 : _this$options$intent.items) || [];
|
|
83
|
-
data = {
|
|
84
|
-
items: items,
|
|
85
|
-
websiteId: websiteId,
|
|
86
|
-
riskMetadata: riskMetadata
|
|
87
|
-
};
|
|
88
|
-
_context.next = 17;
|
|
89
|
-
return this.storefront.purchase.readyToPay({
|
|
90
|
-
data: data
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
case 17:
|
|
94
|
-
_yield$this$storefron = _context.sent;
|
|
95
|
-
readyToPayFields = _yield$this$storefron.fields;
|
|
96
|
-
return _context.abrupt("return", Object.values(readyToPayFields).map(function (fields, index) {
|
|
97
|
-
return new _readyToPayModel["default"](_objectSpread({
|
|
98
|
-
index: index
|
|
99
|
-
}, fields));
|
|
100
|
-
}));
|
|
101
|
-
|
|
102
|
-
case 22:
|
|
103
|
-
_context.prev = 22;
|
|
104
|
-
_context.t0 = _context["catch"](5);
|
|
105
|
-
throw _context.t0;
|
|
106
|
-
|
|
107
|
-
case 25:
|
|
108
|
-
case "end":
|
|
109
|
-
return _context.stop();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}, _callee, this, [[5, 22]]);
|
|
113
|
-
}));
|
|
114
|
-
return _FetchReadyToPay.apply(this, arguments);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
;
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
async function fetchReadyToPay({
|
|
15
|
+
state,
|
|
16
|
+
riskMetadata = null
|
|
17
|
+
}) {
|
|
18
|
+
if (!state.storefront) {
|
|
19
|
+
throw new Error('Could not access rebilly-js-sdk instance');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!state.configs || !state.options) {
|
|
23
|
+
throw new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
var _state$configs, _state$options, _state$options$intent;
|
|
28
|
+
|
|
29
|
+
if (!riskMetadata) {
|
|
30
|
+
const {
|
|
31
|
+
riskMetadata: data
|
|
32
|
+
} = await (0, _riskDataCollector.collectData)();
|
|
33
|
+
riskMetadata = data;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const websiteId = ((_state$configs = state.configs) === null || _state$configs === void 0 ? void 0 : _state$configs.websiteId) || null;
|
|
37
|
+
const items = ((_state$options = state.options) === null || _state$options === void 0 ? void 0 : (_state$options$intent = _state$options.intent) === null || _state$options$intent === void 0 ? void 0 : _state$options$intent.items) || [];
|
|
38
|
+
const data = {
|
|
39
|
+
items,
|
|
40
|
+
websiteId,
|
|
41
|
+
riskMetadata
|
|
42
|
+
};
|
|
43
|
+
const {
|
|
44
|
+
fields: readyToPayFields
|
|
45
|
+
} = await state.storefront.purchase.readyToPay({
|
|
46
|
+
data
|
|
47
|
+
});
|
|
48
|
+
return Object.values(readyToPayFields).map((fields, index) => new _readyToPayModel.default({
|
|
49
|
+
index,
|
|
50
|
+
...fields
|
|
51
|
+
}));
|
|
52
|
+
} catch (error) {
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -1,178 +1,103 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _storefrontMock = require("tests/mocks/storefront-mock");
|
|
3
|
+
var _storefrontMock = require("../../tests/mocks/storefront-mock");
|
|
4
4
|
|
|
5
5
|
var _mswWhenThen = require("msw-when-then");
|
|
6
6
|
|
|
7
|
-
var _server = require("tests/msw/server");
|
|
7
|
+
var _server = require("../../tests/msw/server");
|
|
8
8
|
|
|
9
|
-
var _storefrontApiMock = require("tests/mocks/storefront-api-mock");
|
|
9
|
+
var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
|
|
10
10
|
|
|
11
11
|
var _readyToPay = require("./ready-to-pay");
|
|
12
12
|
|
|
13
13
|
var _readyToPayModel = _interopRequireDefault(require("./models/ready-to-pay-model"));
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
var _asyncUtilities = require("../../tests/async-utilities");
|
|
16
16
|
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
20
|
-
|
|
21
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
22
|
-
|
|
23
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
24
|
-
|
|
25
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
26
|
-
|
|
27
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
28
|
-
|
|
29
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
30
|
-
|
|
31
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
32
|
-
|
|
33
|
-
describe('Storefront API Ready to Pay', function () {
|
|
34
|
-
var TestReadyToPayInstance = /*#__PURE__*/function () {
|
|
35
|
-
function TestReadyToPayInstance() {
|
|
36
|
-
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
37
|
-
_ref$configs = _ref.configs,
|
|
38
|
-
configs = _ref$configs === void 0 ? {} : _ref$configs,
|
|
39
|
-
_ref$options = _ref.options,
|
|
40
|
-
options = _ref$options === void 0 ? {} : _ref$options;
|
|
41
|
-
|
|
42
|
-
_classCallCheck(this, TestReadyToPayInstance);
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
43
18
|
|
|
19
|
+
describe('Storefront API Ready to Pay', () => {
|
|
20
|
+
class TestReadyToPayInstance {
|
|
21
|
+
constructor({
|
|
22
|
+
configs = {},
|
|
23
|
+
options = {}
|
|
24
|
+
} = {}) {
|
|
44
25
|
this.configs = configs;
|
|
45
26
|
this.options = options;
|
|
46
27
|
this.storefront = (0, _storefrontMock.MockStorefront)();
|
|
47
28
|
}
|
|
48
29
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
it('can fetch ready to pay', async () => {
|
|
33
|
+
const readyToPayPayload = [{
|
|
34
|
+
method: 'payment-card',
|
|
35
|
+
feature: null,
|
|
36
|
+
brands: ['Visa'],
|
|
37
|
+
filters: []
|
|
38
|
+
}];
|
|
39
|
+
const configs = {
|
|
40
|
+
websiteId: 'test-website-id'
|
|
41
|
+
};
|
|
42
|
+
const options = {
|
|
43
|
+
intent: {
|
|
44
|
+
items: [{
|
|
45
|
+
planId: 'test-plan-id',
|
|
46
|
+
quantity: 1
|
|
47
|
+
}]
|
|
57
48
|
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
websiteId: 'test-website-id'
|
|
77
|
-
};
|
|
78
|
-
options = {
|
|
79
|
-
intent: {
|
|
80
|
-
items: [{
|
|
81
|
-
planId: 'test-plan-id',
|
|
82
|
-
quantity: 1
|
|
83
|
-
}]
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
(0, _server.when)((0, _mswWhenThen.post)("".concat(_storefrontApiMock.storefrontURL, "/ready-to-pay"))).thenReturn((0, _mswWhenThen.ok)(readyToPayPayload));
|
|
87
|
-
instance = new TestReadyToPayInstance({
|
|
88
|
-
configs: configs,
|
|
89
|
-
options: options
|
|
90
|
-
});
|
|
91
|
-
jest.spyOn(instance.storefront.purchase, 'readyToPay');
|
|
92
|
-
_context.next = 8;
|
|
93
|
-
return instance.fetchReadyToPay();
|
|
94
|
-
|
|
95
|
-
case 8:
|
|
96
|
-
response = _context.sent;
|
|
97
|
-
expect(instance.storefront.purchase.readyToPay).toBeCalledTimes(1);
|
|
98
|
-
expect(instance.storefront.purchase.readyToPay).toBeCalledWith({
|
|
99
|
-
data: {
|
|
100
|
-
items: options.intent.items,
|
|
101
|
-
websiteId: configs.websiteId,
|
|
102
|
-
riskMetadata: {}
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
expect(response).toBeInstanceOf(Array);
|
|
106
|
-
expect(response[0]).toBeInstanceOf(_readyToPayModel["default"]);
|
|
107
|
-
expect(response).toEqual([new _readyToPayModel["default"](_objectSpread({
|
|
108
|
-
index: 0
|
|
109
|
-
}, readyToPayPayload[0]))]);
|
|
110
|
-
|
|
111
|
-
case 14:
|
|
112
|
-
case "end":
|
|
113
|
-
return _context.stop();
|
|
114
|
-
}
|
|
49
|
+
};
|
|
50
|
+
(0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/ready-to-pay`)).thenReturn((0, _mswWhenThen.ok)(readyToPayPayload));
|
|
51
|
+
const instance = new TestReadyToPayInstance({
|
|
52
|
+
configs,
|
|
53
|
+
options
|
|
54
|
+
});
|
|
55
|
+
jest.spyOn(instance.storefront.purchase, 'readyToPay');
|
|
56
|
+
const riskMetadata = null;
|
|
57
|
+
const response = await (0, _readyToPay.fetchReadyToPay)({
|
|
58
|
+
state: instance,
|
|
59
|
+
riskMetadata
|
|
60
|
+
});
|
|
61
|
+
expect(instance.storefront.purchase.readyToPay).toBeCalledTimes(1);
|
|
62
|
+
expect(instance.storefront.purchase.readyToPay).toBeCalledWith({
|
|
63
|
+
data: {
|
|
64
|
+
items: options.intent.items,
|
|
65
|
+
websiteId: configs.websiteId,
|
|
66
|
+
riskMetadata: {}
|
|
115
67
|
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
68
|
+
});
|
|
69
|
+
expect(response).toBeInstanceOf(Array);
|
|
70
|
+
expect(response[0]).toBeInstanceOf(_readyToPayModel.default);
|
|
71
|
+
expect(response).toEqual([new _readyToPayModel.default({
|
|
72
|
+
index: 0,
|
|
73
|
+
...readyToPayPayload[0]
|
|
74
|
+
})]);
|
|
75
|
+
});
|
|
76
|
+
it('should throw errors with no configs or options', async () => {
|
|
77
|
+
const riskMetadata = null;
|
|
78
|
+
const noConfigOrOptionsInstance = new TestReadyToPayInstance({
|
|
121
79
|
configs: null,
|
|
122
80
|
options: null
|
|
123
81
|
});
|
|
124
|
-
|
|
82
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _readyToPay.fetchReadyToPay)({
|
|
83
|
+
riskMetadata,
|
|
84
|
+
state: noConfigOrOptionsInstance
|
|
85
|
+
}));
|
|
86
|
+
const noConfigInstance = new TestReadyToPayInstance({
|
|
125
87
|
configs: null,
|
|
126
88
|
options: {}
|
|
127
89
|
});
|
|
128
|
-
|
|
90
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _readyToPay.fetchReadyToPay)({
|
|
91
|
+
riskMetadata,
|
|
92
|
+
state: noConfigInstance
|
|
93
|
+
}));
|
|
94
|
+
const noOptionsInstance = new TestReadyToPayInstance({
|
|
129
95
|
configs: {},
|
|
130
96
|
options: null
|
|
131
97
|
});
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
case 0:
|
|
137
|
-
_context2.next = 2;
|
|
138
|
-
return noConfigOrOptionsInstance.fetchReadyToPay();
|
|
139
|
-
|
|
140
|
-
case 2:
|
|
141
|
-
case "end":
|
|
142
|
-
return _context2.stop();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}, _callee2);
|
|
146
|
-
}))).rejects.toEqual(NoConfigOrOptionsError);
|
|
147
|
-
expect( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
|
|
148
|
-
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
149
|
-
while (1) {
|
|
150
|
-
switch (_context3.prev = _context3.next) {
|
|
151
|
-
case 0:
|
|
152
|
-
_context3.next = 2;
|
|
153
|
-
return noConfigInstance.fetchReadyToPay();
|
|
154
|
-
|
|
155
|
-
case 2:
|
|
156
|
-
case "end":
|
|
157
|
-
return _context3.stop();
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}, _callee3);
|
|
161
|
-
}))).rejects.toEqual(NoConfigOrOptionsError);
|
|
162
|
-
expect( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
|
|
163
|
-
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
164
|
-
while (1) {
|
|
165
|
-
switch (_context4.prev = _context4.next) {
|
|
166
|
-
case 0:
|
|
167
|
-
_context4.next = 2;
|
|
168
|
-
return noOptionsInstance.fetchReadyToPay();
|
|
169
|
-
|
|
170
|
-
case 2:
|
|
171
|
-
case "end":
|
|
172
|
-
return _context4.stop();
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}, _callee4);
|
|
176
|
-
}))).rejects.toEqual(NoConfigOrOptionsError);
|
|
98
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _readyToPay.fetchReadyToPay)({
|
|
99
|
+
riskMetadata,
|
|
100
|
+
state: noOptionsInstance
|
|
101
|
+
}));
|
|
177
102
|
});
|
|
178
103
|
});
|