@pelcro/react-pelcro-js 3.40.0 → 3.41.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/dist/index.cjs.js CHANGED
@@ -11768,7 +11768,10 @@ const loadPaymentSDKs = () => {
11768
11768
  window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/paypal-checkout.min.js", "braintree-paypal-sdk");
11769
11769
  }
11770
11770
  if (supportsBraintree) {
11771
- window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/three-d-secure.min.js", "braintree-3D-secure-sdk");
11771
+ // window.Pelcro.helpers.loadSDK(
11772
+ // "https://js.braintreegateway.com/web/3.99.0/js/three-d-secure.min.js",
11773
+ // "braintree-3D-secure-sdk"
11774
+ // );
11772
11775
  window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/hosted-fields.min.js", "braintree-hosted-fields-sdk");
11773
11776
  }
11774
11777
 
@@ -18302,7 +18305,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18302
18305
 
18303
18306
  /* ====== Start Braintree integration ======== */
18304
18307
  const braintreeInstanceRef = React__default['default'].useRef(null);
18305
- const braintree3DSecureInstanceRef = React__default['default'].useRef(null);
18306
18308
  function getClientToken() {
18307
18309
  return new Promise((resolve, reject) => {
18308
18310
  window.Pelcro.payment.generateClientToken({
@@ -18363,12 +18365,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18363
18365
  type: SKELETON_LOADER,
18364
18366
  payload: true
18365
18367
  });
18366
- braintree3DSecureInstanceRef.current = new window.braintree.threeDSecure.create({
18367
- version: 2,
18368
- authorization: braintreeToken
18369
- }).then(threeDSecureInstance => {
18370
- return threeDSecureInstance;
18371
- });
18372
18368
  return window.braintree.hostedFields.create(options);
18373
18369
  });
18374
18370
  braintreeInstanceRef.current.then(hostedFieldInstance => {
@@ -18515,7 +18511,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18515
18511
  }
18516
18512
  };
18517
18513
  const submitUsingBraintree = (state, dispatch) => {
18518
- var _ref6, _ref7, _state$updatedPrice2;
18519
18514
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18520
18515
  if (isUsingExistingPaymentMethod) {
18521
18516
  // no need to create a new source using braintree
@@ -18524,22 +18519,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18524
18519
  if (!braintreeInstanceRef.current) {
18525
18520
  return console.error("Braintree sdk script wasn't loaded, you need to load braintree sdk before rendering the braintree payment flow");
18526
18521
  }
18527
- const getOrderItemsTotal = () => {
18528
- if (!order) {
18529
- return null;
18530
- }
18531
- const isQuickPurchase = !Array.isArray(order);
18532
- if (isQuickPurchase) {
18533
- return order.price * order.quantity;
18534
- }
18535
- if (order.length === 0) {
18536
- return null;
18537
- }
18538
- return order.reduce((total, item) => {
18539
- return total + item.price * item.quantity;
18540
- }, 0);
18541
- };
18542
- const totalAmount = (_ref6 = (_ref7 = (_state$updatedPrice2 = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice2 !== void 0 ? _state$updatedPrice2 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref7 !== void 0 ? _ref7 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref6 !== void 0 ? _ref6 : getOrderItemsTotal();
18543
18522
  braintreeInstanceRef.current.then(hostedFieldInstance => {
18544
18523
  hostedFieldInstance.tokenize((tokenizeErr, payload) => {
18545
18524
  if (tokenizeErr) {
@@ -18559,79 +18538,28 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18559
18538
  }
18560
18539
  });
18561
18540
  }
18562
- if (type == "updatePaymentSource" || type == "deletePaymentSource") {
18563
- handleBraintreePayment(payload, state.couponCode);
18564
- } else {
18565
- braintree3DSecureInstanceRef.current.then(threeDSecureInstance => {
18566
- threeDSecureInstance.verifyCard({
18567
- onLookupComplete: function (data, next) {
18568
- next();
18569
- },
18570
- amount: totalAmount !== null && totalAmount !== void 0 ? totalAmount : "0.00",
18571
- nonce: payload.nonce,
18572
- bin: payload.details.bin
18573
- }).then(payload => {
18574
- if (payload.liabilityShifted) {
18575
- handleBraintreePayment(payload, state.couponCode);
18576
- } else if (payload.liabilityShiftPossible) {
18577
- dispatch({
18578
- type: DISABLE_SUBMIT,
18579
- payload: false
18580
- });
18581
- dispatch({
18582
- type: LOADING,
18583
- payload: false
18584
- });
18585
- return dispatch({
18586
- type: SHOW_ALERT,
18587
- payload: {
18588
- type: "error",
18589
- content: "We encountered an issue verifying your transaction with 3D Secure, please try again."
18590
- }
18591
- });
18592
- } else {
18593
- // Liability has not shifted and will not shift
18594
- dispatch({
18595
- type: DISABLE_SUBMIT,
18596
- payload: false
18597
- });
18598
- dispatch({
18599
- type: LOADING,
18600
- payload: false
18601
- });
18602
- return dispatch({
18603
- type: SHOW_ALERT,
18604
- payload: {
18605
- type: "error",
18606
- content: "We encountered an issue verifying your transaction with 3D Secure, please try another payment method."
18607
- }
18608
- });
18609
- }
18610
- }).catch(error => {
18611
- console.error(error);
18612
- dispatch({
18613
- type: DISABLE_SUBMIT,
18614
- payload: false
18615
- });
18616
- dispatch({
18617
- type: LOADING,
18618
- payload: false
18619
- });
18620
- return dispatch({
18621
- type: SHOW_ALERT,
18622
- payload: {
18623
- type: "error",
18624
- content: "There was a problem with your request."
18625
- }
18626
- });
18627
- });
18628
- });
18629
- }
18541
+
18542
+ // Directly handle the payment with the tokenized payload
18543
+ handleBraintreePayment(payload, state.couponCode);
18630
18544
  });
18631
18545
  }).catch(error => {
18632
18546
  if (error) {
18633
18547
  console.error(error);
18634
- return;
18548
+ dispatch({
18549
+ type: DISABLE_SUBMIT,
18550
+ payload: false
18551
+ });
18552
+ dispatch({
18553
+ type: LOADING,
18554
+ payload: false
18555
+ });
18556
+ return dispatch({
18557
+ type: SHOW_ALERT,
18558
+ payload: {
18559
+ type: "error",
18560
+ content: "There was a problem with your request."
18561
+ }
18562
+ });
18635
18563
  }
18636
18564
  });
18637
18565
  };
@@ -19222,13 +19150,13 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19222
19150
  });
