@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
package/dist/i18n/index.js
CHANGED
|
@@ -5,91 +5,68 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Translate = void 0;
|
|
7
7
|
|
|
8
|
-
var _lodash = require("lodash");
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash.merge"));
|
|
9
9
|
|
|
10
10
|
var _en = _interopRequireDefault(require("./en.json"));
|
|
11
11
|
|
|
12
12
|
var _es = _interopRequireDefault(require("./es.json"));
|
|
13
13
|
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : {
|
|
15
|
-
|
|
16
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
17
|
-
|
|
18
|
-
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; }
|
|
19
|
-
|
|
20
|
-
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; }
|
|
21
|
-
|
|
22
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
23
|
-
|
|
24
|
-
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); } }
|
|
25
|
-
|
|
26
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
27
|
-
|
|
28
|
-
var Translate = /*#__PURE__*/function () {
|
|
29
|
-
function Translate() {
|
|
30
|
-
_classCallCheck(this, Translate);
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
15
|
|
|
16
|
+
class Translate {
|
|
17
|
+
constructor() {
|
|
32
18
|
this.locale = '';
|
|
33
19
|
this.items = [];
|
|
34
20
|
this.languages = {};
|
|
35
21
|
}
|
|
36
22
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}, {
|
|
45
|
-
key: "translateItems",
|
|
46
|
-
value: function translateItems() {
|
|
47
|
-
var _this = this;
|
|
48
|
-
|
|
49
|
-
this.items = document.querySelectorAll('[data-rebilly-i18n]');
|
|
23
|
+
init(locale, messages) {
|
|
24
|
+
this.items = document.querySelectorAll('[data-rebilly-i18n]');
|
|
25
|
+
this.locale = this.getLocale(locale);
|
|
26
|
+
this.languages = (0, _lodash.default)({ ..._en.default,
|
|
27
|
+
..._es.default
|
|
28
|
+
}, messages);
|
|
29
|
+
}
|
|
50
30
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var translate = _this.getTranslation(_this.languages[_this.locale], item.dataset.rebillyI18n);
|
|
31
|
+
translateItems() {
|
|
32
|
+
this.items = document.querySelectorAll('[data-rebilly-i18n]');
|
|
54
33
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
59
|
-
}
|
|
34
|
+
if (this.locale in this.languages) {
|
|
35
|
+
return this.items.forEach(item => {
|
|
36
|
+
const translate = this.getTranslation(this.languages[this.locale], item.dataset.rebillyI18n);
|
|
60
37
|
|
|
61
|
-
|
|
38
|
+
if (translate) {
|
|
39
|
+
item.innerHTML = translate;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
62
42
|
}
|
|
63
|
-
}, {
|
|
64
|
-
key: "getLocale",
|
|
65
|
-
value: function getLocale() {
|
|
66
|
-
var locale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.locale;
|
|
67
43
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
71
46
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
}, {
|
|
82
|
-
key: "getTranslation",
|
|
83
|
-
value: function getTranslation() {
|
|
84
|
-
var lan = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.locale;
|
|
85
|
-
var prop = arguments.length > 1 ? arguments[1] : undefined;
|
|
86
|
-
return prop.split('.').reduce(function (acc, val) {
|
|
87
|
-
return acc === null || acc === void 0 ? void 0 : acc[val];
|
|
88
|
-
}, lan);
|
|
47
|
+
updateTranslationsToNewLocale(newLocale) {
|
|
48
|
+
this.locale = newLocale;
|
|
49
|
+
this.translateItems();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getLocale(locale = this.locale) {
|
|
53
|
+
if (!locale.includes('-') || locale in this.languages) {
|
|
54
|
+
return locale;
|
|
89
55
|
}
|
|
90
|
-
}]);
|
|
91
56
|
|
|
92
|
-
|
|
93
|
-
|
|
57
|
+
locale = locale.replace(/[-._]\w+$/gi, '');
|
|
58
|
+
return this.getLocale(locale);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
translateItem(item) {
|
|
62
|
+
const locale = this.getLocale();
|
|
63
|
+
return this.getTranslation(this.languages[locale], item.dataset.rebillyI18n);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getTranslation(lan = this.locale, prop) {
|
|
67
|
+
return prop.split('.').reduce((acc, val) => acc === null || acc === void 0 ? void 0 : acc[val], lan);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
}
|
|
94
71
|
|
|
95
72
|
exports.Translate = Translate;
|
package/dist/index.js
CHANGED
|
@@ -3,101 +3,100 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
var _initialize = require("./functions/initialize");
|
|
6
|
+
exports.default = exports.RebillyInstrumentsInstance = exports.InstrumentsState = void 0;
|
|
9
7
|
|
|
10
8
|
var _mount = require("./functions/mount");
|
|
11
9
|
|
|
10
|
+
var _purchase = require("./functions/purchase");
|
|
11
|
+
|
|
12
|
+
var _on = require("./functions/on");
|
|
13
|
+
|
|
12
14
|
var _update = require("./functions/update");
|
|
13
15
|
|
|
14
16
|
var _destroy = require("./functions/destroy");
|
|
15
17
|
|
|
16
|
-
var
|
|
18
|
+
var _loader = require("./loader");
|
|
17
19
|
|
|
18
|
-
var
|
|
20
|
+
var _i18n = require("./i18n");
|
|
19
21
|
|
|
20
|
-
var
|
|
22
|
+
var _initialize = require("./functions/initialize");
|
|
21
23
|
|
|
22
|
-
var
|
|
24
|
+
var _show = require("./functions/show");
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
class InstrumentsState {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.options = null;
|
|
29
|
+
this.mountingPoints = null;
|
|
30
|
+
this.storefront = null;
|
|
31
|
+
this.form = null;
|
|
32
|
+
this.summary = null;
|
|
33
|
+
this.loader = new _loader.Loader();
|
|
34
|
+
this.translate = new _i18n.Translate();
|
|
35
|
+
this.iframeComponents = [];
|
|
36
|
+
this.hasMounted = false;
|
|
37
|
+
}
|
|
25
38
|
|
|
26
|
-
|
|
39
|
+
}
|
|
27
40
|
|
|
28
|
-
|
|
41
|
+
exports.InstrumentsState = InstrumentsState;
|
|
29
42
|
|
|
30
|
-
|
|
43
|
+
class RebillyInstrumentsInstance {
|
|
44
|
+
constructor() {
|
|
45
|
+
this.state = new InstrumentsState(); // TODO: mountConfirmation, mountResult have different contract shape when they look similar
|
|
46
|
+
// TODO: review test coverage of UpdateSummary and UpdateMethodSelector as no tests were broken
|
|
47
|
+
// when commenting them
|
|
48
|
+
}
|
|
31
49
|
|
|
32
|
-
|
|
50
|
+
initialize(configs) {
|
|
51
|
+
(0, _initialize.initialize)({
|
|
52
|
+
state: this.state,
|
|
53
|
+
configs
|
|
54
|
+
});
|
|
55
|
+
}
|
|
33
56
|
|
|
34
|
-
|
|
57
|
+
async mount(options) {
|
|
58
|
+
await (0, _mount.mount)({
|
|
59
|
+
state: this.state,
|
|
60
|
+
...options
|
|
61
|
+
});
|
|
62
|
+
}
|
|
35
63
|
|
|
36
|
-
|
|
64
|
+
async destroy() {
|
|
65
|
+
await (0, _destroy.destroy)({
|
|
66
|
+
state: this.state
|
|
67
|
+
});
|
|
68
|
+
}
|
|
37
69
|
|
|
38
|
-
|
|
70
|
+
async update(newConfig) {
|
|
71
|
+
await (0, _update.update)(this.state, newConfig);
|
|
72
|
+
}
|
|
39
73
|
|
|
40
|
-
|
|
74
|
+
async purchase(payload) {
|
|
75
|
+
await (0, _purchase.purchase)({
|
|
76
|
+
state: this.state,
|
|
77
|
+
payload
|
|
78
|
+
});
|
|
79
|
+
}
|
|
41
80
|
|
|
42
|
-
|
|
81
|
+
async show(componentName, payload) {
|
|
82
|
+
await (0, _show.show)({
|
|
83
|
+
componentName,
|
|
84
|
+
payload,
|
|
85
|
+
state: this.state
|
|
86
|
+
});
|
|
87
|
+
}
|
|
43
88
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
_classCallCheck(this, RebillyInstrumentsInstance);
|
|
50
|
-
|
|
51
|
-
this.configs = null;
|
|
52
|
-
this.options = null;
|
|
53
|
-
this.mountingPoints = null;
|
|
54
|
-
this.storefront = null;
|
|
55
|
-
this.form = null;
|
|
56
|
-
this.summary = null;
|
|
57
|
-
this.loader = new _loader.Loader();
|
|
58
|
-
this.translate = new _i18n.Translate();
|
|
59
|
-
this.zoidComponents = {};
|
|
60
|
-
var functionsMap = {
|
|
61
|
-
// "Private" functions
|
|
62
|
-
_fetchReadyToPay: _readyToPay.FetchReadyToPay,
|
|
63
|
-
_fetchSummary: _summary.FetchSummary,
|
|
64
|
-
_fetchPlans: _plans.FetchPlans,
|
|
65
|
-
_fetchProducts: _products.FetchProducts,
|
|
66
|
-
_postPurchase: _purchase2.PostPurchase,
|
|
67
|
-
_mountSummary: _summary2.MountSummary,
|
|
68
|
-
_mountForm: _form.MountForm,
|
|
69
|
-
_mountConfirmation: _confirmation.MountConfirmation,
|
|
70
|
-
_mountResult: _result.MountResult,
|
|
71
|
-
// Public Functions
|
|
72
|
-
initialize: _initialize.Initialize,
|
|
73
|
-
mount: _mount.Mount,
|
|
74
|
-
update: _update.Update,
|
|
75
|
-
destroy: _destroy.Destroy,
|
|
76
|
-
purchase: _purchase.Purchase,
|
|
77
|
-
show: _show.Show,
|
|
78
|
-
on: _on.On
|
|
79
|
-
}; // eslint-disable-next-line no-restricted-syntax
|
|
80
|
-
|
|
81
|
-
var _loop = function _loop() {
|
|
82
|
-
var local = _Object$keys[_i];
|
|
83
|
-
|
|
84
|
-
// eslint-disable-next-line func-names
|
|
85
|
-
_this[local] = function () {
|
|
86
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
87
|
-
args[_key] = arguments[_key];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return functionsMap[local].apply(this, args);
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
for (var _i = 0, _Object$keys = Object.keys(functionsMap); _i < _Object$keys.length; _i++) {
|
|
95
|
-
_loop();
|
|
89
|
+
on(eventName, callback) {
|
|
90
|
+
(0, _on.on)({
|
|
91
|
+
eventName,
|
|
92
|
+
callback
|
|
93
|
+
});
|
|
96
94
|
}
|
|
97
|
-
|
|
95
|
+
|
|
96
|
+
}
|
|
98
97
|
|
|
99
98
|
exports.RebillyInstrumentsInstance = RebillyInstrumentsInstance;
|
|
100
99
|
|
|
101
100
|
var _default = new RebillyInstrumentsInstance();
|
|
102
101
|
|
|
103
|
-
exports
|
|
102
|
+
exports.default = _default;
|
package/dist/index.spec.js
CHANGED
|
@@ -1,42 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
-
|
|
5
3
|
var _index = _interopRequireWildcard(require("./index"));
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
var _asyncUtilities = require("../tests/async-utilities");
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
var _initialize = require("./functions/initialize");
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
var rebillyInstruments;
|
|
9
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
12
|
+
|
|
13
|
+
describe('RebillyInstruments instance', () => {
|
|
14
|
+
let rebillyInstruments;
|
|
15
|
+
|
|
16
|
+
function setupInstance(config = {
|
|
17
|
+
test: 'value'
|
|
18
|
+
}) {
|
|
18
19
|
rebillyInstruments.initialize(config);
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
beforeEach(
|
|
22
|
-
rebillyInstruments = _index
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
rebillyInstruments = _index.default;
|
|
23
24
|
});
|
|
24
|
-
it('should have default export as instance of class',
|
|
25
|
-
expect(_index
|
|
25
|
+
it('should have default export as instance of class', () => {
|
|
26
|
+
expect(_index.default).toBeInstanceOf(_index.RebillyInstrumentsInstance);
|
|
26
27
|
});
|
|
27
|
-
it('should be
|
|
28
|
-
jest.spyOn(rebillyInstruments, 'initialize');
|
|
29
|
-
var config = {
|
|
30
|
-
test: 'value'
|
|
31
|
-
};
|
|
32
|
-
rebillyInstruments.initialize(config);
|
|
33
|
-
expect(rebillyInstruments.initialize).toHaveBeenCalledTimes(1);
|
|
34
|
-
expect(rebillyInstruments.initialize).toHaveBeenCalledWith(config);
|
|
35
|
-
});
|
|
36
|
-
it('should be mountable', function () {
|
|
28
|
+
it('should be mountable', async () => {
|
|
37
29
|
jest.spyOn(rebillyInstruments, 'mount');
|
|
38
|
-
document.body.innerHTML =
|
|
39
|
-
|
|
30
|
+
document.body.innerHTML = `
|
|
31
|
+
<div class="form-selector"></div>
|
|
32
|
+
<div class="summary-selector"></div>
|
|
33
|
+
`;
|
|
34
|
+
const options = {
|
|
40
35
|
form: '.form-selector',
|
|
41
36
|
test: 'value'
|
|
42
37
|
};
|
|
@@ -44,26 +39,11 @@ describe('RebillyInstruments instance', function () {
|
|
|
44
39
|
rebillyInstruments.mount(options);
|
|
45
40
|
expect(rebillyInstruments.mount).toHaveBeenCalledTimes(1);
|
|
46
41
|
expect(rebillyInstruments.mount).toHaveBeenCalledWith(options);
|
|
42
|
+
await (0, _asyncUtilities.avoidUnhandledPromises)();
|
|
47
43
|
});
|
|
48
|
-
it('should be
|
|
49
|
-
jest.spyOn(rebillyInstruments, 'update');
|
|
50
|
-
var config = {
|
|
51
|
-
test: 'value'
|
|
52
|
-
};
|
|
53
|
-
setupInstance();
|
|
54
|
-
rebillyInstruments.update(config);
|
|
55
|
-
expect(rebillyInstruments.update).toHaveBeenCalledTimes(1);
|
|
56
|
-
expect(rebillyInstruments.update).toHaveBeenCalledWith(config);
|
|
57
|
-
});
|
|
58
|
-
it('should be destroyable', function () {
|
|
59
|
-
jest.spyOn(rebillyInstruments, 'destroy');
|
|
60
|
-
setupInstance();
|
|
61
|
-
rebillyInstruments.destroy();
|
|
62
|
-
expect(rebillyInstruments.destroy).toHaveBeenCalledTimes(1);
|
|
63
|
-
});
|
|
64
|
-
it('should be able to trigger a purchase', function () {
|
|
44
|
+
it('should be able to trigger a purchase', () => {
|
|
65
45
|
jest.spyOn(rebillyInstruments, 'purchase');
|
|
66
|
-
|
|
46
|
+
const instrument = {};
|
|
67
47
|
setupInstance();
|
|
68
48
|
rebillyInstruments.purchase(instrument);
|
|
69
49
|
expect(rebillyInstruments.purchase).toHaveBeenCalledTimes(1);
|
package/dist/loader/index.js
CHANGED
|
@@ -7,86 +7,87 @@ exports.Loader = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _isDomElement = _interopRequireDefault(require("../utils/is-dom-element"));
|
|
9
9
|
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : {
|
|
11
|
-
|
|
12
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
-
|
|
14
|
-
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); } }
|
|
15
|
-
|
|
16
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
17
|
-
|
|
18
|
-
var Loader = /*#__PURE__*/function () {
|
|
19
|
-
function Loader() {
|
|
20
|
-
_classCallCheck(this, Loader);
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
11
|
|
|
12
|
+
class Loader {
|
|
13
|
+
constructor() {
|
|
22
14
|
this.summary = [];
|
|
23
15
|
this.form = [];
|
|
16
|
+
this.modal = [];
|
|
24
17
|
this.DOM = {
|
|
25
|
-
loading:
|
|
18
|
+
loading: `
|
|
19
|
+
<div class="rebilly-instruments-loader is-active">
|
|
20
|
+
<div class="rebilly-instruments-loader-spinner"></div>
|
|
21
|
+
</div>
|
|
22
|
+
`
|
|
26
23
|
};
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
section = _ref$section === void 0 ? 'form' : _ref$section,
|
|
35
|
-
_ref$el = _ref.el,
|
|
36
|
-
el = _ref$el === void 0 ? null : _ref$el;
|
|
26
|
+
addDOMElement({
|
|
27
|
+
section = 'form',
|
|
28
|
+
el = null
|
|
29
|
+
} = {}) {
|
|
30
|
+
const minHeight = '200px';
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
el.style.minHeight = minHeight;
|
|
43
|
-
el.style.paddingTop = section === 'form' ? '8px' : '0px';
|
|
44
|
-
this.DOM[section] = el;
|
|
45
|
-
}
|
|
32
|
+
if ((0, _isDomElement.default)(el)) {
|
|
33
|
+
el.style.position = 'relative';
|
|
34
|
+
el.style.minHeight = minHeight;
|
|
35
|
+
this.DOM[section] = el;
|
|
46
36
|
}
|
|
47
|
-
}
|
|
48
|
-
key: "startLoading",
|
|
49
|
-
value: function startLoading() {
|
|
50
|
-
var _this$DOM;
|
|
37
|
+
}
|
|
51
38
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
39
|
+
startLoading({
|
|
40
|
+
section = 'form',
|
|
41
|
+
id = ''
|
|
42
|
+
} = {}) {
|
|
43
|
+
var _this$DOM;
|
|
57
44
|
|
|
58
|
-
|
|
45
|
+
this[section].push(id);
|
|
59
46
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
47
|
+
if ((_this$DOM = this.DOM) !== null && _this$DOM !== void 0 && _this$DOM[section]) {
|
|
48
|
+
if (!this.DOM[section].querySelector('.rebilly-instruments-loader')) {
|
|
49
|
+
this.DOM[section].innerHTML = this.DOM.loading;
|
|
50
|
+
} else {
|
|
51
|
+
this.DOM[section].querySelector('.rebilly-instruments-loader').classList.add('is-active');
|
|
66
52
|
}
|
|
67
53
|
}
|
|
68
|
-
}
|
|
69
|
-
key: "stopLoading",
|
|
70
|
-
value: function stopLoading() {
|
|
71
|
-
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
72
|
-
_ref3$section = _ref3.section,
|
|
73
|
-
section = _ref3$section === void 0 ? 'form' : _ref3$section,
|
|
74
|
-
_ref3$id = _ref3.id,
|
|
75
|
-
id = _ref3$id === void 0 ? '' : _ref3$id;
|
|
54
|
+
}
|
|
76
55
|
|
|
77
|
-
|
|
56
|
+
stopLoading({
|
|
57
|
+
section = 'form',
|
|
58
|
+
id = ''
|
|
59
|
+
} = {}) {
|
|
60
|
+
const idIndex = this[section].indexOf(id);
|
|
78
61
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
62
|
+
if (idIndex !== -1) {
|
|
63
|
+
this[section].splice(idIndex, 1);
|
|
64
|
+
}
|
|
82
65
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
66
|
+
if (!this[section].length && this.DOM[section].querySelector('.rebilly-instruments-loader')) {
|
|
67
|
+
this.DOM[section].querySelector('.rebilly-instruments-loader').classList.remove('is-active');
|
|
86
68
|
}
|
|
87
|
-
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
clearAll() {
|
|
72
|
+
this.form.forEach(id => {
|
|
73
|
+
this.stopLoading({
|
|
74
|
+
id
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
this.summary.forEach(id => {
|
|
78
|
+
this.stopLoading({
|
|
79
|
+
section: 'summary',
|
|
80
|
+
id
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
this.modal.forEach(id => {
|
|
84
|
+
this.stopLoading({
|
|
85
|
+
section: 'modal',
|
|
86
|
+
id
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
88
90
|
|
|
89
|
-
|
|
90
|
-
}();
|
|
91
|
+
}
|
|
91
92
|
|
|
92
93
|
exports.Loader = Loader;
|
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
var _index = require("./index");
|
|
4
4
|
|
|
5
|
-
describe('Loader Class',
|
|
6
|
-
|
|
7
|
-
beforeEach(
|
|
5
|
+
describe('Loader Class', () => {
|
|
6
|
+
let loader;
|
|
7
|
+
beforeEach(() => {
|
|
8
8
|
loader = new _index.Loader();
|
|
9
|
-
document.body.innerHTML =
|
|
9
|
+
document.body.innerHTML = `
|
|
10
|
+
<div class="form-selector"></div>
|
|
11
|
+
<div class="summary-selector"></div>
|
|
12
|
+
`;
|
|
10
13
|
loader.addDOMElement({
|
|
11
14
|
el: document.querySelector('.form-selector')
|
|
12
15
|
});
|
|
@@ -15,7 +18,7 @@ describe('Loader Class', function () {
|
|
|
15
18
|
el: document.querySelector('.summary-selector')
|
|
16
19
|
});
|
|
17
20
|
});
|
|
18
|
-
it('manage state of loading ids',
|
|
21
|
+
it('manage state of loading ids', () => {
|
|
19
22
|
loader.startLoading({
|
|
20
23
|
id: 'loadForm'
|
|
21
24
|
});
|
|
@@ -38,18 +41,18 @@ describe('Loader Class', function () {
|
|
|
38
41
|
expect(loader.form.length).toEqual(1);
|
|
39
42
|
expect(loader.summary.length).toEqual(2);
|
|
40
43
|
});
|
|
41
|
-
it('adds the loader HTML on element and removes the active class when stoped',
|
|
44
|
+
it('adds the loader HTML on element and removes the active class when stoped', () => {
|
|
42
45
|
loader.startLoading({
|
|
43
46
|
id: 'loadForm'
|
|
44
47
|
});
|
|
45
48
|
expect(loader.DOM.form.innerHTML).toMatch('rebilly-instruments-loader');
|
|
46
|
-
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('active')).toEqual(true);
|
|
49
|
+
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('is-active')).toEqual(true);
|
|
47
50
|
loader.stopLoading({
|
|
48
51
|
id: 'loadForm'
|
|
49
52
|
});
|
|
50
|
-
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('active')).toEqual(false);
|
|
53
|
+
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('is-active')).toEqual(false);
|
|
51
54
|
});
|
|
52
|
-
it('keeps loading when there are Ids on the element array',
|
|
55
|
+
it('keeps loading when there are Ids on the element array', () => {
|
|
53
56
|
loader.startLoading({
|
|
54
57
|
id: 'loadForm'
|
|
55
58
|
});
|
|
@@ -57,10 +60,10 @@ describe('Loader Class', function () {
|
|
|
57
60
|
id: 'updateForm'
|
|
58
61
|
});
|
|
59
62
|
expect(loader.DOM.form.innerHTML).toMatch('rebilly-instruments-loader');
|
|
60
|
-
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('active')).toEqual(true);
|
|
63
|
+
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('is-active')).toEqual(true);
|
|
61
64
|
loader.stopLoading({
|
|
62
65
|
id: 'loadForm'
|
|
63
66
|
});
|
|
64
|
-
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('active')).toEqual(true);
|
|
67
|
+
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('is-active')).toEqual(true);
|
|
65
68
|
});
|
|
66
69
|
});
|