@rebilly/instruments 3.16.5-beta.0 → 3.19.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebilly/instruments",
3
- "version": "3.16.5-beta.0",
3
+ "version": "3.19.0-beta.0",
4
4
  "author": "Rebilly",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -81,30 +81,40 @@ export async function makePurchase({ state, payload }) {
81
81
  return fields;
82
82
  }
83
83
 
84
- export function handleApprovalUrl({state, fields}) {
85
- const { paymentMethodsUrl } = state.options._computed;
84
+ export function handleApprovalUrl({state, fields, payload}) {
85
+ if (payload.redirectUrl || !fields.transaction?.approvalUrl) {
86
+ const { paymentMethodsUrl } = state.options._computed;
86
87
 
87
- const model = {};
88
- if (state.data.isPayment) {
89
- model.payment = fields;
90
- } else {
91
- model.purchase = fields;
92
- }
93
-
94
- state.data = new DataInstance({state, ...fields});
95
-
96
- mountModal({
97
- state,
98
- name: 'rebilly-instruments-approval-url',
99
- url: `${paymentMethodsUrl}/approval-url`,
100
- model,
101
- close: (updatedPurchase) => {
102
- Events.purchaseCompleted.dispatch(updatedPurchase);
88
+ const model = {};
89
+ if (state.data.isPayment) {
90
+ model.payment = fields;
91
+ } else {
92
+ model.purchase = fields;
103
93
  }
104
- });
94
+
95
+ state.data = new DataInstance({state, ...fields});
96
+
97
+ mountModal({
98
+ state,
99
+ name: 'rebilly-instruments-approval-url',
100
+ url: `${paymentMethodsUrl}/approval-url`,
101
+ model,
102
+ close: (updatedPurchase) => {
103
+ Events.purchaseCompleted.dispatch(updatedPurchase);
104
+ }
105
+ });
106
+ } else if (fields.transaction?.approvalUrl) {
107
+ window.location = fields.transaction?.approvalUrl
108
+ }
105
109
  }
106
110
 
107
111
  export async function purchase({ state, payload }) {
112
+ Object.keys(payload).forEach(key => {
113
+ if (payload[key] === null) {
114
+ delete payload[key];
115
+ }
116
+ });
117
+
108
118
  try {
109
119
  let fields;
110
120
  if (state.data.isPayment) {
@@ -114,7 +124,7 @@ export async function purchase({ state, payload }) {
114
124
  }
115
125
 
116
126
  if (fields.transaction?.approvalUrl && fields.transaction?.result === 'unknown') {
117
- handleApprovalUrl({state, fields});
127
+ handleApprovalUrl({state, fields, payload});
118
128
  } else {
119
129
  Events.purchaseCompleted.dispatch(fields);
120
130
  }
@@ -1,6 +1,8 @@
1
1
  import RebillyApi, {RebillyStorefrontAPI, RebillyExperimentalAPI} from 'rebilly-js-sdk';
2
2
  import { showError } from '../views/errors';
3
3
 
4
+ const TIMEOUT = 60000;
5
+
4
6
  export function validateStateForStorefront({state}) {
5
7
  if (!state.storefront) {
6
8
  throw new Error('Could not access rebilly-js-sdk instance');
@@ -31,7 +33,7 @@ export class StorefrontInstance {
31
33
  jwt = null,
32
34
  organizationId = null,
33
35
  mode = 'live',
34
- timeout = 10000,
36
+ timeout = TIMEOUT,
35
37
  liveUrl = null,
36
38
  sandboxUrl = null
37
39
  } = {}) {
@@ -44,7 +46,7 @@ export class StorefrontInstance {
44
46
  organizationId,
45
47
  sandbox: mode === 'sandbox',
46
48
  timeout: Number.isNaN(parseInt(timeout, 10))
47
- ? 10000
49
+ ? TIMEOUT
48
50
  : parseInt(timeout, 10),
49
51
  urls
50
52
  };
@@ -42,9 +42,10 @@ export async function fetchReadyToPay({
42
42
  }
43
43
 
44
44
  const { fields: readyToPayFields } = await state.storefront.purchase.readyToPay({ data });
45
+ const readyToPay = Object.values(readyToPayFields);
45
46
  const paymentMethodsMetadata = [...paymentMethodsFile];
46
47
 
47
- return Object.values(readyToPayFields)
48
+ return readyToPay
48
49
  // Remove result for "old" paypal method
49
50
  .filter((fields) => !(fields.method === 'paypal' && !fields.feature))
50
51
  // Remove Plaid payment method
@@ -1,6 +1,18 @@
1
- const SUPPORTED_EXPRESS_METHODS = ['Google Pay', 'Apple Pay', 'paypal'];
1
+ // TODO: Express methods should be filtered from RTP some how
2
+ export const SUPPORTED_EXPRESS_METHODS = [
3
+ 'Google Pay',
4
+ 'Apple Pay',
5
+ 'paypal',
6
+ ];
2
7
 
3
- export const SUPPORTED_METHODS = ['payment-card', 'ach', 'cryptocurrency'];
8
+ // TODO: Supported methods should be aimed to be not needed
9
+ // eventually moving to a BLOCKED_METHODS
10
+ export const SUPPORTED_METHODS = [
11
+ 'payment-card',
12
+ 'ach',
13
+ 'cryptocurrency',
14
+ 'bitcoin'
15
+ ];
4
16
 
5
17
  const isExpressMethod = ({ method, feature }) => (
6
18
  SUPPORTED_EXPRESS_METHODS.includes(method) ||
@@ -20,7 +20,7 @@ class TestInstance {
20
20
  filters: []
21
21
  }),
22
22
  new ReadyToPayModel({
23
- method: 'bitcoin',
23
+ method: 'fake-method',
24
24
  filters: []
25
25
  }),
26
26
  new ReadyToPayModel({
@@ -67,7 +67,12 @@ export async function mountModal({
67
67
  modalOverlay.classList.remove('is-visible');
68
68
  setTimeout(() => {
69
69
  document.body.style.overflow = 'auto';
70
- modalOverlay.children.forEach((child) => child.remove());
70
+
71
+ const list = modalOverlay.children;
72
+ for (let i = 0; i < list.length; i += 1) {
73
+ list[i].remove();
74
+ }
75
+
71
76
  modalOverlay.remove();
72
77
  close(...args);
73
78
  iframe.destroy();