@rebilly/instruments 4.8.0 → 4.8.2
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/CHANGELOG.md +14 -0
- package/dist/index.js +3 -3
- package/dist/index.min.js +3 -3
- package/package.json +5 -1
- package/.babelrc +0 -26
- package/project.json +0 -31
- package/rollup.config.mjs +0 -79
- package/src/data/options-schema/index.js +0 -112
- package/src/data/options-schema/schemas/options-schema.js +0 -448
- package/src/events/base-event.js +0 -47
- package/src/events/events.spec.js +0 -11
- package/src/events/index.js +0 -15
- package/src/functions/destroy.js +0 -29
- package/src/functions/destroy.spec.js +0 -63
- package/src/functions/mount/fetch-data.js +0 -234
- package/src/functions/mount/fetch-data.spec.js +0 -317
- package/src/functions/mount/get-lead-source-data.js +0 -46
- package/src/functions/mount/get-lead-source-data.spec.js +0 -38
- package/src/functions/mount/index.js +0 -105
- package/src/functions/mount/mount.spec.js +0 -96
- package/src/functions/mount/setup-element.js +0 -29
- package/src/functions/mount/setup-framepay-theme.js +0 -104
- package/src/functions/mount/setup-framepay.js +0 -26
- package/src/functions/mount/setup-i18n.js +0 -21
- package/src/functions/mount/setup-options.js +0 -100
- package/src/functions/mount/setup-options.spec.js +0 -353
- package/src/functions/mount/setup-storefront.js +0 -23
- package/src/functions/mount/setup-styles-vars.js +0 -30
- package/src/functions/mount/setup-user-flow.js +0 -60
- package/src/functions/on.js +0 -22
- package/src/functions/on.spec.js +0 -75
- package/src/functions/purchase.js +0 -173
- package/src/functions/purchase.spec.js +0 -80
- package/src/functions/setup.js +0 -66
- package/src/functions/setup.spec.js +0 -111
- package/src/functions/show.js +0 -30
- package/src/functions/show.spec.js +0 -62
- package/src/functions/update.js +0 -40
- package/src/functions/update.spec.js +0 -104
- package/src/i18n/en.json +0 -35
- package/src/i18n/es.json +0 -32
- package/src/i18n/i18n.spec.js +0 -27
- package/src/i18n/index.js +0 -59
- package/src/index.js +0 -3
- package/src/instance.js +0 -48
- package/src/instance.spec.js +0 -44
- package/src/loader/index.js +0 -145
- package/src/loader/loader.spec.js +0 -74
- package/src/state/iframes.js +0 -23
- package/src/state/index.js +0 -64
- package/src/storefront/account-and-website.js +0 -18
- package/src/storefront/account-and-website.spec.js +0 -73
- package/src/storefront/deposit-requests.js +0 -12
- package/src/storefront/fetch-plans-from-addons-bumpOffer.js +0 -30
- package/src/storefront/fetch-products-from-plans.js +0 -59
- package/src/storefront/fetch-products-from-plans.spec.js +0 -113
- package/src/storefront/index.js +0 -78
- package/src/storefront/invoices.js +0 -23
- package/src/storefront/invoices.spec.js +0 -92
- package/src/storefront/models/account-model.js +0 -36
- package/src/storefront/models/base-model.js +0 -7
- package/src/storefront/models/deposit-request-model.js +0 -24
- package/src/storefront/models/invoice-model.js +0 -20
- package/src/storefront/models/payment-metadata.js +0 -7
- package/src/storefront/models/plan-model.js +0 -94
- package/src/storefront/models/product-model.js +0 -3
- package/src/storefront/models/ready-to-pay-model.js +0 -76
- package/src/storefront/models/summary-model.js +0 -56
- package/src/storefront/models/transaction-model.js +0 -16
- package/src/storefront/models/website-model.js +0 -3
- package/src/storefront/payment-instruments.js +0 -47
- package/src/storefront/payment-instruments.spec.js +0 -88
- package/src/storefront/purchase.js +0 -60
- package/src/storefront/purchase.spec.js +0 -53
- package/src/storefront/ready-to-pay.js +0 -96
- package/src/storefront/ready-to-pay.spec.js +0 -80
- package/src/storefront/storefront.spec.js +0 -14
- package/src/storefront/summary.js +0 -114
- package/src/storefront/summary.spec.js +0 -136
- package/src/storefront/transactions.js +0 -12
- package/src/style/base/__snapshots__/theme.spec.js.snap +0 -143
- package/src/style/base/default-theme.js +0 -955
- package/src/style/base/index.js +0 -688
- package/src/style/base/theme.js +0 -30
- package/src/style/base/theme.spec.js +0 -19
- package/src/style/index.js +0 -11
- package/src/style/utils/border.js +0 -47
- package/src/style/utils/color-values.js +0 -35
- package/src/style/utils/minifyCss.js +0 -14
- package/src/utils/add-dom-element.js +0 -17
- package/src/utils/format-currency.js +0 -8
- package/src/utils/has-valid-css-selector.js +0 -4
- package/src/utils/index.js +0 -15
- package/src/utils/is-dom-element.js +0 -3
- package/src/utils/process-property-as-dom-element.js +0 -31
- package/src/utils/quantity.js +0 -47
- package/src/utils/sleep.js +0 -5
- package/src/views/amount-selector.js +0 -48
- package/src/views/common/iframe/base-iframe.js +0 -66
- package/src/views/common/iframe/events/change-iframe-src-handler.js +0 -6
- package/src/views/common/iframe/events/dispatch-event-handler.js +0 -8
- package/src/views/common/iframe/events/resize-component-handler.js +0 -9
- package/src/views/common/iframe/events/show-error-handler.js +0 -5
- package/src/views/common/iframe/events/stop-loader-handler.js +0 -9
- package/src/views/common/iframe/events/update-addons-handler.js +0 -23
- package/src/views/common/iframe/events/update-coupons-handler.js +0 -12
- package/src/views/common/iframe/events/update-items-handler.js +0 -34
- package/src/views/common/iframe/index.js +0 -5
- package/src/views/common/iframe/modal-iframe.js +0 -82
- package/src/views/common/iframe/view-iframe.js +0 -23
- package/src/views/common/render-utilities.js +0 -4
- package/src/views/confirmation.js +0 -45
- package/src/views/errors.js +0 -115
- package/src/views/form.js +0 -61
- package/src/views/method-selector/__snapshots__/method-selector.spec.js.snap +0 -135
- package/src/views/method-selector/express-methods.js +0 -52
- package/src/views/method-selector/generate-digital-wallet.js +0 -53
- package/src/views/method-selector/generate-digital-wallet.spec.js +0 -121
- package/src/views/method-selector/generate-framepay-config.js +0 -56
- package/src/views/method-selector/generate-framepay-config.spec.js +0 -216
- package/src/views/method-selector/get-method-data.js +0 -11
- package/src/views/method-selector/get-payment-methods.js +0 -25
- package/src/views/method-selector/get-payment-methods.spec.js +0 -41
- package/src/views/method-selector/index.js +0 -223
- package/src/views/method-selector/method-selector.spec.js +0 -20
- package/src/views/method-selector/mount-bump-offer.js +0 -120
- package/src/views/method-selector/mount-express-methods.js +0 -107
- package/src/views/modal.js +0 -103
- package/src/views/result.js +0 -24
- package/src/views/summary.js +0 -38
- package/tests/async-utilities.js +0 -22
- package/tests/mocks/framepay-mock.js +0 -15
- package/tests/mocks/rebilly-api-mock.js +0 -11
- package/tests/mocks/rebilly-instruments-mock.js +0 -141
- package/tests/mocks/storefront-api-mock.js +0 -62
- package/tests/mocks/storefront-mock.js +0 -20
- package/tests/msw/server.js +0 -14
- package/tests/setup-test.js +0 -30
- package/vitest.config.js +0 -18
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import { collectData } from '@rebilly/risk-data-collector';
|
|
2
|
-
import state from '../../state';
|
|
3
|
-
import { fetchProductsFromPlans } from '../../storefront/fetch-products-from-plans';
|
|
4
|
-
import { fetchPlansFromAddonsBumpOffer } from '../../storefront/fetch-plans-from-addons-bumpOffer';
|
|
5
|
-
import { fetchReadyToPay } from '../../storefront/ready-to-pay';
|
|
6
|
-
import { fetchSummary } from '../../storefront/summary';
|
|
7
|
-
import { fetchInvoiceAndProducts as FetchInvoiceAndProducts } from '../../storefront/invoices';
|
|
8
|
-
import { fetchTransaction as FetchTransaction } from '../../storefront/transactions';
|
|
9
|
-
import { fetchAccountAndWebsite as FetchAccountAndWebsite } from '../../storefront/account-and-website';
|
|
10
|
-
import { fetchPaymentInstrument as FetchInstruments } from '../../storefront/payment-instruments';
|
|
11
|
-
import { fetchDepositRequest as FetchDepositRequest } from '../../storefront/deposit-requests';
|
|
12
|
-
import DepositRequestModel from '../../storefront/models/deposit-request-model';
|
|
13
|
-
import { getLeadSourceData } from './get-lead-source-data';
|
|
14
|
-
|
|
15
|
-
export class DataInstance {
|
|
16
|
-
constructor({ ...fields } = {}) {
|
|
17
|
-
Object.entries({
|
|
18
|
-
...(state.data || {}),
|
|
19
|
-
...fields,
|
|
20
|
-
}).forEach(([key, value]) => {
|
|
21
|
-
this[key] = value;
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
this.money = state.options?.money || null;
|
|
25
|
-
this.couponIds = [];
|
|
26
|
-
this.addons = [];
|
|
27
|
-
this.acceptBumpOffer = false;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get amountAndCurrency() {
|
|
31
|
-
let currency;
|
|
32
|
-
let amount;
|
|
33
|
-
let amountDue;
|
|
34
|
-
|
|
35
|
-
if (this.previewPurchase) {
|
|
36
|
-
currency = this.previewPurchase.currency;
|
|
37
|
-
amount = this.previewPurchase.total;
|
|
38
|
-
} else if (this.invoice) {
|
|
39
|
-
currency = this.invoice.currency;
|
|
40
|
-
amount = this.invoice.amount;
|
|
41
|
-
amountDue = this.invoice.amountDue;
|
|
42
|
-
} else if (this.transaction) {
|
|
43
|
-
currency = this.transaction.currency;
|
|
44
|
-
amount = this.transaction.amount;
|
|
45
|
-
} else if (this.money) {
|
|
46
|
-
currency = this.money.currency;
|
|
47
|
-
amount = this.money.amount;
|
|
48
|
-
}
|
|
49
|
-
const amountAndCurrency = {
|
|
50
|
-
amount,
|
|
51
|
-
currency,
|
|
52
|
-
};
|
|
53
|
-
if (amountDue) {
|
|
54
|
-
amountAndCurrency.amountDue = amountDue;
|
|
55
|
-
}
|
|
56
|
-
return amountAndCurrency;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
get isPayment() {
|
|
60
|
-
return this.invoice || this.transaction || this.money;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
get isPurchase() {
|
|
64
|
-
return this.previewPurchase;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
get hasAmountDue() {
|
|
68
|
-
return !!(
|
|
69
|
-
this.amountAndCurrency.amountDue &&
|
|
70
|
-
this.amountAndCurrency.amountDue !== this.amountAndCurrency.amount
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
get summaryItems() {
|
|
75
|
-
const {
|
|
76
|
-
discountsAmount = null,
|
|
77
|
-
shippingAmount = null,
|
|
78
|
-
subtotalAmount = null,
|
|
79
|
-
taxAmount = null,
|
|
80
|
-
} = this.previewPurchase || this.invoice || {};
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
discountsAmount,
|
|
84
|
-
shippingAmount,
|
|
85
|
-
subtotalAmount,
|
|
86
|
-
taxAmount,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
get summaryLineItems() {
|
|
91
|
-
let lineItems = [];
|
|
92
|
-
if (this.invoice) {
|
|
93
|
-
({ items: lineItems = [] } = this.invoice);
|
|
94
|
-
} else {
|
|
95
|
-
({ lineItems = [] } = this.previewPurchase || {});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return lineItems;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
get isShippingRequired() {
|
|
102
|
-
return (this.products || []).some(
|
|
103
|
-
(product) => product.requiresShipping,
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
toPostmatesModel() {
|
|
108
|
-
return JSON.parse(
|
|
109
|
-
JSON.stringify({
|
|
110
|
-
...this,
|
|
111
|
-
amountAndCurrency: this.amountAndCurrency,
|
|
112
|
-
isPayment: this.isPayment,
|
|
113
|
-
isPurchase: this.isPurchase,
|
|
114
|
-
hasAmountDue: this.hasAmountDue,
|
|
115
|
-
summaryItems: this.summaryItems,
|
|
116
|
-
summaryLineItems: this.summaryLineItems,
|
|
117
|
-
isShippingRequired: this.isShippingRequired,
|
|
118
|
-
leadSource: getLeadSourceData(),
|
|
119
|
-
}),
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export async function fetchData({
|
|
125
|
-
riskMetadata = null,
|
|
126
|
-
|
|
127
|
-
// Dependency injectable functions
|
|
128
|
-
fetchInvoiceAndProducts = FetchInvoiceAndProducts,
|
|
129
|
-
fetchTransaction = FetchTransaction,
|
|
130
|
-
fetchAccountAndWebsite = FetchAccountAndWebsite,
|
|
131
|
-
fetchInstruments = FetchInstruments,
|
|
132
|
-
fetchDepositRequest = FetchDepositRequest,
|
|
133
|
-
} = {}) {
|
|
134
|
-
try {
|
|
135
|
-
state.data = new DataInstance();
|
|
136
|
-
|
|
137
|
-
if (state.options?.deposit) {
|
|
138
|
-
if (state.options.deposit.depositRequestId) {
|
|
139
|
-
state.data.deposit = await fetchDepositRequest({
|
|
140
|
-
data: {
|
|
141
|
-
id: state.options.deposit.depositRequestId,
|
|
142
|
-
},
|
|
143
|
-
});
|
|
144
|
-
} else {
|
|
145
|
-
state.data.deposit = new DepositRequestModel(
|
|
146
|
-
state.options.deposit,
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
let readyToPayPromise = Promise.resolve(null);
|
|
152
|
-
|
|
153
|
-
let availableInstrumentsPromise = null;
|
|
154
|
-
if (state.options?.jwt) {
|
|
155
|
-
fetchAccountAndWebsite({ state }).then(({ account, website }) => {
|
|
156
|
-
state.data.account = account;
|
|
157
|
-
state.data.website = website;
|
|
158
|
-
});
|
|
159
|
-
readyToPayPromise = fetchReadyToPay({ riskMetadata });
|
|
160
|
-
availableInstrumentsPromise = fetchInstruments({ state });
|
|
161
|
-
} else {
|
|
162
|
-
readyToPayPromise = fetchReadyToPay({ riskMetadata });
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (state.options?.transactionId) {
|
|
166
|
-
state.data.transaction = await fetchTransaction({
|
|
167
|
-
data: {
|
|
168
|
-
id: state.options.transactionId,
|
|
169
|
-
},
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
let productsPromise;
|
|
174
|
-
const invoiceId =
|
|
175
|
-
state.options?.invoiceId || state.data?.transaction?.invoiceId;
|
|
176
|
-
if (invoiceId) {
|
|
177
|
-
const { invoice, products } = await fetchInvoiceAndProducts({
|
|
178
|
-
data: {
|
|
179
|
-
id: invoiceId,
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
productsPromise = Promise.resolve(products);
|
|
183
|
-
state.data.invoice = invoice;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (!riskMetadata) {
|
|
187
|
-
({ riskMetadata } = await collectData());
|
|
188
|
-
state.data.riskMetadata = riskMetadata;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const previewPurchasePromise = state.options.items
|
|
192
|
-
? fetchSummary()
|
|
193
|
-
: null;
|
|
194
|
-
|
|
195
|
-
if (!state.options?.jwt) {
|
|
196
|
-
// There is no invoice, only pla ns through the static options,
|
|
197
|
-
// so we should fetch the products from the provided plan names.
|
|
198
|
-
productsPromise = fetchProductsFromPlans({ state });
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
let plansPromise = new Promise((resolve) => {
|
|
202
|
-
resolve([]);
|
|
203
|
-
});
|
|
204
|
-
if (state.options?.addons || state.options?.bumpOffer) {
|
|
205
|
-
plansPromise = fetchPlansFromAddonsBumpOffer({ state });
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const [
|
|
209
|
-
readyToPay,
|
|
210
|
-
previewPurchase,
|
|
211
|
-
products,
|
|
212
|
-
plans,
|
|
213
|
-
availableInstruments,
|
|
214
|
-
] = await Promise.all([
|
|
215
|
-
readyToPayPromise,
|
|
216
|
-
previewPurchasePromise,
|
|
217
|
-
productsPromise,
|
|
218
|
-
plansPromise,
|
|
219
|
-
availableInstrumentsPromise,
|
|
220
|
-
]);
|
|
221
|
-
|
|
222
|
-
return new DataInstance({
|
|
223
|
-
readyToPay,
|
|
224
|
-
previewPurchase,
|
|
225
|
-
products,
|
|
226
|
-
plans,
|
|
227
|
-
availableInstruments,
|
|
228
|
-
});
|
|
229
|
-
} catch (error) {
|
|
230
|
-
// console.log(error);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return new DataInstance({});
|
|
234
|
-
}
|
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
import { StorefontTestingInstance } from 'tests/mocks/storefront-mock';
|
|
2
|
-
import { fetchData, DataInstance } from './fetch-data';
|
|
3
|
-
import TransactionModel from '@/storefront/models/transaction-model';
|
|
4
|
-
|
|
5
|
-
describe('fetchData function', () => {
|
|
6
|
-
it('Should use correct invoice id for invoiceId', async () => {
|
|
7
|
-
const mockFetchInvoiceAndProducts = vi.fn();
|
|
8
|
-
const invoiceId = 'test-invoice-id';
|
|
9
|
-
StorefontTestingInstance({
|
|
10
|
-
options: {
|
|
11
|
-
invoiceId,
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
await fetchData({
|
|
16
|
-
fetchInvoiceAndProducts: mockFetchInvoiceAndProducts,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
expect(mockFetchInvoiceAndProducts).toBeCalledTimes(1);
|
|
20
|
-
expect(mockFetchInvoiceAndProducts).toBeCalledWith(
|
|
21
|
-
expect.objectContaining({
|
|
22
|
-
data: {
|
|
23
|
-
id: invoiceId,
|
|
24
|
-
},
|
|
25
|
-
}),
|
|
26
|
-
);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('Should use correct invoice id for transaction with invoiceIds', async () => {
|
|
30
|
-
const mockFetchInvoiceAndProducts = vi.fn();
|
|
31
|
-
const invoiceId = 'test-invoice-id';
|
|
32
|
-
StorefontTestingInstance({
|
|
33
|
-
data: {
|
|
34
|
-
transaction: new TransactionModel({
|
|
35
|
-
invoiceIds: [invoiceId],
|
|
36
|
-
}),
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
await fetchData({
|
|
41
|
-
fetchInvoiceAndProducts: mockFetchInvoiceAndProducts,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
expect(mockFetchInvoiceAndProducts).toBeCalledTimes(1);
|
|
45
|
-
expect(mockFetchInvoiceAndProducts).toBeCalledWith(
|
|
46
|
-
expect.objectContaining({
|
|
47
|
-
data: {
|
|
48
|
-
id: invoiceId,
|
|
49
|
-
},
|
|
50
|
-
}),
|
|
51
|
-
);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('Should not fetch invoice for transaction with no invoice Ids', async () => {
|
|
55
|
-
const mockFetchInvoiceAndProducts = vi.fn();
|
|
56
|
-
StorefontTestingInstance({
|
|
57
|
-
options: {},
|
|
58
|
-
data: {
|
|
59
|
-
transaction: new TransactionModel({
|
|
60
|
-
invoiceIds: [],
|
|
61
|
-
}),
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
fetchData({
|
|
66
|
-
fetchInvoiceAndProducts: mockFetchInvoiceAndProducts,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
expect(mockFetchInvoiceAndProducts).toBeCalledTimes(0);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('Should fetch account when JWT is supplied', async () => {
|
|
73
|
-
const mockFetchAccountAndWebsite = vi.fn();
|
|
74
|
-
StorefontTestingInstance({
|
|
75
|
-
options: {
|
|
76
|
-
jwt: 'TEST_JWT',
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
await fetchData({
|
|
81
|
-
fetchAccountAndWebsite: mockFetchAccountAndWebsite,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
expect(mockFetchAccountAndWebsite).toBeCalledTimes(1);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('Should not fetch account when there JWT is not supplied', async () => {
|
|
88
|
-
const mockFetchAccountAndWebsite = vi.fn();
|
|
89
|
-
StorefontTestingInstance({
|
|
90
|
-
options: {},
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
await fetchData({
|
|
94
|
-
fetchAccountAndWebsite: mockFetchAccountAndWebsite,
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
expect(mockFetchAccountAndWebsite).toBeCalledTimes(0);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe('DataInstance', () => {
|
|
102
|
-
describe('Determining amountAndCurrency', () => {
|
|
103
|
-
it('should use money option', () => {
|
|
104
|
-
const expectedAmountAndCurrency = {
|
|
105
|
-
amount: 10,
|
|
106
|
-
currency: 'USD',
|
|
107
|
-
};
|
|
108
|
-
StorefontTestingInstance({
|
|
109
|
-
options: {
|
|
110
|
-
money: expectedAmountAndCurrency,
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
const fetchedData = new DataInstance();
|
|
114
|
-
|
|
115
|
-
expect(fetchedData.amountAndCurrency).toEqual(
|
|
116
|
-
expectedAmountAndCurrency,
|
|
117
|
-
);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('should use preview Purchase', () => {
|
|
121
|
-
const expectedAmountAndCurrency = {
|
|
122
|
-
amount: 10,
|
|
123
|
-
currency: 'USD',
|
|
124
|
-
};
|
|
125
|
-
StorefontTestingInstance();
|
|
126
|
-
|
|
127
|
-
const fetchedData = new DataInstance({
|
|
128
|
-
previewPurchase: {
|
|
129
|
-
total: expectedAmountAndCurrency.amount,
|
|
130
|
-
currency: expectedAmountAndCurrency.currency,
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
expect(fetchedData.amountAndCurrency).toEqual(
|
|
134
|
-
expect.objectContaining(expectedAmountAndCurrency),
|
|
135
|
-
);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('should use invoice', () => {
|
|
139
|
-
const expectedAmountAndCurrency = {
|
|
140
|
-
amount: 10,
|
|
141
|
-
currency: 'USD',
|
|
142
|
-
};
|
|
143
|
-
StorefontTestingInstance();
|
|
144
|
-
|
|
145
|
-
const fetchedData = new DataInstance({
|
|
146
|
-
invoice: {
|
|
147
|
-
...expectedAmountAndCurrency,
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
expect(fetchedData.amountAndCurrency).toEqual(
|
|
151
|
-
expect.objectContaining(expectedAmountAndCurrency),
|
|
152
|
-
);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('should use transaction', () => {
|
|
156
|
-
const expectedAmountAndCurrency = {
|
|
157
|
-
amount: 10,
|
|
158
|
-
currency: 'USD',
|
|
159
|
-
};
|
|
160
|
-
StorefontTestingInstance();
|
|
161
|
-
|
|
162
|
-
const fetchedData = new DataInstance({
|
|
163
|
-
transaction: {
|
|
164
|
-
...expectedAmountAndCurrency,
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
expect(fetchedData.amountAndCurrency).toEqual(
|
|
168
|
-
expect.objectContaining(expectedAmountAndCurrency),
|
|
169
|
-
);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('should handle empty value', () => {
|
|
173
|
-
StorefontTestingInstance();
|
|
174
|
-
|
|
175
|
-
const fetchedData = new DataInstance();
|
|
176
|
-
expect(fetchedData.amountAndCurrency).toEqual(
|
|
177
|
-
expect.objectContaining({
|
|
178
|
-
amount: undefined,
|
|
179
|
-
currency: undefined,
|
|
180
|
-
}),
|
|
181
|
-
);
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
describe('isPayment', () => {
|
|
186
|
-
it('money is truthy', () => {
|
|
187
|
-
StorefontTestingInstance({
|
|
188
|
-
options: {
|
|
189
|
-
money: true,
|
|
190
|
-
},
|
|
191
|
-
});
|
|
192
|
-
const fetchedData = new DataInstance();
|
|
193
|
-
expect(fetchedData.isPayment).toBeTruthy();
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it('invoice is truthy', () => {
|
|
197
|
-
StorefontTestingInstance();
|
|
198
|
-
const fetchedData = new DataInstance({
|
|
199
|
-
invoice: true,
|
|
200
|
-
});
|
|
201
|
-
expect(fetchedData.isPayment).toBeTruthy();
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('transaction is truthy', () => {
|
|
205
|
-
StorefontTestingInstance();
|
|
206
|
-
const fetchedData = new DataInstance({
|
|
207
|
-
transaction: true,
|
|
208
|
-
});
|
|
209
|
-
expect(fetchedData.isPayment).toBeTruthy();
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it('previewPurchase is falsy', () => {
|
|
213
|
-
StorefontTestingInstance();
|
|
214
|
-
const fetchedData = new DataInstance({
|
|
215
|
-
previewPurchase: true,
|
|
216
|
-
});
|
|
217
|
-
expect(fetchedData.isPayment).toBeFalsy();
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it('empty is falsy', () => {
|
|
221
|
-
StorefontTestingInstance();
|
|
222
|
-
const fetchedData = new DataInstance({});
|
|
223
|
-
expect(fetchedData.isPayment).toBeFalsy();
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
describe('isPurchase', () => {
|
|
228
|
-
it('previewPurchase is truthy', () => {
|
|
229
|
-
StorefontTestingInstance();
|
|
230
|
-
const fetchedData = new DataInstance({
|
|
231
|
-
previewPurchase: true,
|
|
232
|
-
});
|
|
233
|
-
expect(fetchedData.isPurchase).toBeTruthy();
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
it('money is falsy', () => {
|
|
237
|
-
StorefontTestingInstance({
|
|
238
|
-
options: {
|
|
239
|
-
money: true,
|
|
240
|
-
},
|
|
241
|
-
});
|
|
242
|
-
const fetchedData = new DataInstance();
|
|
243
|
-
expect(fetchedData.isPurchase).toBeFalsy();
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it('invoice is falsy', () => {
|
|
247
|
-
StorefontTestingInstance();
|
|
248
|
-
const fetchedData = new DataInstance({
|
|
249
|
-
invoice: true,
|
|
250
|
-
});
|
|
251
|
-
expect(fetchedData.isPurchase).toBeFalsy();
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('transaction is falsy', () => {
|
|
255
|
-
StorefontTestingInstance();
|
|
256
|
-
const fetchedData = new DataInstance({
|
|
257
|
-
transaction: true,
|
|
258
|
-
});
|
|
259
|
-
expect(fetchedData.isPurchase).toBeFalsy();
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it('empty is falsy', () => {
|
|
263
|
-
StorefontTestingInstance();
|
|
264
|
-
const fetchedData = new DataInstance({});
|
|
265
|
-
expect(fetchedData.isPurchase).toBeFalsy();
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it('Should get summaryItems', () => {
|
|
270
|
-
const expectedSummaryItems = {
|
|
271
|
-
discountsAmount: 1,
|
|
272
|
-
shippingAmount: 2,
|
|
273
|
-
subtotalAmount: 3,
|
|
274
|
-
taxAmount: 4,
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
let fetchedData = new DataInstance({
|
|
278
|
-
previewPurchase: {
|
|
279
|
-
...expectedSummaryItems,
|
|
280
|
-
},
|
|
281
|
-
});
|
|
282
|
-
expect(fetchedData.summaryItems).toEqual(
|
|
283
|
-
expect.objectContaining(expectedSummaryItems),
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
fetchedData = new DataInstance({
|
|
287
|
-
invoice: {
|
|
288
|
-
...expectedSummaryItems,
|
|
289
|
-
},
|
|
290
|
-
});
|
|
291
|
-
expect(fetchedData.summaryItems).toEqual(
|
|
292
|
-
expect.objectContaining(expectedSummaryItems),
|
|
293
|
-
);
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
it('Should get summaryLineItems', () => {
|
|
297
|
-
const expectedSummaryLineItems = [
|
|
298
|
-
{
|
|
299
|
-
line: 'item',
|
|
300
|
-
},
|
|
301
|
-
];
|
|
302
|
-
|
|
303
|
-
let fetchedData = new DataInstance({
|
|
304
|
-
previewPurchase: {
|
|
305
|
-
lineItems: expectedSummaryLineItems,
|
|
306
|
-
},
|
|
307
|
-
});
|
|
308
|
-
expect(fetchedData.summaryLineItems).toEqual(expectedSummaryLineItems);
|
|
309
|
-
|
|
310
|
-
fetchedData = new DataInstance({
|
|
311
|
-
invoice: {
|
|
312
|
-
items: expectedSummaryLineItems,
|
|
313
|
-
},
|
|
314
|
-
});
|
|
315
|
-
expect(fetchedData.summaryLineItems).toEqual(expectedSummaryLineItems);
|
|
316
|
-
});
|
|
317
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const collectedProperties = [
|
|
2
|
-
// Google UTM fields
|
|
3
|
-
'utm_source',
|
|
4
|
-
'utm_medium',
|
|
5
|
-
'utm_campaign',
|
|
6
|
-
'utm_term',
|
|
7
|
-
'utm_content',
|
|
8
|
-
// FramePay specific fields
|
|
9
|
-
'affiliate',
|
|
10
|
-
'subAffiliate',
|
|
11
|
-
'clickId',
|
|
12
|
-
'salesAgent',
|
|
13
|
-
];
|
|
14
|
-
const prefix = /utm_/g;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Generates the lead source data object that framepay expects as part of
|
|
18
|
-
* the extraData property. We generate it in the top level of instruments
|
|
19
|
-
* so that it has the correct path and query parameters.
|
|
20
|
-
* @returns {Object} The lead source data object
|
|
21
|
-
*/
|
|
22
|
-
export const getLeadSourceData = () => {
|
|
23
|
-
const { href, origin, pathname, search } = window.location;
|
|
24
|
-
|
|
25
|
-
const leadSource = {
|
|
26
|
-
// Large query parameters including JWTs will cause issues, so make sure we dont
|
|
27
|
-
// use anything longer than 255 characters.
|
|
28
|
-
path: href.length <= 255 ? href : `${origin}${pathname}`,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const query = search.replace('?', '');
|
|
32
|
-
|
|
33
|
-
// Process query parameters and add them to the leadSource object
|
|
34
|
-
return query
|
|
35
|
-
.split('&')
|
|
36
|
-
.map((field) => field.split('='))
|
|
37
|
-
.filter((field) => {
|
|
38
|
-
const [name] = field;
|
|
39
|
-
return collectedProperties.indexOf(name) > -1;
|
|
40
|
-
})
|
|
41
|
-
.reduce((data, field) => {
|
|
42
|
-
const [name, value = null] = field;
|
|
43
|
-
data[name.replace(prefix, '')] = value;
|
|
44
|
-
return data;
|
|
45
|
-
}, leadSource);
|
|
46
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { getLeadSourceData } from './get-lead-source-data';
|
|
2
|
-
|
|
3
|
-
export const mockLocation = (url) => {
|
|
4
|
-
const location = new URL(url);
|
|
5
|
-
delete window.location;
|
|
6
|
-
window.location = location;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
describe('getLeadSourceData', () => {
|
|
10
|
-
it('should return an object with a path property that matches the current URL', () => {
|
|
11
|
-
const result = getLeadSourceData();
|
|
12
|
-
expect(result.path).toBe(window.location.href);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should return the path without the query if the query is longer than 255 characters', () => {
|
|
16
|
-
const query = Array(300).fill('a').join('');
|
|
17
|
-
|
|
18
|
-
const pathWithoutQuery = 'http://www.example.com/path';
|
|
19
|
-
mockLocation(`${pathWithoutQuery}?${query}`);
|
|
20
|
-
|
|
21
|
-
const result = getLeadSourceData();
|
|
22
|
-
expect(result.path).toBe(pathWithoutQuery);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should add the query parameters to the returned object', () => {
|
|
26
|
-
const query = 'utm_source=google&utm_medium=cpc&utm_campaign=example';
|
|
27
|
-
mockLocation(`http://www.example.com/path?${query}`);
|
|
28
|
-
|
|
29
|
-
expect(getLeadSourceData()).toMatchInlineSnapshot(`
|
|
30
|
-
{
|
|
31
|
-
"campaign": "example",
|
|
32
|
-
"medium": "cpc",
|
|
33
|
-
"path": "http://www.example.com/path?utm_source=google&utm_medium=cpc&utm_campaign=example",
|
|
34
|
-
"source": "google",
|
|
35
|
-
}
|
|
36
|
-
`);
|
|
37
|
-
});
|
|
38
|
-
});
|