@rebilly/instruments 3.21.1-beta.0 → 3.23.0-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.
Files changed (54) hide show
  1. package/dist/index.js +10 -17
  2. package/dist/index.min.js +49 -56
  3. package/package.json +3 -1
  4. package/src/functions/destroy.js +11 -9
  5. package/src/functions/mount/fetch-data.js +20 -21
  6. package/src/functions/mount/fetch-data.spec.js +140 -93
  7. package/src/functions/mount/index.js +9 -10
  8. package/src/functions/mount/mount.spec.js +5 -7
  9. package/src/functions/mount/setup-framepay-theme.js +2 -1
  10. package/src/functions/mount/setup-framepay.js +3 -1
  11. package/src/functions/mount/setup-i18n.js +4 -2
  12. package/src/functions/mount/setup-options.js +6 -4
  13. package/src/functions/on.spec.js +3 -2
  14. package/src/functions/purchase.js +16 -5
  15. package/src/functions/setup.js +3 -4
  16. package/src/functions/show.js +7 -6
  17. package/src/functions/show.spec.js +11 -7
  18. package/src/functions/update.js +3 -3
  19. package/src/functions/update.spec.js +4 -3
  20. package/src/instance.js +11 -31
  21. package/src/state/iframes.js +23 -0
  22. package/src/state/index.js +61 -0
  23. package/src/storefront/account-and-website.js +3 -2
  24. package/src/storefront/{fetch-plans-from-addons-bumpOffers.js → fetch-plans-from-addons-bumpOffer.js} +5 -4
  25. package/src/storefront/fetch-products-from-plans.js +5 -4
  26. package/src/storefront/index.js +3 -4
  27. package/src/storefront/invoices.js +6 -4
  28. package/src/storefront/payment-instruments.js +5 -4
  29. package/src/storefront/purchase.js +5 -4
  30. package/src/storefront/ready-to-pay.js +5 -13
  31. package/src/storefront/summary.js +8 -3
  32. package/src/storefront/transactions.js +3 -2
  33. package/src/style/base/index.js +243 -0
  34. package/src/views/common/iframe/base-iframe.js +0 -2
  35. package/src/views/common/iframe/events/update-addons-handler.js +8 -13
  36. package/src/views/common/iframe/events/update-coupons-handler.js +5 -11
  37. package/src/views/confirmation.js +16 -6
  38. package/src/views/method-selector/__snapshots__/method-selector.spec.js.snap +182 -1
  39. package/src/views/method-selector/generate-digital-wallet.js +2 -1
  40. package/src/views/method-selector/generate-digital-wallet.spec.js +32 -37
  41. package/src/views/method-selector/generate-framepay-config.js +1 -1
  42. package/src/views/method-selector/generate-framepay-config.spec.js +9 -12
  43. package/src/views/method-selector/get-payment-methods.js +3 -1
  44. package/src/views/method-selector/get-payment-methods.spec.js +25 -34
  45. package/src/views/method-selector/index.js +39 -20
  46. package/src/views/method-selector/method-selector.spec.js +9 -109
  47. package/src/views/method-selector/mount-bump-offer.js +99 -0
  48. package/src/views/method-selector/mount-express-methods.js +1 -2
  49. package/src/views/modal.js +3 -3
  50. package/src/views/result.js +7 -5
  51. package/src/views/summary.js +12 -16
  52. package/tests/mocks/rebilly-instruments-mock.js +17 -19
  53. package/tests/mocks/storefront-mock.js +10 -9
  54. package/tests/setup-jest.js +2 -0
@@ -2,6 +2,7 @@ import camelCase from 'lodash.camelcase';
2
2
  import { RenderMockRebillyInstruments } from 'tests/mocks/rebilly-instruments-mock';
3
3
  import { RebillyInstrumentsInstance } from '../instance';
4
4
  import Events from '../events';
5
+ import iframes from '../state/iframes';
5
6
 
