@rebilly/instruments 4.8.1 → 4.8.3
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 +1 -1
- package/dist/index.min.js +1 -1
- package/package.json +21 -19
- 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 -236
- 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 -76
- 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 -46
- 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,30 +0,0 @@
|
|
|
1
|
-
import PlanModel from './models/plan-model';
|
|
2
|
-
import { Endpoint } from './index';
|
|
3
|
-
import state from '../state';
|
|
4
|
-
|
|
5
|
-
export async function fetchPlansFromAddonsBumpOffer() {
|
|
6
|
-
return Endpoint(async () => {
|
|
7
|
-
let ids = [];
|
|
8
|
-
|
|
9
|
-
if (state.options?.addons) {
|
|
10
|
-
ids = ids.concat(state.options.addons.map((item) => item.planId));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (state.options?.bumpOffer) {
|
|
14
|
-
ids = ids.concat(
|
|
15
|
-
state.options.bumpOffer.map((item) => item.planId),
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (ids.length > 0) {
|
|
20
|
-
const { items: planItems } = await state.storefront.plans.getAll({
|
|
21
|
-
filter: `id:${ids.join(',')}`,
|
|
22
|
-
});
|
|
23
|
-
return planItems.map(({ fields }) =>
|
|
24
|
-
new PlanModel(fields).toPayload(),
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return [];
|
|
29
|
-
});
|
|
30
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import ProductModel from './models/product-model';
|
|
2
|
-
import { Endpoint } from './index';
|
|
3
|
-
import state from '../state';
|
|
4
|
-
|
|
5
|
-
export async function fetchProductsFromPlans() {
|
|
6
|
-
return Endpoint(async () => {
|
|
7
|
-
let lineItems = state.data.summaryLineItems;
|
|
8
|
-
if (lineItems.length === 0) {
|
|
9
|
-
lineItems = state.options?.items ?? [];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const filterByPlanId = {
|
|
13
|
-
filter: '',
|
|
14
|
-
expand: 'product',
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
if (lineItems.length) {
|
|
18
|
-
let ids = lineItems.map((item) => item.planId);
|
|
19
|
-
|
|
20
|
-
if (state.options?.addons) {
|
|
21
|
-
ids = ids.concat(
|
|
22
|
-
state.options.addons.map((item) => item.planId),
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (state.options?.bumpOffer) {
|
|
27
|
-
ids = ids.concat(
|
|
28
|
-
state.options.bumpOffer.map((item) => item.planId),
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
filterByPlanId.filter = `id:${[...new Set(ids)].join(',')}`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Only fetch plans if we have specific plans to fetch
|
|
36
|
-
if (filterByPlanId.filter.length) {
|
|
37
|
-
try {
|
|
38
|
-
const { items: planItems } =
|
|
39
|
-
await state.storefront.plans.getAll(filterByPlanId);
|
|
40
|
-
|
|
41
|
-
const products = [];
|
|
42
|
-
planItems
|
|
43
|
-
.map(
|
|
44
|
-
({ fields }) =>
|
|
45
|
-
new ProductModel(fields._embedded.product),
|
|
46
|
-
)
|
|
47
|
-
.forEach((product) => {
|
|
48
|
-
if (products.every((item) => item.id !== product.id)) {
|
|
49
|
-
products.push(product);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return products;
|
|
53
|
-
} catch (e) {
|
|
54
|
-
// Ignore and return empty items
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return [];
|
|
58
|
-
});
|
|
59
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { StorefontTestingInstance } from 'tests/mocks/storefront-mock';
|
|
2
|
-
import { ok, get } from 'msw-when-then';
|
|
3
|
-
import { when } from 'tests/msw/server';
|
|
4
|
-
import { storefrontURL } from 'tests/mocks/storefront-api-mock';
|
|
5
|
-
import { fetchProductsFromPlans } from './fetch-products-from-plans';
|
|
6
|
-
import ProductModel from './models/product-model';
|
|
7
|
-
import { expectConfigurationError } from 'tests/async-utilities';
|
|
8
|
-
|
|
9
|
-
describe('Storefront API Plan', () => {
|
|
10
|
-
it('can fetch products from a single plan', async () => {
|
|
11
|
-
const testPlan = {
|
|
12
|
-
name: 'Test Plan',
|
|
13
|
-
id: 'test-plan-id-1',
|
|
14
|
-
_embedded: {
|
|
15
|
-
product: {
|
|
16
|
-
id: 'test-product-id',
|
|
17
|
-
requiresShipping: true,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
when(get(`${storefrontURL}/plans`)).thenReturn(ok([testPlan]));
|
|
23
|
-
|
|
24
|
-
const instance = new StorefontTestingInstance({
|
|
25
|
-
options: {
|
|
26
|
-
items: [
|
|
27
|
-
{
|
|
28
|
-
planId: 'test-plan-id-1',
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
vi.spyOn(instance.storefront.plans, 'getAll');
|
|
35
|
-
|
|
36
|
-
const products = await fetchProductsFromPlans({
|
|
37
|
-
state: instance,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
expect(instance.storefront.plans.getAll).toBeCalledTimes(1);
|
|
41
|
-
expect(instance.storefront.plans.getAll).toBeCalledWith({
|
|
42
|
-
filter: 'id:test-plan-id-1',
|
|
43
|
-
expand: 'product',
|
|
44
|
-
});
|
|
45
|
-
expect(products).toEqual([
|
|
46
|
-
new ProductModel(testPlan._embedded.product),
|
|
47
|
-
]);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('can fetch multiple plans with multiple filters', async () => {
|
|
51
|
-
const testPlans = [
|
|
52
|
-
{
|
|
53
|
-
name: 'Test Plan 1',
|
|
54
|
-
id: 'test-plan-id-1',
|
|
55
|
-
_embedded: {
|
|
56
|
-
product: {
|
|
57
|
-
id: 'test-product-id-1',
|
|
58
|
-
requiresShipping: true,
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
name: 'Test Plan 2',
|
|
64
|
-
id: 'test-plan-id-2',
|
|
65
|
-
_embedded: {
|
|
66
|
-
product: {
|
|
67
|
-
id: 'test-product-id-2',
|
|
68
|
-
requiresShipping: true,
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
];
|
|
73
|
-
when(get(`${storefrontURL}/plans`)).thenReturn(ok(testPlans));
|
|
74
|
-
|
|
75
|
-
const instance = new StorefontTestingInstance({
|
|
76
|
-
options: {
|
|
77
|
-
items: [
|
|
78
|
-
{
|
|
79
|
-
planId: 'test-plan-id-1',
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
planId: 'test-plan-id-2',
|
|
83
|
-
},
|
|
84
|
-
],
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
vi.spyOn(instance.storefront.plans, 'getAll');
|
|
89
|
-
|
|
90
|
-
const products = await fetchProductsFromPlans({
|
|
91
|
-
state: instance,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
expect(instance.storefront.plans.getAll).toBeCalledWith(
|
|
95
|
-
expect.objectContaining({
|
|
96
|
-
filter: 'id:test-plan-id-1,test-plan-id-2',
|
|
97
|
-
}),
|
|
98
|
-
);
|
|
99
|
-
expect(products).toEqual([
|
|
100
|
-
new ProductModel(testPlans[0]._embedded.product),
|
|
101
|
-
new ProductModel(testPlans[1]._embedded.product),
|
|
102
|
-
]);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should throw errors with no options', async () => {
|
|
106
|
-
const noConfigOrOptionsInstance = new StorefontTestingInstance({
|
|
107
|
-
options: null,
|
|
108
|
-
});
|
|
109
|
-
await expectConfigurationError(
|
|
110
|
-
fetchProductsFromPlans({ state: noConfigOrOptionsInstance }),
|
|
111
|
-
);
|
|
112
|
-
});
|
|
113
|
-
});
|
package/src/storefront/index.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import RebillyApi, {
|
|
2
|
-
RebillyStorefrontAPI,
|
|
3
|
-
RebillyExperimentalAPI,
|
|
4
|
-
} from 'rebilly-js-sdk';
|
|
5
|
-
import { showError } from '../views/errors';
|
|
6
|
-
import state from '../state';
|
|
7
|
-
|
|
8
|
-
const TIMEOUT = 60000;
|
|
9
|
-
|
|
10
|
-
export function validateStateForStorefront() {
|
|
11
|
-
if (!state.storefront) {
|
|
12
|
-
throw new Error('Could not access rebilly-js-sdk instance');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (!state.options) {
|
|
16
|
-
throw new Error(
|
|
17
|
-
'Could not use Rebilly Instruments mount options to fetch Rebilly data',
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export async function Endpoint(callback) {
|
|
23
|
-
try {
|
|
24
|
-
validateStateForStorefront({ state });
|
|
25
|
-
return await callback();
|
|
26
|
-
} catch (error) {
|
|
27
|
-
showError(error);
|
|
28
|
-
throw error;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export class StorefrontInstance {
|
|
33
|
-
constructor({
|
|
34
|
-
publishableKey = null,
|
|
35
|
-
jwt = null,
|
|
36
|
-
organizationId = null,
|
|
37
|
-
mode = 'live',
|
|
38
|
-
timeout = TIMEOUT,
|
|
39
|
-
liveUrl = null,
|
|
40
|
-
sandboxUrl = null,
|
|
41
|
-
} = {}) {
|
|
42
|
-
const urls = {
|
|
43
|
-
live: liveUrl || 'https://api.rebilly.com',
|
|
44
|
-
sandbox: sandboxUrl || 'https://api-sandbox.rebilly.com',
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const config = {
|
|
48
|
-
organizationId,
|
|
49
|
-
sandbox: mode === 'sandbox',
|
|
50
|
-
timeout: Number.isNaN(parseInt(timeout, 10))
|
|
51
|
-
? TIMEOUT
|
|
52
|
-
: parseInt(timeout, 10),
|
|
53
|
-
urls,
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const api = RebillyStorefrontAPI(config);
|
|
57
|
-
// TODO: Check why Rollup is making the default as an named export
|
|
58
|
-
const rebilly =
|
|
59
|
-
typeof RebillyApi.default === 'function'
|
|
60
|
-
? RebillyApi.default(config)
|
|
61
|
-
: RebillyApi(config);
|
|
62
|
-
|
|
63
|
-
const experimental = RebillyExperimentalAPI(config);
|
|
64
|
-
|
|
65
|
-
api.setSessionToken(publishableKey || jwt);
|
|
66
|
-
rebilly.setSessionToken(publishableKey || jwt);
|
|
67
|
-
experimental.setSessionToken(publishableKey || jwt);
|
|
68
|
-
|
|
69
|
-
this.api = api;
|
|
70
|
-
this.api.rebilly = rebilly;
|
|
71
|
-
this.api.rebilly.experimental = experimental;
|
|
72
|
-
|
|
73
|
-
// eslint-disable-next-line no-constructor-return
|
|
74
|
-
return this.api;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export default (config = {}) => new StorefrontInstance(config);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import InvoiceModel from './models/invoice-model';
|
|
2
|
-
import ProductModel from './models/product-model';
|
|
3
|
-
import { Endpoint } from './index';
|
|
4
|
-
import state from '../state';
|
|
5
|
-
|
|
6
|
-
export async function fetchInvoiceAndProducts({ data = null }) {
|
|
7
|
-
return Endpoint(async () => {
|
|
8
|
-
state.storefront.setSessionToken(state.options.jwt);
|
|
9
|
-
const { fields } = await state.storefront.invoices.get({
|
|
10
|
-
...data,
|
|
11
|
-
expand: 'items.*.product',
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const products = fields.items
|
|
15
|
-
.filter((item) => item._embedded)
|
|
16
|
-
.map((items) => new ProductModel(items._embedded.product));
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
products,
|
|
20
|
-
invoice: new InvoiceModel(fields),
|
|
21
|
-
};
|
|
22
|
-
});
|
|
23
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { StorefontTestingInstance } from 'tests/mocks/storefront-mock';
|
|
2
|
-
import { ok, get } from 'msw-when-then';
|
|
3
|
-
import { when } from 'tests/msw/server';
|
|
4
|
-
import { storefrontURL } from 'tests/mocks/storefront-api-mock';
|
|
5
|
-
import { fetchInvoiceAndProducts } from './invoices';
|
|
6
|
-
import ProductModel from './models/product-model';
|
|
7
|
-
import InvoiceModel from './models/invoice-model';
|
|
8
|
-
|
|
9
|
-
describe('Storefront Invoices', () => {
|
|
10
|
-
it('can fetch an invoice and its embedded products', async () => {
|
|
11
|
-
const id = '1234';
|
|
12
|
-
const testInvoice = {
|
|
13
|
-
id: 'test-invoice-id-1',
|
|
14
|
-
items: [
|
|
15
|
-
{
|
|
16
|
-
_embedded: {
|
|
17
|
-
product: {
|
|
18
|
-
id: 'test-product-id',
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
when(get(`${storefrontURL}/invoices/${id}`)).thenReturn(
|
|
26
|
-
ok(testInvoice),
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
const instance = new StorefontTestingInstance({
|
|
30
|
-
data: {
|
|
31
|
-
invoice: {
|
|
32
|
-
id,
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
vi.spyOn(instance.storefront.invoices, 'get');
|
|
38
|
-
|
|
39
|
-
const { invoice, products } = await fetchInvoiceAndProducts({
|
|
40
|
-
data: { id },
|
|
41
|
-
state: instance,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
expect(instance.storefront.invoices.get).toBeCalledTimes(1);
|
|
45
|
-
expect(instance.storefront.invoices.get).toBeCalledWith({
|
|
46
|
-
id,
|
|
47
|
-
expand: 'items.*.product',
|
|
48
|
-
});
|
|
49
|
-
expect(invoice).toBeInstanceOf(InvoiceModel);
|
|
50
|
-
expect(products).toBeInstanceOf(Array);
|
|
51
|
-
expect(products[0]).toBeInstanceOf(ProductModel);
|
|
52
|
-
expect(products[0]).toMatchInlineSnapshot(`
|
|
53
|
-
ProductModel {
|
|
54
|
-
"id": "test-product-id",
|
|
55
|
-
}
|
|
56
|
-
`);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('can fetch an invoice when it does not have any products', async () => {
|
|
60
|
-
const id = '1234';
|
|
61
|
-
const testInvoice = {
|
|
62
|
-
id: 'test-invoice-id-1',
|
|
63
|
-
items: [
|
|
64
|
-
{
|
|
65
|
-
id: 'test',
|
|
66
|
-
price: 0.99,
|
|
67
|
-
},
|
|
68
|
-
],
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
when(get(`${storefrontURL}/invoices/${id}`)).thenReturn(
|
|
72
|
-
ok(testInvoice),
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const instance = new StorefontTestingInstance({
|
|
76
|
-
data: {
|
|
77
|
-
invoice: {
|
|
78
|
-
id,
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
const { invoice, products } = await fetchInvoiceAndProducts({
|
|
84
|
-
data: { id },
|
|
85
|
-
state: instance,
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
expect(invoice).toBeInstanceOf(InvoiceModel);
|
|
89
|
-
expect(products).toBeInstanceOf(Array);
|
|
90
|
-
expect(products.length).toBe(0);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import BaseModel from './base-model';
|
|
2
|
-
|
|
3
|
-
export class AddressModel {
|
|
4
|
-
constructor({
|
|
5
|
-
firstName = null,
|
|
6
|
-
lastName = null,
|
|
7
|
-
organization = null,
|
|
8
|
-
address = null,
|
|
9
|
-
address2 = null,
|
|
10
|
-
city = null,
|
|
11
|
-
region = null,
|
|
12
|
-
country = null,
|
|
13
|
-
postalCode = null,
|
|
14
|
-
emails = [],
|
|
15
|
-
phoneNumbers = [],
|
|
16
|
-
} = {}) {
|
|
17
|
-
this.firstName = firstName;
|
|
18
|
-
this.lastName = lastName;
|
|
19
|
-
this.organization = organization;
|
|
20
|
-
this.address = address;
|
|
21
|
-
this.address2 = address2;
|
|
22
|
-
this.city = city;
|
|
23
|
-
this.region = region;
|
|
24
|
-
this.country = country;
|
|
25
|
-
this.postalCode = postalCode;
|
|
26
|
-
this.email = emails.find((v) => v.primary)?.value || null;
|
|
27
|
-
this.phoneNumber = phoneNumbers.find((v) => v.primary)?.value || null;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export default class AccountModel extends BaseModel {
|
|
32
|
-
constructor({ primaryAddress = {}, ...fields } = {}) {
|
|
33
|
-
super(fields);
|
|
34
|
-
this.address = new AddressModel({ ...primaryAddress });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import merge from 'lodash.merge';
|
|
2
|
-
import BaseModel from './base-model';
|
|
3
|
-
|
|
4
|
-
export default class DepositRequestModel extends BaseModel {
|
|
5
|
-
constructor(fields) {
|
|
6
|
-
super(fields);
|
|
7
|
-
this.amount = Array.isArray(fields.amounts)
|
|
8
|
-
? fields.amounts[0]
|
|
9
|
-
: fields.amount;
|
|
10
|
-
this.buttons = fields.buttons ?? [...fields.amounts];
|
|
11
|
-
this.editable =
|
|
12
|
-
typeof fields.editable === 'boolean'
|
|
13
|
-
? fields.editable
|
|
14
|
-
: Boolean(fields.customAmount);
|
|
15
|
-
this.customAmount = merge(
|
|
16
|
-
{
|
|
17
|
-
minimum: 1,
|
|
18
|
-
maximum: 1000000000000,
|
|
19
|
-
multipleOf: 1,
|
|
20
|
-
},
|
|
21
|
-
fields.customAmount || {},
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import BaseModel from './base-model';
|
|
2
|
-
|
|
3
|
-
export default class InvoiceModel extends BaseModel {
|
|
4
|
-
static Status = {
|
|
5
|
-
draft: 'draft',
|
|
6
|
-
unpaid: 'unpaid',
|
|
7
|
-
paid: 'paid',
|
|
8
|
-
partiallyPaid: 'partially-paid',
|
|
9
|
-
pastDue: 'past-due',
|
|
10
|
-
abandoned: 'abandoned',
|
|
11
|
-
voided: 'voided',
|
|
12
|
-
partiallyRefunded: 'partially-refunded',
|
|
13
|
-
refunded: 'refunded',
|
|
14
|
-
disputed: 'disputed',
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
get isPaid() {
|
|
18
|
-
return this.status === InvoiceModel.Status.paid;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import BaseModel from './base-model';
|
|
2
|
-
|
|
3
|
-
export class PlanPricingBracketModel {
|
|
4
|
-
constructor({ maxQuantity = null, price = null } = {}) {
|
|
5
|
-
this.maxQuantity = maxQuantity || Number.MAX_SAFE_INTEGER;
|
|
6
|
-
this.price = !Number.isNaN(parseFloat(price))
|
|
7
|
-
? parseFloat(price)
|
|
8
|
-
: null;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class PlanPricingModel {
|
|
13
|
-
static SimpleFormulas = {
|
|
14
|
-
fixedFee: 'fixed-fee',
|
|
15
|
-
flatRate: 'flat-rate',
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
static BracketFormulas = {
|
|
19
|
-
stairstep: 'stairstep',
|
|
20
|
-
tiered: 'tiered',
|
|
21
|
-
volume: 'volume',
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
static Formulas = {
|
|
25
|
-
...PlanPricingModel.SimpleFormulas,
|
|
26
|
-
...PlanPricingModel.BracketFormulas,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
constructor({
|
|
30
|
-
formula = PlanPricingModel.Formulas.fixedFee,
|
|
31
|
-
price = 0,
|
|
32
|
-
maxQuantity = null,
|
|
33
|
-
brackets = [],
|
|
34
|
-
} = {}) {
|
|
35
|
-
this.formula = formula;
|
|
36
|
-
|
|
37
|
-
switch (this.formula) {
|
|
38
|
-
case PlanPricingModel.Formulas.stairstep:
|
|
39
|
-
case PlanPricingModel.Formulas.tiered:
|
|
40
|
-
case PlanPricingModel.Formulas.volume:
|
|
41
|
-
this.brackets = brackets.map(
|
|
42
|
-
(bracket) => new PlanPricingBracketModel(bracket),
|
|
43
|
-
);
|
|
44
|
-
break;
|
|
45
|
-
case PlanPricingModel.Formulas.flatRate:
|
|
46
|
-
this.price = !Number.isNaN(parseFloat(price))
|
|
47
|
-
? parseFloat(price)
|
|
48
|
-
: null;
|
|
49
|
-
this.maxQuantity = maxQuantity;
|
|
50
|
-
break;
|
|
51
|
-
case PlanPricingModel.Formulas.fixedFee:
|
|
52
|
-
default:
|
|
53
|
-
this.price = !Number.isNaN(parseFloat(price))
|
|
54
|
-
? parseFloat(price)
|
|
55
|
-
: null;
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
get isSimple() {
|
|
61
|
-
return Object.values(PlanPricingModel.SimpleFormulas).includes(
|
|
62
|
-
this.formula,
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
get isBracket() {
|
|
67
|
-
return Object.values(PlanPricingModel.BracketFormulas).includes(
|
|
68
|
-
this.formula,
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
toPayload() {
|
|
73
|
-
return {
|
|
74
|
-
...this,
|
|
75
|
-
isSimple: this.isSimple,
|
|
76
|
-
isBracket: this.isBracket,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export default class PlanModel extends BaseModel {
|
|
82
|
-
constructor(fields = {}) {
|
|
83
|
-
super(fields);
|
|
84
|
-
|
|
85
|
-
this.pricing = new PlanPricingModel(fields.pricing || {});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
toPayload() {
|
|
89
|
-
return {
|
|
90
|
-
...this,
|
|
91
|
-
pricing: this.pricing.toPayload(),
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import PaymentMetadataModel from './payment-metadata';
|
|
2
|
-
|
|
3
|
-
export class ReadyToPayFeatureModel {
|
|
4
|
-
static FeatureName = {
|
|
5
|
-
paypalBillingAgreement: 'PayPal billing agreement',
|
|
6
|
-
googlePay: 'Google Pay',
|
|
7
|
-
applePay: 'Apple Pay',
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
constructor({
|
|
11
|
-
name = '',
|
|
12
|
-
expirationTime = '',
|
|
13
|
-
|
|
14
|
-
// Apple Pay fields
|
|
15
|
-
displayName = '',
|
|
16
|
-
country = '',
|
|
17
|
-
|
|
18
|
-
// Google Pay fields
|
|
19
|
-
merchantName = '',
|
|
20
|
-
merchantOrigin = '',
|
|
21
|
-
|
|
22
|
-
// Paypal fields
|
|
23
|
-
paypalMerchantId = '',
|
|
24
|
-
billingAgreementToken = '',
|
|
25
|
-
paypalClientId = '',
|
|
26
|
-
|
|
27
|
-
// Plaid fields
|
|
28
|
-
linkToken = '',
|
|
29
|
-
} = {}) {
|
|
30
|
-
this.name = name;
|
|
31
|
-
this.expirationTime = expirationTime;
|
|
32
|
-
|
|
33
|
-
this.displayName = displayName;
|
|
34
|
-
this.country = country;
|
|
35
|
-
|
|
36
|
-
this.merchantName = merchantName;
|
|
37
|
-
this.merchantOrigin = merchantOrigin;
|
|
38
|
-
|
|
39
|
-
this.paypalMerchantId = paypalMerchantId;
|
|
40
|
-
this.billingAgreementToken = billingAgreementToken;
|
|
41
|
-
this.paypalClientId = paypalClientId;
|
|
42
|
-
|
|
43
|
-
this.linkToken = linkToken;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export default class ReadyToPayModel {
|
|
48
|
-
constructor({
|
|
49
|
-
index = null,
|
|
50
|
-
method = '',
|
|
51
|
-
feature = null,
|
|
52
|
-
brands = [],
|
|
53
|
-
filters = [],
|
|
54
|
-
metadata = null,
|
|
55
|
-
} = {}) {
|
|
56
|
-
this.index = index;
|
|
57
|
-
this.method = method;
|
|
58
|
-
this.feature = feature ? new ReadyToPayFeatureModel(feature) : null;
|
|
59
|
-
this.brands = brands;
|
|
60
|
-
this.filters = filters;
|
|
61
|
-
this.metadata = metadata ? new PaymentMetadataModel(metadata) : null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
get optionsPaymentInstrumentsKey() {
|
|
65
|
-
switch (this.feature?.name) {
|
|
66
|
-
case ReadyToPayFeatureModel.FeatureName.paypalBillingAgreement:
|
|
67
|
-
return 'paypal';
|
|
68
|
-
case ReadyToPayFeatureModel.FeatureName.googlePay:
|
|
69
|
-
return 'googlePay';
|
|
70
|
-
case ReadyToPayFeatureModel.FeatureName.applePay:
|
|
71
|
-
return 'applePay';
|
|
72
|
-
default:
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|