@rebilly/instruments 1.0.2-beta.8 → 2.1.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +13 -4
- package/.eslintrc.js +3 -0
- package/.prettierrc.js +11 -0
- package/README.md +15 -314
- package/dist/events/base-event.js +6 -9
- package/dist/events/events.spec.js +4 -4
- package/dist/events/index.js +2 -1
- package/dist/functions/destroy.js +12 -14
- package/dist/functions/destroy.spec.js +3 -3
- package/dist/functions/mount/fetch-data.js +183 -0
- package/dist/functions/mount/fetch-data.spec.js +189 -0
- package/dist/functions/mount/index.js +158 -251
- package/dist/functions/mount/mount.spec.js +24 -121
- package/dist/functions/mount/setup-element.js +40 -0
- package/dist/functions/mount/setup-framepay.js +46 -0
- package/dist/functions/mount/setup-i18n.js +33 -0
- package/dist/functions/mount/setup-options.js +96 -0
- package/dist/functions/mount/setup-options.spec.js +66 -0
- package/dist/functions/mount/setup-storefront.js +34 -0
- package/dist/functions/mount/setup-styles.js +43 -0
- package/dist/functions/on.js +13 -4
- package/dist/functions/on.spec.js +19 -5
- package/dist/functions/purchase.js +139 -22
- package/dist/functions/purchase.spec.js +23 -19
- package/dist/functions/setup.js +85 -0
- package/dist/functions/setup.spec.js +87 -0
- package/dist/functions/show.js +31 -14
- package/dist/functions/show.spec.js +47 -18
- package/dist/functions/update.js +53 -27
- package/dist/functions/update.spec.js +40 -21
- package/dist/i18n/en.json +4 -1
- package/dist/i18n/es.json +4 -1
- package/dist/index.js +67 -56
- package/dist/index.spec.js +7 -27
- package/dist/loader/index.js +4 -3
- package/dist/storefront/index.js +33 -0
- package/dist/storefront/invoices.js +27 -0
- package/dist/storefront/models/base-model.js +18 -0
- package/dist/storefront/models/invoice-model.js +14 -0
- package/dist/storefront/models/plan-model.js +4 -35
- package/dist/storefront/models/product-model.js +4 -23
- package/dist/storefront/models/summary-model.js +12 -25
- package/dist/storefront/models/transaction-model.js +31 -0
- package/dist/storefront/payment-instruments.js +47 -0
- package/dist/storefront/payment-instruments.spec.js +55 -0
- package/dist/storefront/plans.js +15 -24
- package/dist/storefront/plans.spec.js +17 -44
- package/dist/storefront/products.js +16 -20
- package/dist/storefront/products.spec.js +25 -49
- package/dist/storefront/purchase.js +28 -16
- package/dist/storefront/purchase.spec.js +4 -22
- package/dist/storefront/ready-to-pay.js +26 -22
- package/dist/storefront/ready-to-pay.spec.js +25 -54
- package/dist/storefront/storefront.spec.js +1 -1
- package/dist/storefront/summary.js +27 -24
- package/dist/storefront/summary.spec.js +44 -86
- package/dist/storefront/transactions.js +27 -0
- package/dist/style/base/theme.js +3 -3
- package/dist/style/components/methods.js +43 -42
- package/dist/style/utils/color-values.js +1 -3
- package/dist/style/views/confirmation.js +0 -4
- package/dist/style/views/method-selector.js +1 -1
- package/dist/style/views/modal.js +3 -1
- package/dist/style/views/summary.js +5 -1
- package/dist/utils/format-currency.js +4 -2
- package/dist/utils/has-valid-css-selector.js +1 -1
- package/dist/utils/process-property-as-dom-element.js +0 -2
- package/dist/views/__snapshots__/summary.spec.js.snap +103 -113
- package/dist/views/common/iframe/base-iframe.js +10 -2
- package/dist/views/common/iframe/modal-iframe.js +44 -3
- package/dist/views/confirmation.js +44 -20
- package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
- package/dist/views/method-selector/express-methods/google-pay.js +31 -0
- package/dist/views/method-selector/express-methods/paypal.js +19 -0
- package/dist/views/method-selector/generate-digital-wallet.js +68 -0
- package/dist/views/method-selector/generate-digital-wallet.spec.js +135 -0
- package/dist/views/method-selector/get-payment-methods.js +28 -8
- package/dist/views/method-selector/get-payment-methods.spec.js +25 -26
- package/dist/views/method-selector/index.js +55 -86
- package/dist/views/method-selector/method-selector.spec.js +80 -69
- package/dist/views/method-selector/mount-express-methods.js +38 -62
- package/dist/views/method-selector/mount-methods.js +18 -18
- package/dist/views/modal.js +21 -15
- package/dist/views/result.js +13 -16
- package/dist/views/summary.js +170 -114
- package/dist/views/summary.spec.js +72 -76
- package/package.json +5 -4
- package/src/events/base-event.js +15 -17
- package/src/events/events.spec.js +6 -4
- package/src/events/index.js +6 -3
- package/src/functions/destroy.js +12 -13
- package/src/functions/destroy.spec.js +30 -31
- package/src/functions/mount/fetch-data.js +148 -0
- package/src/functions/mount/fetch-data.spec.js +238 -0
- package/src/functions/mount/index.js +129 -244
- package/src/functions/mount/mount.spec.js +35 -139
- package/src/functions/mount/setup-element.js +26 -0
- package/src/functions/mount/setup-framepay.js +41 -0
- package/src/functions/mount/setup-i18n.js +19 -0
- package/src/functions/mount/setup-options.js +100 -0
- package/src/functions/mount/setup-options.spec.js +60 -0
- package/src/functions/mount/setup-storefront.js +24 -0
- package/src/functions/mount/setup-styles.js +30 -0
- package/src/functions/on.js +13 -8
- package/src/functions/on.spec.js +30 -17
- package/src/functions/purchase.js +101 -19
- package/src/functions/purchase.spec.js +18 -18
- package/src/functions/setup.js +48 -0
- package/src/functions/setup.spec.js +98 -0
- package/src/functions/show.js +20 -10
- package/src/functions/show.spec.js +43 -22
- package/src/functions/update.js +50 -27
- package/src/functions/update.spec.js +57 -22
- package/src/i18n/en.json +4 -1
- package/src/i18n/es.json +4 -1
- package/src/i18n/i18n.spec.js +6 -4
- package/src/i18n/index.js +14 -11
- package/src/index.js +41 -52
- package/src/index.spec.js +8 -37
- package/src/loader/index.js +51 -47
- package/src/loader/loader.spec.js +26 -19
- package/src/storefront/index.js +37 -7
- package/src/storefront/invoices.js +11 -0
- package/src/storefront/models/base-model.js +10 -0
- package/src/storefront/models/invoice-model.js +3 -0
- package/src/storefront/models/plan-model.js +3 -35
- package/src/storefront/models/product-model.js +3 -23
- package/src/storefront/models/ready-to-pay-model.js +3 -3
- package/src/storefront/models/summary-model.js +15 -29
- package/src/storefront/models/transaction-model.js +19 -0
- package/src/storefront/payment-instruments.js +30 -0
- package/src/storefront/payment-instruments.spec.js +69 -0
- package/src/storefront/plans.js +16 -23
- package/src/storefront/plans.spec.js +25 -54
- package/src/storefront/products.js +18 -22
- package/src/storefront/products.spec.js +23 -54
- package/src/storefront/purchase.js +14 -14
- package/src/storefront/purchase.spec.js +17 -29
- package/src/storefront/ready-to-pay.js +26 -23
- package/src/storefront/ready-to-pay.spec.js +41 -71
- package/src/storefront/storefront.spec.js +1 -1
- package/src/storefront/summary.js +26 -22
- package/src/storefront/summary.spec.js +60 -109
- package/src/storefront/transactions.js +11 -0
- package/src/style/base/theme.js +10 -8
- package/src/style/base/theme.spec.js +4 -2
- package/src/style/browserslist.js +1 -3
- package/src/style/components/button.js +3 -1
- package/src/style/components/forms/checkbox.js +3 -1
- package/src/style/components/index.js +1 -1
- package/src/style/components/loader.js +3 -1
- package/src/style/components/methods.js +43 -42
- package/src/style/helpers/index.js +1 -1
- package/src/style/index.js +2 -1
- package/src/style/utils/color-values.js +4 -4
- package/src/style/vendor/framepay.js +1 -1
- package/src/style/vendor/postmate.js +1 -1
- package/src/style/views/confirmation.js +0 -4
- package/src/style/views/index.js +1 -1
- package/src/style/views/method-selector.js +1 -1
- package/src/style/views/modal.js +4 -2
- package/src/style/views/summary.js +5 -1
- package/src/utils/add-dom-element.js +12 -13
- package/src/utils/format-currency.js +6 -2
- package/src/utils/has-valid-css-selector.js +2 -2
- package/src/utils/is-dom-element.js +1 -1
- package/src/utils/process-property-as-dom-element.js +27 -24
- package/src/utils/sleep.js +1 -1
- package/src/views/__snapshots__/summary.spec.js.snap +103 -113
- package/src/views/common/iframe/base-iframe.js +12 -4
- package/src/views/common/iframe/event-listeners.js +6 -6
- package/src/views/common/iframe/index.js +1 -1
- package/src/views/common/iframe/method-iframe.js +3 -6
- package/src/views/common/iframe/modal-iframe.js +42 -6
- package/src/views/common/iframe/view-iframe.js +3 -5
- package/src/views/common/render-utilities.js +3 -3
- package/src/views/confirmation.js +34 -25
- package/src/views/method-selector/express-methods/apple-pay.js +78 -0
- package/src/views/method-selector/express-methods/google-pay.js +24 -0
- package/src/views/method-selector/express-methods/paypal.js +7 -0
- package/src/views/method-selector/generate-digital-wallet.js +51 -0
- package/src/views/method-selector/generate-digital-wallet.spec.js +135 -0
- package/src/views/method-selector/get-method-data.js +7 -4
- package/src/views/method-selector/get-payment-methods.js +38 -29
- package/src/views/method-selector/get-payment-methods.spec.js +26 -33
- package/src/views/method-selector/index.js +70 -99
- package/src/views/method-selector/method-selector.spec.js +88 -78
- package/src/views/method-selector/mount-express-methods.js +36 -60
- package/src/views/method-selector/mount-methods.js +32 -21
- package/src/views/modal.js +37 -23
- package/src/views/result.js +12 -15
- package/src/views/summary.js +169 -101
- package/src/views/summary.spec.js +99 -74
- package/tests/async-utilities.js +22 -0
- package/tests/mocks/rebilly-instruments-mock.js +89 -77
- package/tests/mocks/storefront-api-mock.js +8 -0
- package/tests/mocks/storefront-mock.js +17 -0
- package/dist/events/purchase-completed.js +0 -24
- package/dist/functions/initialize.js +0 -82
- package/dist/functions/initialize.spec.js +0 -34
- package/dist/functions/mount/fetch-summary-data.js +0 -31
- package/dist/functions/mount/fetch-summary-data.spec.js +0 -45
- package/dist/views/method-selector/process-digital-wallet-options.js +0 -35
- package/dist/views/method-selector/process-digital-wallet-options.spec.js +0 -80
- package/src/events/purchase-completed.js +0 -11
- package/src/functions/initialize.js +0 -74
- package/src/functions/initialize.spec.js +0 -38
- package/src/functions/mount/fetch-summary-data.js +0 -26
- package/src/functions/mount/fetch-summary-data.spec.js +0 -46
- package/src/views/method-selector/process-digital-wallet-options.js +0 -16
- package/src/views/method-selector/process-digital-wallet-options.spec.js +0 -94
package/dist/views/summary.js
CHANGED
|
@@ -3,121 +3,180 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
6
|
+
exports.lineItemHTML = lineItemHTML;
|
|
7
|
+
exports.summaryBreakdownHTML = summaryBreakdownHTML;
|
|
8
|
+
exports.mountSummary = mountSummary;
|
|
9
|
+
exports.updateSummary = updateSummary;
|
|
9
10
|
|
|
10
11
|
var _riskDataCollector = require("@rebilly/risk-data-collector");
|
|
11
12
|
|
|
12
13
|
var _utils = require("../utils");
|
|
13
14
|
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
exports.baseSummaryHTML = baseSummaryHTML;
|
|
23
|
-
|
|
24
|
-
function MountSummary({
|
|
25
|
-
summary,
|
|
26
|
-
plans,
|
|
27
|
-
products
|
|
28
|
-
} = {}) {
|
|
29
|
-
this.summary.innerHTML += baseSummaryHTML;
|
|
30
|
-
const itemsContainer = document.querySelector('.rebilly-instruments-summary-line-items');
|
|
31
|
-
const summaryBreakdown = document.querySelector('.rebilly-instruments-summary-breakdown');
|
|
15
|
+
var _fetchData = require("../functions/mount/fetch-data");
|
|
16
|
+
|
|
17
|
+
function lineItemHTML({
|
|
18
|
+
state,
|
|
19
|
+
lineItem
|
|
20
|
+
}) {
|
|
21
|
+
var _state$data;
|
|
22
|
+
|
|
32
23
|
const {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
} = this.options;
|
|
37
|
-
const hasThumbnails = optionItems.some(optionItem => optionItem.thumbnail);
|
|
24
|
+
products
|
|
25
|
+
} = state.data;
|
|
38
26
|
const {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
<div class="rebilly-instruments-summary-line-item">
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
</
|
|
70
|
-
<div class="rebilly-instruments-summary-line-item-price-breakdown">
|
|
71
|
-
<p class="rebilly-instruments-summary-line-item-price-breakdown-quantity">${lineItem.quantity}</p>
|
|
72
|
-
<svg class="rebilly-instruments-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
73
|
-
<path d="M12 10.5858l2.8284-2.8284c.3906-.3906 1.0237-.3906 1.4142 0 .3906.3905.3906 1.0236 0 1.4142L13.4142 12l2.8284 2.8284c.3906.3906.3906 1.0237 0 1.4142-.3905.3906-1.0236.3906-1.4142 0L12 13.4142l-2.8284 2.8284c-.3906.3906-1.0237.3906-1.4142 0-.3906-.3905-.3906-1.0236 0-1.4142L10.5858 12 7.7574 9.1716c-.3906-.3906-.3906-1.0237 0-1.4142.3905-.3906 1.0236-.3906 1.4142 0L12 10.5858z" fill-rule="nonzero"/>
|
|
74
|
-
</svg>
|
|
75
|
-
<p class="rebilly-instruments-summary-line-item-price-breakdown-unit-price">${(0, _utils.formatCurrency)(lineItem.unitPrice, currency)}</p>
|
|
76
|
-
</div>
|
|
27
|
+
currency = null
|
|
28
|
+
} = (_state$data = state.data) === null || _state$data === void 0 ? void 0 : _state$data.amountAndCurrency;
|
|
29
|
+
const {
|
|
30
|
+
items: optionItems = []
|
|
31
|
+
} = state.options;
|
|
32
|
+
const hasThumbnails = optionItems === null || optionItems === void 0 ? void 0 : optionItems.some(optionItem => optionItem.thumbnail);
|
|
33
|
+
const {
|
|
34
|
+
thumbnail = null
|
|
35
|
+
} = optionItems.find(optionItem => optionItem.planId === lineItem.planId) || {};
|
|
36
|
+
const {
|
|
37
|
+
name
|
|
38
|
+
} = products.find(product => product.id === lineItem.productId);
|
|
39
|
+
return `
|
|
40
|
+
<div class="rebilly-instruments-summary-line-item">
|
|
41
|
+
${hasThumbnails ? `
|
|
42
|
+
<figure class="rebilly-instruments-summary-line-item-figure">
|
|
43
|
+
${thumbnail ? `<img src="${thumbnail}" alt="${name}">` : ''}
|
|
44
|
+
</figure>
|
|
45
|
+
` : ''}
|
|
46
|
+
<div class="rebilly-instruments-summary-line-item-synopsis">
|
|
47
|
+
<p class="rebilly-instruments-summary-line-item-synopsis-title">${name}</p>
|
|
48
|
+
${lineItem.description ? `
|
|
49
|
+
<p class="rebilly-instruments-summary-line-item-synopsis-description">${lineItem.description}</p>
|
|
50
|
+
` : ''}
|
|
51
|
+
</div>
|
|
52
|
+
<div class="rebilly-instruments-summary-line-item-price-breakdown">
|
|
53
|
+
<p class="rebilly-instruments-summary-line-item-price-breakdown-quantity">${lineItem.quantity}</p>
|
|
54
|
+
<svg class="rebilly-instruments-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
55
|
+
<path d="M12 10.5858l2.8284-2.8284c.3906-.3906 1.0237-.3906 1.4142 0 .3906.3905.3906 1.0236 0 1.4142L13.4142 12l2.8284 2.8284c.3906.3906.3906 1.0237 0 1.4142-.3905.3906-1.0236.3906-1.4142 0L12 13.4142l-2.8284 2.8284c-.3906.3906-1.0237.3906-1.4142 0-.3906-.3905-.3906-1.0236 0-1.4142L10.5858 12 7.7574 9.1716c-.3906-.3906-.3906-1.0237 0-1.4142.3905-.3906 1.0236-.3906 1.4142 0L12 10.5858z" fill-rule="nonzero"/>
|
|
56
|
+
</svg>
|
|
57
|
+
<p class="rebilly-instruments-summary-line-item-price-breakdown-unit-price">${(0, _utils.formatCurrency)(lineItem.unitPrice, currency)}</p>
|
|
77
58
|
</div>
|
|
78
|
-
`;
|
|
79
|
-
});
|
|
80
|
-
summaryBreakdown.innerHTML = `
|
|
81
|
-
<table>
|
|
82
|
-
<colgroup>
|
|
83
|
-
<col>
|
|
84
|
-
<col>
|
|
85
|
-
</colgroup>
|
|
86
|
-
<tr class="rebilly-instruments-summary-breakdown-sub-total">
|
|
87
|
-
<td data-rebilly-i18n="summary.subTotal">Sub Total</td>
|
|
88
|
-
<td>${(0, _utils.formatCurrency)(subtotalAmount, currency)}</td>
|
|
89
|
-
</tr>
|
|
90
|
-
<tr class="rebilly-instruments-summary-breakdown-discounts">
|
|
91
|
-
<td data-rebilly-i18n="summary.discounts">Discounts</td>
|
|
92
|
-
<td>${(0, _utils.formatCurrency)(discountsAmount, currency)}</td>
|
|
93
|
-
</tr>
|
|
94
|
-
<tr class="rebilly-instruments-summary-breakdown-taxes">
|
|
95
|
-
<td data-rebilly-i18n="summary.taxes">Taxes</td>
|
|
96
|
-
<td>${(0, _utils.formatCurrency)(taxAmount, currency)}</td>
|
|
97
|
-
</tr>
|
|
98
|
-
<tr class="rebilly-instruments-summary-breakdown-taxes">
|
|
99
|
-
<td data-rebilly-i18n="summary.shipping">Shipping</td>
|
|
100
|
-
<td>${(0, _utils.formatCurrency)(shippingAmount, currency)}</td>
|
|
101
|
-
</tr>
|
|
102
|
-
</table>
|
|
103
|
-
<div class="rebilly-instruments-summary-breakdown-total">
|
|
104
|
-
<p data-rebilly-i18n="summary.total">Total</p>
|
|
105
|
-
<p class="rebilly-instruments-summary-breakdown-total-amount">
|
|
106
|
-
<span class="rebilly-instruments-summary-breakdown-total-amount-currency">${currency}</span>${(0, _utils.formatCurrency)(total, currency)}
|
|
107
|
-
</p>
|
|
108
59
|
</div>
|
|
109
60
|
`;
|
|
110
|
-
|
|
111
|
-
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function summaryBreakdownHTML({
|
|
64
|
+
state,
|
|
65
|
+
element
|
|
66
|
+
}) {
|
|
67
|
+
const {
|
|
68
|
+
amount = null,
|
|
69
|
+
currency = null,
|
|
70
|
+
discountsAmount = null,
|
|
71
|
+
shippingAmount = null,
|
|
72
|
+
subtotalAmount = null,
|
|
73
|
+
taxAmount = null
|
|
74
|
+
} = { ...state.data.amountAndCurrency,
|
|
75
|
+
...state.data.summaryItems
|
|
76
|
+
};
|
|
77
|
+
let table = null;
|
|
78
|
+
[{
|
|
79
|
+
label: 'Sub Total',
|
|
80
|
+
class: 'sub-total',
|
|
81
|
+
i18n: 'summary.subTotal',
|
|
82
|
+
value: subtotalAmount
|
|
83
|
+
}, {
|
|
84
|
+
label: 'Discounts',
|
|
85
|
+
class: 'discounts',
|
|
86
|
+
i18n: 'summary.discounts',
|
|
87
|
+
value: discountsAmount
|
|
88
|
+
}, {
|
|
89
|
+
label: 'Taxes',
|
|
90
|
+
class: 'taxes',
|
|
91
|
+
i18n: 'summary.taxes',
|
|
92
|
+
value: taxAmount
|
|
93
|
+
}, {
|
|
94
|
+
label: 'Shipping',
|
|
95
|
+
class: 'shipping',
|
|
96
|
+
i18n: 'summary.shipping',
|
|
97
|
+
value: shippingAmount
|
|
98
|
+
}].filter(({
|
|
99
|
+
value
|
|
100
|
+
}) => value !== null).forEach(item => {
|
|
101
|
+
if (!table) {
|
|
102
|
+
table = document.createElement('table');
|
|
103
|
+
table.insertAdjacentHTML('beforeend', `
|
|
104
|
+
<colgroup>
|
|
105
|
+
<col>
|
|
106
|
+
<col>
|
|
107
|
+
</colgroup>
|
|
108
|
+
`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const row = document.createElement('tr');
|
|
112
|
+
row.setAttribute('class', `rebilly-instruments-summary-breakdown-${item.class}`);
|
|
113
|
+
row.insertAdjacentHTML('beforeend', `
|
|
114
|
+
<td data-rebilly-i18n="${item.i18n}">${item.label}</td>
|
|
115
|
+
<td>${(0, _utils.formatCurrency)(item.value, currency)}</td>
|
|
116
|
+
`);
|
|
117
|
+
table.appendChild(row);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
if (table) {
|
|
121
|
+
element.appendChild(table);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const totalElement = document.createElement('div');
|
|
125
|
+
totalElement.setAttribute('class', 'rebilly-instruments-summary-breakdown-total');
|
|
126
|
+
totalElement.insertAdjacentHTML('beforeend', `
|
|
127
|
+
<p data-rebilly-i18n="summary.total">Total</p>
|
|
128
|
+
<p class="rebilly-instruments-summary-breakdown-total-amount">
|
|
129
|
+
<span class="rebilly-instruments-summary-breakdown-total-amount-currency">
|
|
130
|
+
${currency}
|
|
131
|
+
</span>
|
|
132
|
+
${(0, _utils.formatCurrency)(amount, currency)}
|
|
133
|
+
<p>
|
|
134
|
+
`);
|
|
135
|
+
element.appendChild(totalElement);
|
|
136
|
+
return element;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function mountSummary({
|
|
140
|
+
state
|
|
141
|
+
}) {
|
|
142
|
+
const contentContainer = document.createElement('div');
|
|
143
|
+
contentContainer.setAttribute('class', 'rebilly-instruments-content');
|
|
144
|
+
const lineItems = state.data.summaryLineItems;
|
|
145
|
+
|
|
146
|
+
if (lineItems) {
|
|
147
|
+
const lineItemsElement = document.createElement('div');
|
|
148
|
+
lineItemsElement.setAttribute('class', 'rebilly-instruments-summary-line-items');
|
|
149
|
+
lineItems.forEach(lineItem => {
|
|
150
|
+
lineItemsElement.insertAdjacentHTML('beforeend', lineItemHTML({
|
|
151
|
+
state,
|
|
152
|
+
lineItem
|
|
153
|
+
}));
|
|
154
|
+
});
|
|
155
|
+
contentContainer.appendChild(lineItemsElement);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const summaryBreakdownElement = document.createElement('div');
|
|
159
|
+
summaryBreakdownElement.setAttribute('class', 'rebilly-instruments-summary-breakdown');
|
|
160
|
+
contentContainer.appendChild(summaryBreakdownHTML({
|
|
161
|
+
state,
|
|
162
|
+
element: summaryBreakdownElement
|
|
163
|
+
}));
|
|
164
|
+
state.summary.appendChild(contentContainer);
|
|
165
|
+
state.summary.style.minHeight = '';
|
|
166
|
+
state.translate.translateItems();
|
|
167
|
+
state.loader.stopLoading({
|
|
112
168
|
section: 'summary',
|
|
113
169
|
id: 'initSummary'
|
|
114
170
|
});
|
|
115
171
|
}
|
|
116
172
|
|
|
117
|
-
|
|
173
|
+
async function updateSummary({
|
|
174
|
+
state,
|
|
175
|
+
instrument = null
|
|
176
|
+
}) {
|
|
177
|
+
var _state$data$transacti;
|
|
118
178
|
|
|
119
|
-
|
|
120
|
-
this.loader.startLoading({
|
|
179
|
+
state.loader.startLoading({
|
|
121
180
|
section: 'summary',
|
|
122
181
|
id: 'initSummary'
|
|
123
182
|
});
|
|
@@ -132,22 +191,19 @@ async function UpdateSummary(instrument = null) {
|
|
|
132
191
|
};
|
|
133
192
|
}
|
|
134
193
|
|
|
135
|
-
|
|
136
|
-
readyToPay,
|
|
137
|
-
summary: summaryData,
|
|
138
|
-
plans,
|
|
139
|
-
products
|
|
140
|
-
} = await _fetchSummaryData.FetchSummaryData.call(this, {
|
|
194
|
+
state.data = await (0, _fetchData.fetchData)({
|
|
141
195
|
riskMetadata,
|
|
142
|
-
summaryPayload
|
|
196
|
+
summaryPayload,
|
|
197
|
+
state
|
|
143
198
|
});
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const itemsContainer = this.summary.querySelector('.rebilly-instruments-content');
|
|
199
|
+
|
|
200
|
+
if (state.data.transaction && ((_state$data$transacti = state.data.transaction) === null || _state$data$transacti === void 0 ? void 0 : _state$data$transacti.type) === 'setup') {
|
|
201
|
+
state.options.transactionType = 'setup';
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const itemsContainer = state.summary.querySelector('.rebilly-instruments-content');
|
|
151
205
|
itemsContainer === null || itemsContainer === void 0 ? void 0 : itemsContainer.remove();
|
|
152
|
-
|
|
206
|
+
mountSummary({
|
|
207
|
+
state
|
|
208
|
+
});
|
|
153
209
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _summaryModel = _interopRequireDefault(require("
|
|
3
|
+
var _summaryModel = _interopRequireDefault(require("../storefront/models/summary-model"));
|
|
4
4
|
|
|
5
|
-
var _planModel = _interopRequireDefault(require("
|
|
5
|
+
var _planModel = _interopRequireDefault(require("../storefront/models/plan-model"));
|
|
6
6
|
|
|
7
|
-
var _productModel = _interopRequireDefault(require("
|
|
7
|
+
var _productModel = _interopRequireDefault(require("../storefront/models/product-model"));
|
|
8
8
|
|
|
9
9
|
var _loader = require("../loader");
|
|
10
10
|
|
|
@@ -12,6 +12,8 @@ var _i18n = require("../i18n");
|
|
|
12
12
|
|
|
13
13
|
var _summary = require("./summary");
|
|
14
14
|
|
|
15
|
+
var _fetchData = require("../functions/mount/fetch-data");
|
|
16
|
+
|
|
15
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
18
|
|
|
17
19
|
describe('Summary component', () => {
|
|
@@ -24,93 +26,88 @@ describe('Summary component', () => {
|
|
|
24
26
|
|
|
25
27
|
class TestMountSummaryInstance {
|
|
26
28
|
constructor({
|
|
27
|
-
configs = {},
|
|
28
29
|
options = {},
|
|
29
30
|
summary = summaryElement,
|
|
30
31
|
loader = new _loader.Loader(),
|
|
31
|
-
translate = new _i18n.Translate()
|
|
32
|
+
translate = new _i18n.Translate(),
|
|
33
|
+
data = {}
|
|
32
34
|
} = {}) {
|
|
33
|
-
this.configs = configs;
|
|
34
35
|
this.options = options;
|
|
35
36
|
this.summary = summary;
|
|
36
37
|
this.loader = loader;
|
|
37
38
|
this.translate = translate;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
this.data = new _fetchData.DataInstance({
|
|
40
|
+
state: {
|
|
41
|
+
options
|
|
42
|
+
},
|
|
43
|
+
previewPurchase: new _summaryModel.default({
|
|
44
|
+
currency: 'USD',
|
|
45
|
+
lineItems: [{
|
|
46
|
+
type: 'debit',
|
|
47
|
+
description: 'My Awesome Product',
|
|
48
|
+
unitPrice: 30,
|
|
49
|
+
quantity: 1,
|
|
50
|
+
price: 30,
|
|
51
|
+
productId: 'test-product-1',
|
|
52
|
+
planId: 'my-awesome-product'
|
|
53
|
+
}, {
|
|
54
|
+
type: 'debit',
|
|
55
|
+
description: 'Awesome T-Shirt',
|
|
56
|
+
unitPrice: 20,
|
|
57
|
+
quantity: 2,
|
|
58
|
+
price: 40,
|
|
59
|
+
productId: 'test-product-2',
|
|
60
|
+
planId: 'awesome-t-shirt'
|
|
61
|
+
}],
|
|
62
|
+
subtotalAmount: 70,
|
|
63
|
+
taxAmount: 0,
|
|
64
|
+
shippingAmount: 0,
|
|
65
|
+
discountsAmount: 0,
|
|
66
|
+
total: 70
|
|
67
|
+
}),
|
|
68
|
+
plans: [new _planModel.default({
|
|
69
|
+
name: 'My Awesome Product',
|
|
70
|
+
id: 'my-awesome-product',
|
|
71
|
+
productId: 'test-product-1'
|
|
72
|
+
}), new _planModel.default({
|
|
73
|
+
name: 'My Awesome T-Shirt',
|
|
74
|
+
id: 'awesome-t-shirt',
|
|
75
|
+
productId: 'test-product-2'
|
|
76
|
+
})],
|
|
77
|
+
products: [new _productModel.default({
|
|
78
|
+
name: 'My Awesome Product',
|
|
79
|
+
id: 'test-product-1'
|
|
80
|
+
}), new _productModel.default({
|
|
81
|
+
name: 'My Awesome T-Shirt',
|
|
82
|
+
id: 'test-product-2'
|
|
83
|
+
})],
|
|
84
|
+
...data
|
|
85
|
+
});
|
|
43
86
|
}
|
|
44
87
|
|
|
45
88
|
}
|
|
46
89
|
|
|
47
90
|
const options = {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
quantity: 1,
|
|
53
|
-
thumbnail: ''
|
|
54
|
-
}, {
|
|
55
|
-
planId: 'awesome-t-shirt',
|
|
56
|
-
quantity: 2,
|
|
57
|
-
thumbnail: ''
|
|
58
|
-
}]
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const summaryData = new _summaryModel.default({
|
|
62
|
-
currency: "USD",
|
|
63
|
-
lineItems: [{
|
|
64
|
-
type: "debit",
|
|
65
|
-
description: "My Awesome Product",
|
|
66
|
-
unitPrice: 30,
|
|
91
|
+
websiteId: 'test-website-id',
|
|
92
|
+
countryCode: 'US',
|
|
93
|
+
items: [{
|
|
94
|
+
planId: 'my-awesome-product',
|
|
67
95
|
quantity: 1,
|
|
68
|
-
|
|
69
|
-
productId: "test-product-1",
|
|
70
|
-
planId: "my-awesome-product"
|
|
96
|
+
thumbnail: ''
|
|
71
97
|
}, {
|
|
72
|
-
|
|
73
|
-
description: "Awesome T-Shirt",
|
|
74
|
-
unitPrice: 20,
|
|
98
|
+
planId: 'awesome-t-shirt',
|
|
75
99
|
quantity: 2,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
planId: "awesome-t-shirt"
|
|
79
|
-
}],
|
|
80
|
-
subtotalAmount: 70,
|
|
81
|
-
taxAmount: 0,
|
|
82
|
-
shippingAmount: 0,
|
|
83
|
-
discountsAmount: 0,
|
|
84
|
-
total: 70
|
|
85
|
-
});
|
|
86
|
-
const planData = [new _planModel.default({
|
|
87
|
-
name: 'My Awesome Product',
|
|
88
|
-
id: 'my-awesome-product',
|
|
89
|
-
productId: 'test-product-1'
|
|
90
|
-
}), new _planModel.default({
|
|
91
|
-
name: 'My Awesome T-Shirt',
|
|
92
|
-
id: 'awesome-t-shirt',
|
|
93
|
-
productId: 'test-product-2'
|
|
94
|
-
})];
|
|
95
|
-
const productData = [new _productModel.default({
|
|
96
|
-
description: 'My Awesome Product',
|
|
97
|
-
id: 'test-product-1'
|
|
98
|
-
}), new _productModel.default({
|
|
99
|
-
description: 'My Awesome T-Shirt',
|
|
100
|
-
id: 'test-product-2'
|
|
101
|
-
})];
|
|
102
|
-
const configs = {
|
|
103
|
-
websiteId: 'test-website-id'
|
|
100
|
+
thumbnail: ''
|
|
101
|
+
}]
|
|
104
102
|
};
|
|
105
103
|
it('should render the summary correctly', () => {
|
|
106
104
|
const mountSummaryInstance = new TestMountSummaryInstance({
|
|
107
|
-
configs,
|
|
108
105
|
options
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
106
|
+
}); //TODO: improve design to avoid this manual change
|
|
107
|
+
|
|
108
|
+
mountSummaryInstance.loader.DOM.summary = mountSummaryInstance.summary;
|
|
109
|
+
(0, _summary.mountSummary)({
|
|
110
|
+
state: mountSummaryInstance
|
|
114
111
|
}); // Number of line items
|
|
115
112
|
|
|
116
113
|
const itemsContainer = document.querySelector('.rebilly-instruments-summary-line-items');
|
|
@@ -121,15 +118,14 @@ describe('Summary component', () => {
|
|
|
121
118
|
});
|
|
122
119
|
it('should not render the plan description if its falsy', () => {
|
|
123
120
|
const mountSummaryInstance = new TestMountSummaryInstance({
|
|
124
|
-
configs,
|
|
125
121
|
options
|
|
126
122
|
}); // Making one product description falsy
|
|
127
123
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
mountSummaryInstance.data.previewPurchase.lineItems[0].description = null; //TODO: improve design to avoid this manual change
|
|
125
|
+
|
|
126
|
+
mountSummaryInstance.loader.DOM.summary = mountSummaryInstance.summary;
|
|
127
|
+
(0, _summary.mountSummary)({
|
|
128
|
+
state: mountSummaryInstance
|
|
133
129
|
}); // Check that only one description is render
|
|
134
130
|
|
|
135
131
|
const itemsSynopsysDescription = document.querySelectorAll('.rebilly-instruments-summary-line-item-synopsis-description');
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebilly/instruments",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.1-beta.0",
|
|
4
4
|
"author": "Rebilly",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "yarn babel src --out-dir dist --copy-files",
|
|
9
9
|
"dev": "yarn babel src --watch --out-dir dist",
|
|
10
|
-
"test": "yarn jest"
|
|
10
|
+
"test": "yarn jest",
|
|
11
|
+
"test:watch": "yarn jest --watchAll"
|
|
11
12
|
},
|
|
12
13
|
"dependencies": {
|
|
13
14
|
"@babel/cli": "^7.14.5",
|
|
@@ -19,9 +20,9 @@
|
|
|
19
20
|
"lodash.isequal": "^4.5.0",
|
|
20
21
|
"lodash.kebabcase": "^4.1.1",
|
|
21
22
|
"lodash.merge": "^4.6.2",
|
|
23
|
+
"popostmate": "^1.6.4",
|
|
22
24
|
"postcss": "^8.3.6",
|
|
23
|
-
"
|
|
24
|
-
"rebilly-js-sdk": "^42.0.2",
|
|
25
|
+
"rebilly-js-sdk": "^44.4.0",
|
|
25
26
|
"values.js": "^2.0.0"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
package/src/events/base-event.js
CHANGED
|
@@ -5,42 +5,40 @@ export class RegisteredListeners {
|
|
|
5
5
|
document.addEventListener(eventName, callback, false);
|
|
6
6
|
|
|
7
7
|
if (!(eventName in this._listeners)) {
|
|
8
|
-
this._listeners[eventName] = []
|
|
8
|
+
this._listeners[eventName] = [];
|
|
9
9
|
}
|
|
10
10
|
this._listeners[eventName].push(callback);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
removeAll() {
|
|
14
|
-
Object.keys(this._listeners).forEach(eventName => {
|
|
15
|
-
this._listeners[eventName].forEach(callback =>
|
|
16
|
-
document.removeEventListener(eventName, callback, false)
|
|
17
|
-
|
|
14
|
+
Object.keys(this._listeners).forEach((eventName) => {
|
|
15
|
+
this._listeners[eventName].forEach((callback) =>
|
|
16
|
+
document.removeEventListener(eventName, callback, false)
|
|
17
|
+
);
|
|
18
|
+
});
|
|
18
19
|
this._listeners = {};
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
export const registeredListeners = new RegisteredListeners();
|
|
23
24
|
|
|
24
|
-
export default class BaseEvent {
|
|
25
|
+
export default class BaseEvent {
|
|
25
26
|
/**
|
|
26
|
-
* @param {string} name
|
|
27
|
+
* @param {string} name
|
|
27
28
|
*/
|
|
28
29
|
constructor(name) {
|
|
29
|
-
|
|
30
|
+
// Using namespaced internal name as a protection mechanism
|
|
31
|
+
const PREFIX = 'rebilly-instruments-';
|
|
32
|
+
this.internalName = PREFIX+ name;
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
addEventListener
|
|
33
|
-
const innerCallback = ({detail}) => callback(detail);
|
|
34
|
-
registeredListeners.add(this.
|
|
35
|
+
addEventListener(callback) {
|
|
36
|
+
const innerCallback = ({ detail }) => callback(detail);
|
|
37
|
+
registeredListeners.add(this.internalName, innerCallback);
|
|
35
38
|
}
|
|
36
39
|
|
|
37
|
-
removeEventListener() {
|
|
38
|
-
document.removeEventListener(this.name, this.callback, false);
|
|
39
|
-
this.callback = null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
40
|
dispatch(detail) {
|
|
43
|
-
const event = new CustomEvent(this.
|
|
41
|
+
const event = new CustomEvent(this.internalName, {
|
|
44
42
|
bubbles: true,
|
|
45
43
|
detail
|
|
46
44
|
});
|
|
@@ -2,8 +2,10 @@ import kebabCase from 'lodash.kebabcase';
|
|
|
2
2
|
import events, { publicEventNames } from '@/events';
|
|
3
3
|
|
|
4
4
|
it('Should export all public event names', async () => {
|
|
5
|
-
Object.keys(events).forEach(internalEventName => {
|
|
6
|
-
expect(events[internalEventName].
|
|
5
|
+
Object.keys(events).forEach((internalEventName) => {
|
|
6
|
+
expect(events[internalEventName].internalName).toEqual(
|
|
7
|
+
`rebilly-instruments-${kebabCase(internalEventName)}`
|
|
8
|
+
);
|
|
7
9
|
expect(kebabCase(internalEventName) in publicEventNames);
|
|
8
|
-
})
|
|
9
|
-
});
|
|
10
|
+
});
|
|
11
|
+
});
|
package/src/events/index.js
CHANGED
|
@@ -3,9 +3,12 @@ import BaseEvent from './base-event';
|
|
|
3
3
|
|
|
4
4
|
const events = {
|
|
5
5
|
instrumentReady: new BaseEvent('instrument-ready'),
|
|
6
|
-
purchaseCompleted: new BaseEvent('purchase-completed')
|
|
7
|
-
|
|
6
|
+
purchaseCompleted: new BaseEvent('purchase-completed'),
|
|
7
|
+
setupCompleted: new BaseEvent('setup-completed')
|
|
8
|
+
};
|
|
8
9
|
|
|
9
10
|
export default events;
|
|
10
11
|
|
|
11
|
-
export const publicEventNames =
|
|
12
|
+
export const publicEventNames = Object.keys(events).map((internalName) =>
|
|
13
|
+
kebabCase(internalName)
|
|
14
|
+
);
|
package/src/functions/destroy.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import {cancellation} from 'rebilly-js-sdk';
|
|
1
|
+
import { cancellation } from 'rebilly-js-sdk';
|
|
2
2
|
import { registeredListeners } from '../events/base-event';
|
|
3
3
|
import { sleep } from '../utils';
|
|
4
4
|
|
|
5
|
-
export async function
|
|
5
|
+
export async function destroy({ state }) {
|
|
6
6
|
// wait to allow for cancellation to catch any pending api requests
|
|
7
7
|
const sleepMilliseconds = 1000;
|
|
8
8
|
await sleep(sleepMilliseconds);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
iframe.component?.destroy();
|
|
9
|
+
[...(state.iframeComponents || {})].forEach((iframe) => {
|
|
10
|
+
iframe.destroy();
|
|
12
11
|
});
|
|
13
12
|
|
|
14
13
|
registeredListeners.removeAll(document);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
|
|
15
|
+
state.iframeComponents = [];
|
|
16
|
+
state.hasMounted = false;
|
|
17
|
+
|
|
18
|
+
state.summary.textContent = '';
|
|
19
|
+
state.form.textContent = '';
|
|
21
20
|
cancellation.cancelAll();
|
|
22
|
-
|
|
23
|
-
}
|
|
21
|
+
state.loader.clearAll();
|
|
22
|
+
}
|