19223
19151
 
19224
19152
  // When Google pay / Apple pay source created
19225
- paymentRequest.on("source", _ref8 => {
19153
+ paymentRequest.on("source", _ref6 => {
19226
19154
  var _source$card;
19227
19155
  let {
19228
19156
  complete,
19229
19157
  source,
19230
19158
  ...data
19231
- } = _ref8;
19159
+ } = _ref6;
19232
19160
  dispatch({
19233
19161
  type: DISABLE_COUPON_BUTTON,
19234
19162
  payload: true
@@ -19243,11 +19171,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19243
19171
  });
19244
19172
  complete("success");
19245
19173
  if ((source === null || source === void 0 ? void 0 : (_source$card = source.card) === null || _source$card === void 0 ? void 0 : _source$card.three_d_secure) === "required") {
19246
- return generate3DSecureSource(source).then(_ref9 => {
19174
+ return generate3DSecureSource(source).then(_ref7 => {
19247
19175
  let {
19248
19176
  source,
19249
19177
  error
19250
- } = _ref9;
19178
+ } = _ref7;
19251
19179
  if (error) {
19252
19180
  return handlePaymentError(error);
19253
19181
  }
@@ -19964,11 +19892,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19964
19892
  const createPaymentSource = (state, dispatch) => {
19965
19893
  return stripe.createSource({
19966
19894
  type: "card"
19967
- }).then(_ref10 => {
19895
+ }).then(_ref8 => {
19968
19896
  let {
19969
19897
  source,
19970
19898
  error
19971
- } = _ref10;
19899
+ } = _ref8;
19972
19900
  if (error) {
19973
19901
  return handlePaymentError(error);
19974
19902
  }
@@ -20082,11 +20010,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20082
20010
  } = paymentMethodToDelete;
20083
20011
  return stripe.createSource({
20084
20012
  type: "card"
20085
- }).then(_ref11 => {
20013
+ }).then(_ref9 => {
20086
20014
  let {
20087
20015
  source,
20088
20016
  error
20089
- } = _ref11;
20017
+ } = _ref9;
20090
20018
  if (error) {
20091
20019
  return handlePaymentError(error);
20092
20020
  }
@@ -20184,12 +20112,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20184
20112
  }
20185
20113
  stripe.createSource({
20186
20114
  type: "card"
20187
- }).then(_ref12 => {
20188
- var _ref13, _ref14, _state$updatedPrice3;
20115
+ }).then(_ref10 => {
20116
+ var _ref11, _ref12, _state$updatedPrice2;
20189
20117
  let {
20190
20118
  source,
20191
20119
  error
20192
- } = _ref12;
20120
+ } = _ref10;
20193
20121
  if (error) {
20194
20122
  return handlePaymentError(error);
20195
20123
  }
@@ -20208,7 +20136,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20208
20136
  return total + item.price * item.quantity;
20209
20137
  }, 0);
20210
20138
  };
20211
- (_ref13 = (_ref14 = (_state$updatedPrice3 = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice3 !== void 0 ? _state$updatedPrice3 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref14 !== void 0 ? _ref14 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref13 !== void 0 ? _ref13 : getOrderItemsTotal();
20139
+ (_ref11 = (_ref12 = (_state$updatedPrice2 = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice2 !== void 0 ? _state$updatedPrice2 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref12 !== void 0 ? _ref12 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref11 !== void 0 ? _ref11 : getOrderItemsTotal();
20212
20140
  return handlePayment(source);
20213
20141
  }).catch(error => {
20214
20142
  return handlePaymentError(error);
package/dist/index.esm.js CHANGED
@@ -11738,7 +11738,10 @@ const loadPaymentSDKs = () => {
11738
11738
  window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/paypal-checkout.min.js", "braintree-paypal-sdk");
11739
11739
  }
11740
11740
  if (supportsBraintree) {
11741
- window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/three-d-secure.min.js", "braintree-3D-secure-sdk");
11741
+ // window.Pelcro.helpers.loadSDK(
11742
+ // "https://js.braintreegateway.com/web/3.99.0/js/three-d-secure.min.js",
11743
+ // "braintree-3D-secure-sdk"
11744
+ // );
11742
11745
  window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/hosted-fields.min.js", "braintree-hosted-fields-sdk");
11743
11746
  }
11744
11747
 
@@ -18272,7 +18275,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18272
18275
 
18273
18276
  /* ====== Start Braintree integration ======== */
18274
18277
  const braintreeInstanceRef = React__default.useRef(null);
18275
- const braintree3DSecureInstanceRef = React__default.useRef(null);
18276
18278
  function getClientToken() {
18277
18279
  return new Promise((resolve, reject) => {
18278
18280
  window.Pelcro.payment.generateClientToken({
@@ -18333,12 +18335,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18333
18335
  type: SKELETON_LOADER,
18334
18336
  payload: true
18335
18337
  });
18336
- braintree3DSecureInstanceRef.current = new window.braintree.threeDSecure.create({
18337
- version: 2,
18338
- authorization: braintreeToken
18339
- }).then(threeDSecureInstance => {
18340
- return threeDSecureInstance;
18341
- });
18342
18338
  return window.braintree.hostedFields.create(options);
18343
18339
  });
18344
18340
  braintreeInstanceRef.current.then(hostedFieldInstance => {
@@ -18485,7 +18481,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18485
18481
  }
18486
18482
  };
18487
18483
  const submitUsingBraintree = (state, dispatch) => {
18488
- var _ref6, _ref7, _state$updatedPrice2;
18489
18484
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18490
18485
  if (isUsingExistingPaymentMethod) {
18491
18486
  // no need to create a new source using braintree
@@ -18494,22 +18489,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18494
18489
  if (!braintreeInstanceRef.current) {
18495
18490
  return console.error("Braintree sdk script wasn't loaded, you need to load braintree sdk before rendering the braintree payment flow");
18496
18491
  }
18497
- const getOrderItemsTotal = () => {
18498
- if (!order) {
18499
- return null;
18500
- }
18501
- const isQuickPurchase = !Array.isArray(order);
18502
- if (isQuickPurchase) {
18503
- return order.price * order.quantity;
18504
- }
18505
- if (order.length === 0) {
18506
- return null;
18507
- }
18508
- return order.reduce((total, item) => {
18509
- return total + item.price * item.quantity;
18510
- }, 0);
18511
- };
18512
- const totalAmount = (_ref6 = (_ref7 = (_state$updatedPrice2 = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice2 !== void 0 ? _state$updatedPrice2 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref7 !== void 0 ? _ref7 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref6 !== void 0 ? _ref6 : getOrderItemsTotal();
18513
18492
  braintreeInstanceRef.current.then(hostedFieldInstance => {
18514
18493
  hostedFieldInstance.tokenize((tokenizeErr, payload) => {
18515
18494
  if (tokenizeErr) {
@@ -18529,79 +18508,28 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18529
18508
  }
18530
18509
  });
18531
18510
  }
18532
- if (type == "updatePaymentSource" || type == "deletePaymentSource") {
18533
- handleBraintreePayment(payload, state.couponCode);
18534
- } else {
18535
- braintree3DSecureInstanceRef.current.then(threeDSecureInstance => {
18536
- threeDSecureInstance.verifyCard({
18537
- onLookupComplete: function (data, next) {
18538
- next();
18539
- },
18540
- amount: totalAmount !== null && totalAmount !== void 0 ? totalAmount : "0.00",
18541
- nonce: payload.nonce,
18542
- bin: payload.details.bin
18543
- }).then(payload => {
18544
- if (payload.liabilityShifted) {
18545
- handleBraintreePayment(payload, state.couponCode);
18546
- } else if (payload.liabilityShiftPossible) {
18547
- dispatch({
18548
- type: DISABLE_SUBMIT,
18549
- payload: false
18550
- });
18551
- dispatch({
18552
- type: LOADING,
18553
- payload: false
18554
- });
18555
- return dispatch({
18556
- type: SHOW_ALERT,
18557
- payload: {
18558
- type: "error",
18559
- content: "We encountered an issue verifying your transaction with 3D Secure, please try again."
18560
- }
18561
- });
18562
- } else {
18563
- // Liability has not shifted and will not shift
18564
- dispatch({
18565
- type: DISABLE_SUBMIT,
18566
- payload: false
18567
- });
18568
- dispatch({
18569
- type: LOADING,
18570
- payload: false
18571
- });
18572
- return dispatch({
18573
- type: SHOW_ALERT,
18574
- payload: {
18575
- type: "error",
18576
- content: "We encountered an issue verifying your transaction with 3D Secure, please try another payment method."
18577
- }
18578
- });
18579
- }
18580
- }).catch(error => {
18581
- console.error(error);
18582
- dispatch({
18583
- type: DISABLE_SUBMIT,
18584
- payload: false
18585
- });
18586
- dispatch({
18587
- type: LOADING,
18588
- payload: false
18589
- });
18590
- return dispatch({
18591
- type: SHOW_ALERT,
18592
- payload: {
18593
- type: "error",
18594
- content: "There was a problem with your request."
18595
- }
18596
- });
18597
- });
18598
- });
18599
- }
18511
+
18512
+ // Directly handle the payment with the tokenized payload
18513
+ handleBraintreePayment(payload, state.couponCode);
18600
18514
  });
18601
18515
  }).catch(error => {
18602
18516
  if (error) {
18603
18517
  console.error(error);
18604
- return;
18518
+ dispatch({
18519
+ type: DISABLE_SUBMIT,
18520
+ payload: false
18521
+ });
18522
+ dispatch({
18523
+ type: LOADING,
18524
+ payload: false
18525
+ });
18526
+ return dispatch({
18527
+ type: SHOW_ALERT,
18528
+ payload: {
18529
+ type: "error",
18530
+ content: "There was a problem with your request."
18531
+ }
18532
+ });
18605
18533
  }
18606
18534
  });
18607
18535
  };
@@ -19192,13 +19120,13 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19192
19120
  });
19193
19121
 
19194
19122
  // When Google pay / Apple pay source created
19195
- paymentRequest.on("source", _ref8 => {
19123
+ paymentRequest.on("source", _ref6 => {
19196
19124
  var _source$card;
19197
19125
  let {
19198
19126
  complete,
19199
19127
  source,
19200
19128
  ...data
19201
- } = _ref8;
19129
+ } = _ref6;
19202
19130
  dispatch({
19203
19131
  type: DISABLE_COUPON_BUTTON,
19204
19132
  payload: true
@@ -19213,11 +19141,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19213
19141
  });
19214
19142
  complete("success");
19215
19143
  if ((source === null || source === void 0 ? void 0 : (_source$card = source.card) === null || _source$card === void 0 ? void 0 : _source$card.three_d_secure) === "required") {
19216
- return generate3DSecureSource(source).then(_ref9 => {
19144
+ return generate3DSecureSource(source).then(_ref7 => {
19217
19145
  let {
19218
19146
  source,
19219
19147
  error
19220
- } = _ref9;
19148
+ } = _ref7;
19221
19149
  if (error) {
19222
19150
  return handlePaymentError(error);
19223
19151
  }
@@ -19934,11 +19862,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19934
19862
  const createPaymentSource = (state, dispatch) => {
19935
19863
  return stripe.createSource({
19936
19864
  type: "card"
19937
- }).then(_ref10 => {
19865
+ }).then(_ref8 => {
19938
19866
  let {
19939
19867
  source,
19940
19868
  error
19941
- } = _ref10;
19869
+ } = _ref8;
19942
19870
  if (error) {
19943
19871
  return handlePaymentError(error);
19944
19872
  }
@@ -20052,11 +19980,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20052
19980
  } = paymentMethodToDelete;
20053
19981
  return stripe.createSource({
20054
19982
  type: "card"
20055
- }).then(_ref11 => {
19983
+ }).then(_ref9 => {
20056
19984
  let {
20057
19985
  source,
20058
19986
  error
20059
- } = _ref11;
19987
+ } = _ref9;
20060
19988
  if (error) {
20061
19989
  return handlePaymentError(error);
20062
19990
  }
@@ -20154,12 +20082,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20154
20082
  }
20155
20083
  stripe.createSource({
20156
20084
  type: "card"
20157
- }).then(_ref12 => {
20158
- var _ref13, _ref14, _state$updatedPrice3;
20085
+ }).then(_ref10 => {
20086
+ var _ref11, _ref12, _state$updatedPrice2;
20159
20087
  let {
20160
20088
  source,
20161
20089
  error
20162
- } = _ref12;
20090
+ } = _ref10;
20163
20091
  if (error) {
20164
20092
  return handlePaymentError(error);
20165
20093
  }
@@ -20178,7 +20106,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20178
20106
  return total + item.price * item.quantity;
20179
20107
  }, 0);
20180
20108
  };
20181
- (_ref13 = (_ref14 = (_state$updatedPrice3 = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice3 !== void 0 ? _state$updatedPrice3 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref14 !== void 0 ? _ref14 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref13 !== void 0 ? _ref13 : getOrderItemsTotal();
20109
+ (_ref11 = (_ref12 = (_state$updatedPrice2 = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice2 !== void 0 ? _state$updatedPrice2 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref12 !== void 0 ? _ref12 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref11 !== void 0 ? _ref11 : getOrderItemsTotal();
20182
20110
  return handlePayment(source);
20183
20111
  }).catch(error => {
20184
20112
  return handlePaymentError(error);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pelcro/react-pelcro-js",
3
3
  "description": "Pelcro's React UI Elements",
4
- "version": "3.40.0",
4
+ "version": "3.41.0",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",