6
7
  describe('RebillyInstruments on', () => {
7
8
  it('should register event listeners', async () => {
@@ -32,7 +33,7 @@ describe('RebillyInstruments on', () => {
32
33
  call: jest.fn()
33
34
  }
34
35
  };
35
- instance.state.iframeComponents.form = iframeMock;
36
+ iframes.form = iframeMock;
36
37
 
37
38
  let error;
38
39
  try {
@@ -52,7 +53,7 @@ describe('RebillyInstruments on', () => {
52
53
  call: jest.fn()
53
54
  }
54
55
  };
55
- instance.state.iframeComponents.form = iframeMock;
56
+ iframes.form = iframeMock;
56
57
 
57
58
  let error;
58
59
  try {
@@ -1,10 +1,11 @@
1
+ import state from '../state';
1
2
  import { postPurchase, postPayment } from '../storefront/purchase';
2
3
  import Events from '../events';
3
4
  import { mountModal } from '../views/modal';
4
5
  import { DataInstance } from './mount/fetch-data';
5
6
  import { showError } from '../views/errors';
6
7
 
7
- export async function makePayment({ state, payload }) {
8
+ export async function makePayment({ payload }) {
8
9
  const {
9
10
  _raw: {
10
11
  id
@@ -60,16 +61,21 @@ export async function makePayment({ state, payload }) {
60
61
  return fields;
61
62
  }
62
63
 
63
- export async function makePurchase({ state, payload }) {
64
+ export async function makePurchase({ payload }) {
64
65
  const data = {
65
66
  websiteId: state.options.websiteId,
66
- items: state.options.items,
67
67
  paymentInstruction: {
68
68
  token: payload._raw.id
69
69
  },
70
70
  ...payload
71
71
  };
72
72
 
73
+ if (state.data.acceptBumpOffer) {
74
+ data.items = state.options.bumpOffer;
75
+ } else {
76
+ data.items = state.options.items;
77
+ }
78
+
73
79
  if (state.data.couponIds && Array.isArray(state.data.couponIds)) {
74
80
  data.couponIds = state.data.couponIds
75
81
  }
@@ -82,6 +88,11 @@ export async function makePurchase({ state, payload }) {
82
88
  })
83
89
  }
84
90
 
91
+ data.items = data.items.map(item => {
92
+ delete item.thumbnail;
93
+ return item;
94
+ })
95
+
85
96
  const { fields } = await postPurchase({
86
97
  state,
87
98
  data
@@ -89,7 +100,7 @@ export async function makePurchase({ state, payload }) {
89
100
  return fields;
90
101
  }
91
102
 
92
- export function handleApprovalUrl({state, fields, payload}) {
103
+ export function handleApprovalUrl({fields, payload}) {
93
104
  if (payload.redirectUrl || !fields.transaction?.approvalUrl) {
94
105
  const { paymentMethodsUrl } = state.options._computed;
95
106
 
@@ -116,7 +127,7 @@ export function handleApprovalUrl({state, fields, payload}) {
116
127
  }
117
128
  }
118
129
 
119
- export async function purchase({ state, payload }) {
130
+ export async function purchase({ payload }) {
120
131
  Object.keys(payload).forEach(key => {
121
132
  if (payload[key] === null) {
122
133
  delete payload[key];
@@ -1,10 +1,11 @@
1
+ import state from '../state';
1
2
  import { setupPaymentInstrument } from '../storefront/payment-instruments';
2
3
  import Events from '../events';
3
4
  import { mountModal } from '../views/modal';
4
5
  import { DataInstance } from './mount/fetch-data';
5
6
  import { showError } from '../views/errors';
6
7
 
7
- export async function setup({ state, payload }) {
8
+ export async function setup({ payload }) {
8
9
  try {
9
10
  const {
10
11
  _raw: {
@@ -26,19 +27,17 @@ export async function setup({ state, payload }) {
26
27
  }
27
28
 
28
29
  const {instrument, transaction} = await setupPaymentInstrument({
29
- state,
30
30
  data: {
31
31
  websiteId: state.options?.websiteId,
32
32
  ...data
33
33
  }
34
34
  });
35
35
 
36
- state.data = new DataInstance({state, instrument, transaction});
36
+ state.data = new DataInstance({instrument, transaction});
37
37
 
38
38
  if (transaction.approvalUrl && transaction.result === 'unknown') {
39
39
  const { paymentMethodsUrl } = state.options._computed;
40
40
  mountModal({
41
- state,
42
41
  name: 'rebilly-instruments-approval-url',
43
42
  url: `${paymentMethodsUrl}/approval-url`,
44
43
  model: {
@@ -1,3 +1,4 @@
1
+ import iframes from '../state/iframes';
1
2
  import { mountConfirmation } from '../views/confirmation';
2
3
  import { mountResult } from '../views/result';
3
4
 
@@ -13,17 +14,17 @@ import { mountResult } from '../views/result';
13
14
  * Register events that will be triggered
14
15
  * @param {ShowParams} params
15
16
  */
16
- export async function show({ componentName, payload, state }) {
17
+ export async function show({ componentName, payload }) {
17
18
  switch (componentName) {
18
19
  case 'result':
19
- if (state.iframeComponents.form) {
20
- state.iframeComponents.form.destroy();
21
- state.iframeComponents.form = null;
20
+ if (iframes.hasFrame('form')) {
21
+ iframes.form.destroy();
22
+ iframes.form = null;
22
23
  }
23
- mountResult({payload, state});
24
+ mountResult({ payload });
24
25
  break;
25
26
  case 'confirmation':
26
- mountConfirmation({payload, state});
27
+ mountConfirmation({ payload });
27
28
  break;
28
29
  default:
29
30
  throw new Error(`'${componentName}' not a supported component`);
@@ -1,7 +1,7 @@
1
1
  import * as result from '@/views/result';
2
2
  import * as confirmation from '@/views/confirmation';
3
- import { RenderMockRebillyInstruments } from 'tests/mocks/rebilly-instruments-mock';
4
3
  import { RebillyInstrumentsInstance } from '../instance';
4
+ import iframes from 'src/state/iframes';
5
5
 
6
6
  const iframeMock = { destroy: jest.fn() };
7
7
 
@@ -12,7 +12,7 @@ describe('RebillyInstruments show', () => {
12
12
  .mockReturnValue(Promise.resolve());
13
13
 
14
14
  const instance = new RebillyInstrumentsInstance();
15
- instance.state.iframeComponents.form = iframeMock;
15
+ iframes.form = iframeMock;
16
16
 
17
17
  const payload = {
18
18
  test: 'value'
@@ -21,8 +21,10 @@ describe('RebillyInstruments show', () => {
21
21
  await instance.show('result', payload);
22
22
 
23
23
  expect(mountResult).toBeCalledTimes(1);
24
- expect(mountResult).toBeCalledWith({payload, state: instance.state});
25
- expect(instance.state.iframeComponents.form).toEqual(null);
24
+ expect(mountResult).toBeCalledWith(
25
+ expect.objectContaining({ payload })
26
+ );
27
+ expect(iframes.form).toEqual(null);
26
28
  });
27
29
 
28
30
  it('should show confirmation component', async () => {
@@ -31,7 +33,7 @@ describe('RebillyInstruments show', () => {
31
33
  .mockReturnValue(Promise.resolve());
32
34
 
33
35
  const instance = new RebillyInstrumentsInstance();
34
- instance.state.iframeComponents.form = iframeMock;
36
+ iframes.form = iframeMock;
35
37
 
36
38
  const payload = {
37
39
  test: 'value'
@@ -40,8 +42,10 @@ describe('RebillyInstruments show', () => {
40
42
  await instance.show('confirmation', payload);
41
43
 
42
44
  expect(mountConfirmation).toBeCalledTimes(1);
43
- expect(mountConfirmation).toBeCalledWith({payload, state: instance.state});
44
- expect(instance.state.iframeComponents.form).toEqual(iframeMock);
45
+ expect(mountConfirmation).toBeCalledWith(
46
+ expect.objectContaining({payload})
47
+ );
48
+ expect(iframes.form).toEqual(iframeMock);
45
49
  });
46
50
 
47
51
  it('should fail for non supported component', async () => {
@@ -1,4 +1,5 @@
1
1
  import merge from 'lodash.merge';
2
+ import state from '../state';
2
3
  import { destroy } from './destroy';
3
4
  import { mount } from './mount';
4
5
 
@@ -21,7 +22,7 @@ function sanitizeOldPurchaseData({newOptions}) {
21
22
  return purchaseData;
22
23
  };
23
24
 
24
- export async function update({state, newOptions = {}}) {
25
+ export async function update({newOptions = {}}) {
25
26
  if (!state.hasMounted) {
26
27
  throw Error('Update method cannot be called before mounting instruments');
27
28
  }
@@ -51,10 +52,9 @@ export async function update({state, newOptions = {}}) {
51
52
 
52
53
  const updatedOptions = merge({...oldOptions}, newOptions);
53
54
 
54
- await destroy({ state });
55
+ await destroy();
55
56
 
56
57
  mount({
57
- state,
58
58
  form: state.form,
59
59
  summary: state.summary,
60
60
  ...updatedOptions,
@@ -1,5 +1,6 @@
1
1
  import { RenderMockRebillyInstruments } from 'tests/mocks/rebilly-instruments-mock';
2
2
  import { avoidUnhandledPromises } from 'tests/async-utilities';
3
+ import iframes from '../state/iframes';
3
4
 
4
5
  describe('RebillyInstruments Update', () => {
5
6
  it('should throw an error when methods are not mounted', async () => {
@@ -31,7 +32,7 @@ describe('RebillyInstruments Update', () => {
31
32
  call
32
33
  }
33
34
  };
34
- rebillyInstruments.state.iframeComponents.form = fakeIFrameComponent;
35
+ iframes.form = fakeIFrameComponent;
35
36
 
36
37
  await rebillyInstruments.update({ locale: 'ja' });
37
38
 
@@ -58,7 +59,7 @@ describe('RebillyInstruments Update', () => {
58
59
  call
59
60
  }
60
61
  };
61
- rebillyInstruments.state.iframeComponents.form = fakeIFrameComponent;
62
+ iframes.form = fakeIFrameComponent;
62
63
 
63
64
  await rebillyInstruments.update({
64
65
  countryCode: 'ES'
@@ -84,7 +85,7 @@ describe('RebillyInstruments Update', () => {
84
85
  }
85
86
  };
86
87
 
87
- rebillyInstruments.state.iframeComponents.form = fakeIFrameComponent;
88
+ iframes.form = fakeIFrameComponent;
88
89
 
89
90
  await rebillyInstruments.update({
90
91
  items: [
package/src/instance.js CHANGED
@@ -1,61 +1,41 @@
1
+ import state from './state';
2
+ import iframes from './state/iframes';
1
3
  import { mount } from './functions/mount';
2
4
  import { purchase } from './functions/purchase';
3
5
  import { setup } from './functions/setup';
4
6
  import { on } from './functions/on';
5
7
  import { update } from './functions/update';
6
8
  import { destroy } from './functions/destroy';
7
- import { Loader } from './loader';
8
- import { Translate } from './i18n';
9
9
  import { show } from './functions/show';
10
10
 
11
- export class InstrumentsState {
12
- constructor() {
13
- this.options = null;
14
- this.data = {};
15
- this.mountingPoints = null;
16
- this.storefront = null;
17
- this.form = null;
18
- this.summary = null;
19
- this.loader = new Loader();
20
- this.translate = new Translate();
21
- this.iframeComponents = {
22
- summary: null,
23
- form: null,
24
- };
25
- this.hasMounted = false;
26
- }
27
- }
28
-
29
11
  export class RebillyInstrumentsInstance {
30
12
  constructor() {
31
- this.state = new InstrumentsState();
32
- // TODO: mountConfirmation, mountResult have different contract shape when they look similar
33
- // TODO: review test coverage of UpdateSummary and UpdateMethodSelector as no tests were broken
34
- // when commenting them
13
+ this.state = state;
14
+ this.iframes = iframes;
35
15
  }
36
16
 
37
17
  async mount(options) {
38
- await mount({ state: this.state, ...options });
18
+ await mount(options);
39
19
  }
40
20
 
41
21
  async destroy() {
42
- await destroy({ state: this.state });
22
+ await destroy();
43
23
  }
44
24
 
45
25
  async update(newOptions) {
46
- await update({state: this.state, newOptions});
26
+ await update({newOptions});
47
27
  }
48
28
 
49
29
  async purchase(payload) {
50
- await purchase({ state: this.state, payload });
30
+ await purchase({ payload });
51
31
  }
52
32
 
53
33
  async setup(payload) {
54
- await setup({ state: this.state, payload });
34
+ await setup({ payload });
55
35
  }
56
36
 
57
37
  async show(componentName, payload) {
58
- await show({ state: this.state, componentName, payload });
38
+ await show({ componentName, payload });
59
39
  }
60
40
 
61
41
  get version() {
@@ -63,6 +43,6 @@ export class RebillyInstrumentsInstance {
63
43
  }
64
44
 
65
45
  on(eventName, callback) {
66
- on({ state: this.state, eventName, callback });
46
+ on({ eventName, callback });
67
47
  }
68
48
  }
@@ -0,0 +1,23 @@
1
+ export default (() => {
2
+ let state = null;
3
+ return {
4
+ getInstance() {
5
+ if (state === null) {
6
+ state = {
7
+ form: null,
8
+ summary: null,
9
+ hasFrame(name) {
10
+ if (state[name] && !name.match(/^has.*/)) {
11
+ return !!state[name];
12
+ }
13
+ return false;
14
+ },
15
+ hasComponent(name) {
16
+ return !!state[name]?.component;
17
+ }
18
+ }
19
+ }
20
+ return state;
21
+ }
22
+ }
23
+ })().getInstance();
@@ -0,0 +1,61 @@
1
+ import { reactive } from '@vue/reactivity';
2
+ import { Loader } from '../loader';
3
+ import { Translate } from '../i18n';
4
+ import iframes from './iframes';
5
+
6
+ export default (() => {
7
+ let state = null;
8
+ const defaultState = {
9
+ options: null,
10
+ data: {},
11
+ mountingPoints: null,
12
+ storefront: null,
13
+ form: null,
14
+ summary: null,
15
+ loader: new Loader(),
16
+ translate: new Translate,
17
+ hasMounted: false,
18
+ toModel() {
19
+ const model = {
20
+ ...state,
21
+ data: state.data.toPostmatesMode ? state.data.toPostmatesModel() : {},
22
+ };
23
+
24
+ // remove functions from model
25
+ delete model.toModel;
26
+ delete model.updateModel;
27
+
28
+ return JSON.parse(JSON.stringify(model));
29
+ },
30
+ updateModel() {
31
+ const modelSafeState = state?.toModel();
32
+ if (modelSafeState) {
33
+ const updateModel = {
34
+ data: modelSafeState.data,
35
+ options: modelSafeState.options
36
+ }
37
+
38
+ if (iframes.hasComponent('summary')) {
39
+ iframes.summary.component.call('update', updateModel);
40
+ }
41
+ if (iframes.hasComponent('summary')) {
42
+ iframes.form.component.call('update', updateModel);
43
+ }
44
+ }
45
+ },
46
+ reset() {
47
+ if (state !== null) {
48
+ state = reactive({...defaultState});
49
+ }
50
+ }
51
+ };
52
+
53
+ return {
54
+ getInstance() {
55
+ if (state === null) {
56
+ state = reactive({...defaultState});
57
+ }
58
+ return state;
59
+ }
60
+ }
61
+ })().getInstance();
@@ -1,9 +1,10 @@
1
1
  import AccountModel from './models/account-model';
2
2
  import WebsiteModel from './models/website-model';
3
3
  import { Endpoint } from './index';
4
+ import state from '../state';
4
5
 
5
- export async function fetchAccountAndWebsite({ state = null }) {
6
- return Endpoint({state}, async () => {
6
+ export async function fetchAccountAndWebsite() {
7
+ return Endpoint(async () => {
7
8
  state.storefront.setSessionToken(state.options.jwt);
8
9
  const {fields} = await state.storefront.account.get({expand: 'website'});
9
10
 
@@ -1,8 +1,9 @@
1
1
  import PlanModel from './models/plan-model';
2
2
  import { Endpoint } from './index';
3
+ import state from '../state';
3
4
 
4
- export async function fetchPlansFromAddonsBumpOffers({ state = {} }) {
5
- return Endpoint({state}, async () => {
5
+ export async function fetchPlansFromAddonsBumpOffer() {
6
+ return Endpoint(async () => {
6
7
  let ids = [];
7
8
 
8
9
  if (state.options?.addons) {
@@ -10,8 +11,8 @@ export async function fetchPlansFromAddonsBumpOffers({ state = {} }) {
10
11
  .map((item) => item.planId));
11
12
  }
12
13
 
13
- if (state.options?.bumpOffers) {
14
- ids = ids.concat(state.options.bumpOffers
14
+ if (state.options?.bumpOffer) {
15
+ ids = ids.concat(state.options.bumpOffer
15
16
  .map((item) => item.planId));
16
17
  }
17
18
 
@@ -1,8 +1,9 @@
1
1
  import ProductModel from './models/product-model';
2
2
  import { Endpoint } from './index';
3
+ import state from '../state';
3
4
 
4
- export async function fetchProductsFromPlans({ state = {} }) {
5
- return Endpoint({state}, async () => {
5
+ export async function fetchProductsFromPlans() {
6
+ return Endpoint(async () => {
6
7
  let lineItems = state.data.summaryLineItems;
7
8
  if(lineItems.length === 0)
8
9
  {
@@ -23,8 +24,8 @@ export async function fetchProductsFromPlans({ state = {} }) {
23
24
  .map((item) => item.planId));
24
25
  }
25
26
 
26
- if (state.options?.bumpOffers) {
27
- ids = ids.concat(state.options.bumpOffers
27
+ if (state.options?.bumpOffer) {
28
+ ids = ids.concat(state.options.bumpOffer
28
29
  .map((item) => item.planId));
29
30
  }
30
31
 
@@ -1,9 +1,10 @@
1
1
  import RebillyApi, {RebillyStorefrontAPI, RebillyExperimentalAPI} from 'rebilly-js-sdk';
2
2
  import { showError } from '../views/errors';
3
+ import state from '../state';
3
4
 
4
5
  const TIMEOUT = 60000;
5
6
 
6
- export function validateStateForStorefront({state}) {
7
+ export function validateStateForStorefront() {
7
8
  if (!state.storefront) {
8
9
  throw new Error('Could not access rebilly-js-sdk instance');
9
10
  }
@@ -15,9 +16,7 @@ export function validateStateForStorefront({state}) {
15
16
  }
16
17
  }
17
18
 
18
- export async function Endpoint({
19
- state
20
- } = {}, callback) {
19
+ export async function Endpoint(callback) {
21
20
  try {
22
21
  validateStateForStorefront({state});
23
22
  return await callback();
@@ -1,17 +1,19 @@
1
1
  import InvoiceModel from './models/invoice-model';
2
2
  import ProductModel from './models/product-model';
3
3
  import { Endpoint } from './index';
4
+ import state from '../state';
4
5
 
5
- export async function fetchInvoiceAndProducts({ data = null, state = null }) {
6
- return Endpoint({state}, async () => {
6
+ export async function fetchInvoiceAndProducts({ data = null }) {
7
+ return Endpoint(async () => {
7
8
  state.storefront.setSessionToken(state.options.jwt);
8
9
  const {fields} = await state.storefront.invoices.get({
9
10
  ...data,
10
11
  expand: 'items.*.product'
11
12
  });
12
13
 
13
- const products = fields.items.filter(item => item._embedded)
14
- .map(items => new ProductModel(items._embedded.product));
14
+ const products = fields.items
15
+ .filter(item => item._embedded)
16
+ .map(items => new ProductModel(items._embedded.product));
15
17
 
16
18
  return {
17
19
  products,
@@ -1,7 +1,8 @@
1
1
  import { Endpoint } from './index';
2
+ import state from '../state';
2
3
 
3
- export async function setupPaymentInstrument({ data, state }) {
4
- return Endpoint({state}, async () => {
4
+ export async function setupPaymentInstrument({ data }) {
5
+ return Endpoint(async () => {
5
6
  // Create payment instrument
6
7
  const { fields: instrument } = await state.storefront.paymentInstruments.create({data});
7
8
 
@@ -33,8 +34,8 @@ export async function setupPaymentInstrument({ data, state }) {
33
34
  });
34
35
  }
35
36
 
36
- export async function fetchPaymentInstrument({ state }) {
37
- return Endpoint({state}, async () => {
37
+ export async function fetchPaymentInstrument() {
38
+ return Endpoint(async () => {
38
39
  const { items: instruments } = await state.storefront.paymentInstruments.getAll();
39
40
  return instruments.map(({fields}) => fields);
40
41
  });
@@ -1,7 +1,8 @@
1
+ import state from '../state';
1
2
  import { Endpoint } from './index';
2
3
 
3
- export async function postPurchase({ data, state }) {
4
- return Endpoint({state}, async () => {
4
+ export async function postPurchase({ data }) {
5
+ return Endpoint(async () => {
5
6
  if (data._raw) {
6
7
  delete data._raw;
7
8
  }
@@ -9,8 +10,8 @@ export async function postPurchase({ data, state }) {
9
10
  });
10
11
  }
11
12
 
12
- export async function postPayment({ data, state }) {
13
- return Endpoint({state}, async () => {
13
+ export async function postPayment({ data }) {
14
+ return Endpoint(async () => {
14
15
  if (data._raw) {
15
16
  delete data._raw;
16
17
  }
@@ -2,12 +2,12 @@ import { collectData } from '@rebilly/risk-data-collector';
2
2
  import paymentMethodsFile from '../data/payment-methods.json';
3
3
  import ReadyToPayModel from './models/ready-to-pay-model';
4
4
  import { Endpoint } from './index';
5
+ import state from '../state';
5
6
 
6
7
  export async function fetchReadyToPay({
7
- state,
8
8
  riskMetadata = null,
9
9
  }) {
10
- return Endpoint({state}, async () => {
10
+ return Endpoint(async () => {
11
11
  if (!riskMetadata) {
12
12
  const { riskMetadata: data } = await collectData();
13
13
  riskMetadata = data;
@@ -16,22 +16,14 @@ export async function fetchReadyToPay({
16
16
  const data = {
17
17
  riskMetadata
18
18
  };
19
-
20
- let websiteId = state.options?.websiteId || null;
21
- if (!websiteId) {
22
- if (state.data.transaction?.websiteId) {
23
- websiteId = state.data.transaction.websiteId
24
- } else if (state.data.invoice?.websiteId) {
25
- websiteId = state.data.invoice.websiteId;
26
- }
27
- }
28
- data.websiteId = websiteId;
19
+
20
+ data.websiteId = state.options?.websiteId || null;
29
21
 
30
22
  if (state.options?.items) {
31
23
  data.items = state.options.items;
32
24
  }
33
25
 
34
- if (state.data?.amountAndCurrency) {
26
+ if (state.options?.money && state.data?.amountAndCurrency) {
35
27
  const money = state.data.amountAndCurrency;
36
28
  data.amount = money.amount;
37
29
  data.currency = money.currency;
@@ -1,8 +1,9 @@
1
+ import state from '../state';
1
2
  import SummaryModel from './models/summary-model';
2
3
  import { Endpoint } from './index';
3
4
 
4
- export async function fetchSummary({ data = null, state = null } = {}) {
5
- return Endpoint({state}, async () => {
5
+ export async function fetchSummary({ data = null } = {}) {
6
+ return Endpoint(async () => {
6
7
  const websiteId = state.options?.websiteId || null;
7
8
 
8
9
  const payload = {
@@ -12,7 +13,11 @@ export async function fetchSummary({ data = null, state = null } = {}) {
12
13
  };
13
14
 
14
15
  if (state.options?.items) {
15
- payload.data.items = state.options.items;
16
+ if (state.data.acceptBumpOffer) {
17
+ payload.data.items = state.options.bumpOffer;
18
+ } else {
19
+ payload.data.items = state.options.items;
20
+ }
16
21
  } else {
17
22
  payload.data.items = state.data.summaryLineItems.map(item => ({
18
23
  planId: item.planId,
@@ -1,8 +1,9 @@
1
1
  import TransactionModel from './models/transaction-model';
2
2
  import { Endpoint } from './index';
3
+ import state from '../state';
3
4
 
4
- export async function fetchTransaction({ data = null, state = null }) {
5
- return Endpoint({state}, async () => {
5
+ export async function fetchTransaction({ data = null }) {
6
+ return Endpoint(async () => {
6
7
  state.storefront.setSessionToken(state.options.jwt);
7
8
  const {fields} = await state.storefront.transactions.get(data);
8
9