@rebilly/instruments 4.4.0 → 4.6.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 +24 -26
- package/CHANGELOG.md +14 -0
- package/dist/index.js +14 -40
- package/dist/index.min.js +14 -40
- package/package.json +16 -5
- package/project.json +9 -0
- package/rollup.config.mjs +21 -26
- package/src/data/options-schema/index.js +94 -78
- package/src/data/options-schema/schemas/options-schema.js +420 -408
- package/src/events/base-event.js +34 -34
- package/src/events/events.spec.js +6 -6
- package/src/events/index.js +5 -5
- package/src/functions/destroy.js +19 -19
- package/src/functions/destroy.spec.js +41 -41
- package/src/functions/mount/fetch-data.js +200 -193
- package/src/functions/mount/fetch-data.spec.js +287 -285
- package/src/functions/mount/get-lead-source-data.js +31 -31
- package/src/functions/mount/get-lead-source-data.spec.js +19 -19
- package/src/functions/mount/index.js +73 -65
- package/src/functions/mount/mount.spec.js +77 -66
- package/src/functions/mount/setup-element.js +23 -23
- package/src/functions/mount/setup-framepay-theme.js +86 -68
- package/src/functions/mount/setup-framepay.js +9 -5
- package/src/functions/mount/setup-i18n.js +15 -15
- package/src/functions/mount/setup-options.js +74 -74
- package/src/functions/mount/setup-options.spec.js +325 -289
- package/src/functions/mount/setup-storefront.js +15 -20
- package/src/functions/mount/setup-styles-vars.js +19 -22
- package/src/functions/mount/setup-user-flow.js +51 -47
- package/src/functions/on.js +5 -5
- package/src/functions/on.spec.js +60 -51
- package/src/functions/purchase.js +149 -134
- package/src/functions/purchase.spec.js +59 -56
- package/src/functions/setup.js +53 -49
- package/src/functions/setup.spec.js +88 -75
- package/src/functions/show.js +13 -14
- package/src/functions/show.spec.js +53 -53
- package/src/functions/update.js +30 -28
- package/src/functions/update.spec.js +94 -93
- package/src/i18n/en.json +32 -32
- package/src/i18n/es.json +29 -29
- package/src/i18n/i18n.spec.js +18 -18
- package/src/i18n/index.js +48 -48
- package/src/instance.js +36 -36
- package/src/instance.spec.js +29 -27
- package/src/loader/index.js +95 -70
- package/src/loader/loader.spec.js +63 -63
- package/src/state/iframes.js +21 -21
- package/src/state/index.js +56 -54
- package/src/storefront/account-and-website.js +10 -8
- package/src/storefront/account-and-website.spec.js +55 -55
- package/src/storefront/deposit-requests.js +6 -6
- package/src/storefront/fetch-plans-from-addons-bumpOffer.js +21 -19
- package/src/storefront/fetch-products-from-plans.js +52 -51
- package/src/storefront/fetch-products-from-plans.spec.js +90 -87
- package/src/storefront/index.js +56 -49
- package/src/storefront/invoices.js +15 -15
- package/src/storefront/invoices.spec.js +69 -65
- package/src/storefront/models/account-model.js +29 -32
- package/src/storefront/models/base-model.js +6 -9
- package/src/storefront/models/deposit-request-model.js +22 -13
- package/src/storefront/models/invoice-model.js +16 -16
- package/src/storefront/models/payment-metadata.js +4 -4
- package/src/storefront/models/plan-model.js +73 -64
- package/src/storefront/models/ready-to-pay-model.js +59 -59
- package/src/storefront/models/summary-model.js +43 -46
- package/src/storefront/models/transaction-model.js +11 -14
- package/src/storefront/payment-instruments.js +38 -35
- package/src/storefront/payment-instruments.spec.js +81 -62
- package/src/storefront/purchase.js +50 -44
- package/src/storefront/purchase.spec.js +40 -40
- package/src/storefront/ready-to-pay.js +75 -77
- package/src/storefront/ready-to-pay.spec.js +59 -54
- package/src/storefront/storefront.spec.js +9 -9
- package/src/storefront/summary.js +93 -67
- package/src/storefront/summary.spec.js +108 -106
- package/src/storefront/transactions.js +6 -6
- package/src/style/base/default-theme.js +928 -923
- package/src/style/base/theme.js +21 -21
- package/src/style/base/theme.spec.js +13 -13
- package/src/style/index.js +3 -3
- package/src/style/utils/border.js +40 -27
- package/src/style/utils/color-values.js +18 -18
- package/src/style/utils/minifyCss.js +6 -6
- package/src/utils/add-dom-element.js +14 -14
- package/src/utils/format-currency.js +6 -5
- package/src/utils/has-valid-css-selector.js +2 -2
- package/src/utils/index.js +6 -6
- package/src/utils/is-dom-element.js +1 -1
- package/src/utils/process-property-as-dom-element.js +22 -22
- package/src/utils/quantity.js +26 -28
- package/src/utils/sleep.js +3 -1
- package/src/views/amount-selector.js +37 -36
- package/src/views/common/iframe/base-iframe.js +53 -52
- package/src/views/common/iframe/events/change-iframe-src-handler.js +5 -5
- package/src/views/common/iframe/events/dispatch-event-handler.js +4 -4
- package/src/views/common/iframe/events/resize-component-handler.js +8 -8
- package/src/views/common/iframe/events/show-error-handler.js +2 -2
- package/src/views/common/iframe/events/stop-loader-handler.js +8 -8
- package/src/views/common/iframe/events/update-addons-handler.js +20 -13
- package/src/views/common/iframe/events/update-coupons-handler.js +9 -9
- package/src/views/common/iframe/events/update-items-handler.js +26 -22
- package/src/views/common/iframe/modal-iframe.js +67 -56
- package/src/views/common/iframe/view-iframe.js +11 -11
- package/src/views/common/render-utilities.js +2 -2
- package/src/views/confirmation.js +33 -30
- package/src/views/errors.js +89 -79
- package/src/views/form.js +41 -37
- package/src/views/method-selector/express-methods.js +46 -46
- package/src/views/method-selector/generate-digital-wallet.js +46 -45
- package/src/views/method-selector/generate-digital-wallet.spec.js +104 -102
- package/src/views/method-selector/generate-framepay-config.js +53 -51
- package/src/views/method-selector/generate-framepay-config.spec.js +197 -173
- package/src/views/method-selector/get-method-data.js +5 -6
- package/src/views/method-selector/get-payment-methods.js +18 -16
- package/src/views/method-selector/get-payment-methods.spec.js +29 -27
- package/src/views/method-selector/index.js +154 -139
- package/src/views/method-selector/method-selector.spec.js +13 -13
- package/src/views/method-selector/mount-bump-offer.js +65 -49
- package/src/views/method-selector/mount-express-methods.js +89 -85
- package/src/views/modal.js +74 -67
- package/src/views/result.js +14 -14
- package/src/views/summary.js +25 -26
- package/tests/async-utilities.js +13 -13
- package/tests/mocks/framepay-mock.js +9 -8
- package/tests/mocks/rebilly-api-mock.js +5 -3
- package/tests/mocks/rebilly-instruments-mock.js +121 -117
- package/tests/mocks/storefront-api-mock.js +55 -48
- package/tests/mocks/storefront-mock.js +10 -14
- package/tests/msw/server.js +6 -6
- package/tests/setup-test.js +14 -16
- package/vitest.config.js +14 -14
- package/.eslintrc.js +0 -34
- package/.prettierrc.js +0 -11
|
@@ -13,18 +13,47 @@ import { updateSummary } from '../summary';
|
|
|
13
13
|
import { mountAmountSelector } from '../amount-selector';
|
|
14
14
|
|
|
15
15
|
function getElement(id, rootElement = state.form) {
|
|
16
|
-
|
|
16
|
+
return rootElement.querySelector(`[data-rebilly-instruments="${id}"]`);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
const getBumpOfferElement = () => {
|
|
20
|
+
const rootDiv = document.createElement('div');
|
|
21
|
+
rootDiv.classList.add('rebilly-instruments-bump-offers');
|
|
22
|
+
rootDiv.setAttribute('data-rebilly-instruments', 'bump-offer');
|
|
23
|
+
return rootDiv;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function hideExtraUI() {
|
|
27
|
+
const { expressMethods } = getPaymentMethods();
|
|
28
|
+
|
|
29
|
+
if (state.options?.deposit) {
|
|
30
|
+
const linkElement = getElement('deposit-back');
|
|
31
|
+
if (linkElement) {
|
|
32
|
+
linkElement.style.height = '0px';
|
|
33
|
+
linkElement.style.overflow = 'hidden';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (expressMethods.length) {
|
|
38
|
+
const expressMethodsElement = getElement('express-methods');
|
|
39
|
+
if (expressMethodsElement) {
|
|
40
|
+
expressMethodsElement.style.height = '0px';
|
|
41
|
+
expressMethodsElement.style.overflow = 'hidden';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (state.options?.bumpOffer?.length) {
|
|
46
|
+
const bumpOfferElement = getElement('bump-offer');
|
|
47
|
+
if (bumpOfferElement) {
|
|
48
|
+
bumpOfferElement.style.height = '0px';
|
|
49
|
+
bumpOfferElement.style.overflow = 'hidden';
|
|
50
|
+
bumpOfferElement.style.marginBottom = '0px';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
24
53
|
}
|
|
25
54
|
|
|
26
55
|
const backToAmountElement = () => {
|
|
27
|
-
|
|
56
|
+
const template = `
|
|
28
57
|
<div class="rebilly-instruments-confirmation-go-back-link" style="display: inline-block;margin-bottom: var(--rebilly-spacingM);margin-left: calc(var(--rebilly-spacingXs) * -1);">
|
|
29
58
|
<a
|
|
30
59
|
class="rebilly-instruments-link has-icon-left"
|
|
@@ -45,27 +74,24 @@ const backToAmountElement = () => {
|
|
|
45
74
|
</a>
|
|
46
75
|
</div>
|
|
47
76
|
`;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return rootDiv;
|
|
59
|
-
}
|
|
77
|
+
const rootDiv = document.createElement('div');
|
|
78
|
+
rootDiv.setAttribute('data-rebilly-instruments', 'deposit-back');
|
|
79
|
+
rootDiv.innerHTML += template;
|
|
80
|
+
|
|
81
|
+
const link = rootDiv.querySelector('.rebilly-instruments-link');
|
|
82
|
+
link.addEventListener('click', () => {
|
|
83
|
+
hideExtraUI();
|
|
84
|
+
mountAmountSelector();
|
|
85
|
+
});
|
|
60
86
|
|
|
87
|
+
return rootDiv;
|
|
88
|
+
};
|
|
61
89
|
|
|
62
|
-
const expressMethodsElement = ({
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
rootDiv.setAttribute('data-rebilly-instruments', 'express-methods');
|
|
68
|
-
rootDiv.innerHTML = `
|
|
90
|
+
const expressMethodsElement = ({ expressMethods }) => {
|
|
91
|
+
const rootDiv = document.createElement('div');
|
|
92
|
+
rootDiv.classList.add('rebilly-instruments-method-selector');
|
|
93
|
+
rootDiv.setAttribute('data-rebilly-instruments', 'express-methods');
|
|
94
|
+
rootDiv.innerHTML = `
|
|
69
95
|
<div class="rebilly-instruments-express-methods ">
|
|
70
96
|
<span data-rebilly-i18n="form.expressCheckout" class="rebilly-instruments-express-methods-label">Express checkout</span>
|
|
71
97
|
<div class="rebilly-instruments-express-methods-container" data-rebilly-instruments="express-methods-container"></div>
|
|
@@ -74,135 +100,124 @@ const expressMethodsElement = ({
|
|
|
74
100
|
<span class="rebilly-instruments-divider-label" data-rebilly-i18n="form.or">Or</span>
|
|
75
101
|
</div>
|
|
76
102
|
`;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
export function hideExtraUI() {
|
|
89
|
-
const { expressMethods } = getPaymentMethods();
|
|
90
|
-
|
|
91
|
-
if (state.options?.deposit) {
|
|
92
|
-
const linkElement = getElement('deposit-back');
|
|
93
|
-
if (linkElement) {
|
|
94
|
-
linkElement.style.height = '0px';
|
|
95
|
-
linkElement.style.overflow = 'hidden';
|
|
103
|
+
const expressMethodsContainer = getElement(
|
|
104
|
+
'express-methods-container',
|
|
105
|
+
rootDiv,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const useCompactExpressInstruments =
|
|
109
|
+
state.options.paymentInstruments.compactExpressInstruments &&
|
|
110
|
+
expressMethods.length;
|
|
111
|
+
if (useCompactExpressInstruments) {
|
|
112
|
+
rootDiv.classList.add('has-express-compact');
|
|
113
|
+
expressMethodsContainer.classList.add('is-compact');
|
|
96
114
|
}
|
|
97
|
-
}
|
|
98
115
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (expressMethodsElement) {
|
|
102
|
-
expressMethodsElement.style.height = '0px';
|
|
103
|
-
expressMethodsElement.style.overflow = 'hidden';
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (state.options?.bumpOffer?.length) {
|
|
108
|
-
const bumpOfferElement = getElement('bump-offer');
|
|
109
|
-
if (bumpOfferElement) {
|
|
110
|
-
bumpOfferElement.style.height = '0px';
|
|
111
|
-
bumpOfferElement.style.overflow = 'hidden';
|
|
112
|
-
bumpOfferElement.style.marginBottom = '0px';
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
+
return rootDiv;
|
|
117
|
+
};
|
|
116
118
|
|
|
117
119
|
export async function mountMethodSelector() {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
120
|
+
const contentEl = getElement('content');
|
|
121
|
+
const formEl = getElement('form');
|
|
122
|
+
|
|
123
|
+
const { expressMethods, methods } = getPaymentMethods();
|
|
124
|
+
|
|
125
|
+
if (state.options?.deposit) {
|
|
126
|
+
const existingDepositBackElement = getElement('deposit-back');
|
|
127
|
+
if (existingDepositBackElement) {
|
|
128
|
+
existingDepositBackElement.style.height = 'auto';
|
|
129
|
+
} else {
|
|
130
|
+
contentEl.insertBefore(backToAmountElement(), formEl);
|
|
131
|
+
}
|
|
129
132
|
}
|
|
130
|
-
}
|
|
131
133
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
134
|
+
if (expressMethods.length) {
|
|
135
|
+
const existingExpressMethodElement = getElement('express-methods');
|
|
136
|
+
if (existingExpressMethodElement) {
|
|
137
|
+
existingExpressMethodElement.style.height = 'auto';
|
|
138
|
+
} else {
|
|
139
|
+
contentEl.insertBefore(
|
|
140
|
+
expressMethodsElement({ expressMethods }),
|
|
141
|
+
formEl,
|
|
142
|
+
);
|
|
143
|
+
state.options.digitalWallet = generateDigitalWallet({
|
|
144
|
+
expressMethods,
|
|
145
|
+
});
|
|
146
|
+
const container = document.querySelector(
|
|
147
|
+
'[data-rebilly-instruments="express-methods-container"]',
|
|
148
|
+
);
|
|
149
|
+
mountExpressMethods({
|
|
150
|
+
methods: expressMethods,
|
|
151
|
+
container,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
144
154
|
}
|
|
145
|
-
}
|
|
146
155
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
if (state.options?.bumpOffer?.length) {
|
|
157
|
+
const existingExpressMethodElement = getElement('bump-offer');
|
|
158
|
+
if (existingExpressMethodElement) {
|
|
159
|
+
existingExpressMethodElement.style.height = 'auto';
|
|
160
|
+
existingExpressMethodElement.style.marginBottom =
|
|
161
|
+
'calc(var(--rebilly-spacingM) + var(--rebilly-fontSizeS))';
|
|
162
|
+
} else {
|
|
163
|
+
contentEl.insertBefore(getBumpOfferElement(), formEl);
|
|
164
|
+
const container = getElement('bump-offer');
|
|
165
|
+
mountBumpOffer({
|
|
166
|
+
container,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
158
169
|
}
|
|
159
|
-
}
|
|
160
170
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
171
|
+
if (methods.length) {
|
|
172
|
+
const iframe = iframes.form;
|
|
173
|
+
if (!iframe) {
|
|
174
|
+
await mountForm();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const modelSafeState = state.toModel();
|
|
178
|
+
const model = {
|
|
179
|
+
options: modelSafeState.options,
|
|
180
|
+
data: modelSafeState.data,
|
|
181
|
+
mainStyleVars: modelSafeState.mainStyleVars,
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
iframe?.component?.call('route', {
|
|
185
|
+
name: 'method-switch',
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
iframe?.component?.call('update', model);
|
|
189
|
+
|
|
190
|
+
iframe?.component?.on('choose-another-method', () => {
|
|
191
|
+
if (state.data.isPurchase) {
|
|
192
|
+
updateSummary();
|
|
193
|
+
}
|
|
194
|
+
mountMethodSelector();
|
|
195
|
+
});
|
|
196
|
+
} else {
|
|
197
|
+
state.loader.stopLoading({ id: 'rebilly-instruments-form' });
|
|
198
|
+
state.form.querySelector(
|
|
199
|
+
'[data-rebilly-instruments="form"]',
|
|
200
|
+
).style.display = 'none';
|
|
201
|
+
document
|
|
202
|
+
.querySelectorAll('[data-rebilly-instruments="divider"]')
|
|
203
|
+
.forEach((el) => {
|
|
204
|
+
el.style.display = 'none';
|
|
205
|
+
});
|
|
165
206
|
}
|
|
166
207
|
|
|
167
|
-
|
|
168
|
-
const model = {
|
|
169
|
-
options: modelSafeState.options,
|
|
170
|
-
data: modelSafeState.data,
|
|
171
|
-
mainStyleVars: modelSafeState.mainStyleVars,
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
iframe?.component?.call('route', {
|
|
175
|
-
name: 'method-switch'
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
iframe?.component?.call('update', model);
|
|
179
|
-
|
|
180
|
-
iframe?.component?.on('choose-another-method', () => {
|
|
181
|
-
if (state.data.isPurchase) {
|
|
182
|
-
updateSummary();
|
|
183
|
-
}
|
|
184
|
-
mountMethodSelector();
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
} else {
|
|
188
|
-
state.loader.stopLoading({id: 'rebilly-instruments-form'});
|
|
189
|
-
state.form.querySelector('[data-rebilly-instruments="form"]').style.display = 'none';
|
|
190
|
-
document.querySelectorAll('[data-rebilly-instruments="divider"]').forEach(el => { el.style.display = 'none' });
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
state.translate.translateItems();
|
|
208
|
+
state.translate.translateItems();
|
|
194
209
|
}
|
|
195
210
|
|
|
196
211
|
export async function updateMethodSelector() {
|
|
197
|
-
|
|
212
|
+
state.loader.startLoading({ id: 'rebilly-instruments-methods' });
|
|
198
213
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
214
|
+
const { riskMetadata } = await collectData();
|
|
215
|
+
state.data = await fetchData({ riskMetadata });
|
|
216
|
+
state.updateModel();
|
|
202
217
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
218
|
+
if (state.data.transaction && state.data.transaction?.type === 'setup') {
|
|
219
|
+
state.options.transactionType = 'setup';
|
|
220
|
+
}
|
|
206
221
|
|
|
207
|
-
|
|
222
|
+
mountMethodSelector();
|
|
208
223
|
}
|
|
@@ -2,19 +2,19 @@ import { RenderMockRebillyInstruments } from 'tests/mocks/rebilly-instruments-mo
|
|
|
2
2
|
import { updateMethodSelector } from './index';
|
|
3
3
|
|
|
4
4
|
describe('Methods Selector Component', () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
it('should inject the proper HTML for express methods', async () => {
|
|
6
|
+
await RenderMockRebillyInstruments({
|
|
7
|
+
form: '.rebilly-instruments-form',
|
|
8
|
+
});
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const form = document.querySelector('.rebilly-instruments-form');
|
|
11
|
+
expect(form).toMatchSnapshot();
|
|
12
|
+
});
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
it('should allow updating method selector', async () => {
|
|
15
|
+
await RenderMockRebillyInstruments();
|
|
16
|
+
await updateMethodSelector({
|
|
17
|
+
mainStyleVars: 'any main style',
|
|
18
|
+
});
|
|
18
19
|
});
|
|
19
|
-
|
|
20
|
-
});
|
|
20
|
+
});
|
|
@@ -1,79 +1,94 @@
|
|
|
1
1
|
import state from '../../state';
|
|
2
2
|
import formatCurrency from '../../utils/format-currency';
|
|
3
|
-
import {fetchSummary} from '../../storefront/summary'
|
|
3
|
+
import { fetchSummary } from '../../storefront/summary';
|
|
4
4
|
|
|
5
|
-
function lineItem({offer}) {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function lineItem({ offer }) {
|
|
6
|
+
const plan = state.data.plans.find((item) => item.id === offer.planId);
|
|
7
|
+
const product = state.data.products.find(
|
|
8
|
+
(item) => item.id === plan.productId,
|
|
9
|
+
);
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
const rif = (condition, template) => (condition ? template : '');
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
function unitPrice() {
|
|
14
|
+
const planPricing = plan.pricing.isBracket
|
|
15
|
+
? plan.pricing.brackets[0].price
|
|
16
|
+
: plan.pricing.price;
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const basePrice = formatCurrency(planPricing, plan.currency);
|
|
19
|
+
return plan.pricing.isBracket
|
|
20
|
+
? state.translate
|
|
21
|
+
.getTranslation('form.bumpOffer.startingAt')
|
|
22
|
+
.replace('{basePrice}', basePrice)
|
|
23
|
+
: basePrice;
|
|
24
|
+
}
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
const thumbnail = (item) =>
|
|
27
|
+
rif(
|
|
28
|
+
item.thumbnail,
|
|
29
|
+
`
|
|
24
30
|
<figure class="rebilly-instruments-bump-offer-line-item-figure">
|
|
25
31
|
<img src="${item.thumbnail}" :alt="${item.name}"/>
|
|
26
32
|
</figure>
|
|
27
|
-
|
|
33
|
+
`,
|
|
34
|
+
);
|
|
28
35
|
|
|
29
|
-
|
|
36
|
+
const synopsis = (item) => `
|
|
30
37
|
<div class="rebilly-instruments-bump-offer-line-item-synopsis">
|
|
31
38
|
<p class="rebilly-instruments-bump-offer-line-item-synopsis-title">
|
|
32
39
|
${item.name}
|
|
33
40
|
</p>
|
|
34
|
-
${rif(
|
|
41
|
+
${rif(
|
|
42
|
+
item.description,
|
|
43
|
+
`
|
|
35
44
|
<p class="rebilly-instruments-bump-offer-line-item-synopsis-description">
|
|
36
45
|
${item.description}
|
|
37
46
|
</p>
|
|
38
|
-
|
|
47
|
+
`,
|
|
48
|
+
)}
|
|
39
49
|
</div>
|
|
40
50
|
`;
|
|
41
51
|
|
|
42
|
-
|
|
52
|
+
const breakdown = (item) => `
|
|
43
53
|
<div class="rebilly-instruments-bump-offer-line-item-price-breakdown">
|
|
44
|
-
${rif(
|
|
54
|
+
${rif(
|
|
55
|
+
item.quantity,
|
|
56
|
+
`
|
|
45
57
|
<p class="rebilly-instruments-bump-offer-line-item-price-breakdown-quantity">
|
|
46
58
|
${item.quantity}
|
|
47
59
|
</p>
|
|
48
60
|
<svg class="rebilly-instruments-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
49
61
|
<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"/>
|
|
50
62
|
</svg>
|
|
51
|
-
|
|
63
|
+
`,
|
|
64
|
+
)}
|
|
52
65
|
<p class="rebilly-instruments-bump-offer-line-item-price-breakdown-unit-price">
|
|
53
66
|
${item.unitPrice}
|
|
54
67
|
</p>
|
|
55
68
|
<div>
|
|
56
69
|
`;
|
|
57
70
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
const line = {
|
|
72
|
+
...offer,
|
|
73
|
+
quantity: plan.pricing.isBracket ? null : offer.quantity,
|
|
74
|
+
name: product.name,
|
|
75
|
+
description: plan.name,
|
|
76
|
+
unitPrice: unitPrice(),
|
|
77
|
+
};
|
|
65
78
|
|
|
66
|
-
|
|
79
|
+
return `
|
|
67
80
|
<div class="rebilly-instruments-bump-offer-line-item">
|
|
68
81
|
${thumbnail(line)}
|
|
69
82
|
${synopsis(line)}
|
|
70
83
|
${breakdown(line)}
|
|
71
84
|
</div>
|
|
72
|
-
|
|
85
|
+
`;
|
|
73
86
|
}
|
|
74
87
|
|
|
75
|
-
export function mountBumpOffer
|
|
76
|
-
|
|
88
|
+
export function mountBumpOffer({ container }) {
|
|
89
|
+
container.insertAdjacentHTML(
|
|
90
|
+
'beforeEnd',
|
|
91
|
+
`
|
|
77
92
|
<label for="rebilly-instruments-bump-offer" class="rebilly-instruments-form-field-checkbox">
|
|
78
93
|
<div class="rebilly-instruments-bump-offer-label" data-rebilly-i18n="form.bumpOffer.title">
|
|
79
94
|
${state.translate.getTranslation('form.bumpOffer.title')}
|
|
@@ -84,21 +99,22 @@ export function mountBumpOffer ({container}) {
|
|
|
84
99
|
/>
|
|
85
100
|
<span></span>
|
|
86
101
|
</label>
|
|
87
|
-
|
|
102
|
+
`,
|
|
103
|
+
);
|
|
88
104
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
105
|
+
const checkbox = document.getElementById('rebilly-instruments-bump-offer');
|
|
106
|
+
checkbox.addEventListener('click', async () => {
|
|
107
|
+
state.data.acceptBumpOffer = checkbox.checked;
|
|
108
|
+
await fetchSummary();
|
|
109
|
+
state.updateModel();
|
|
110
|
+
});
|
|
95
111
|
|
|
96
|
-
|
|
112
|
+
checkbox.checked = state.data.acceptBumpOffer;
|
|
97
113
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
114
|
+
state.options.bumpOffer.forEach((offer) => {
|
|
115
|
+
const node = document.createElement('div');
|
|
116
|
+
node.classList.add('rebilly-instruments-bump-offer');
|
|
117
|
+
node.insertAdjacentHTML('beforeEnd', lineItem({ offer }));
|
|
118
|
+
container.appendChild(node);
|
|
119
|
+
});
|
|
120
|
+
}
|