@pelcro/react-pelcro-js 3.26.0-beta.61 → 3.26.0-beta.63

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
@@ -12087,7 +12087,8 @@ const loadPaymentSDKs = () => {
12087
12087
  window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/paypal-checkout.min.js", "braintree-paypal-sdk");
12088
12088
  }
12089
12089
  if (supportsBraintree) {
12090
- window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/hosted-fields.min.js", "braintree-histed-fields-sdk");
12090
+ window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/three-d-secure.min.js", "braintree-3D-secure-sdk");
12091
+ window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/hosted-fields.min.js", "braintree-hosted-fields-sdk");
12091
12092
  }
12092
12093
 
12093
12094
  // Load Vantiv SDKs
@@ -19231,61 +19232,174 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19231
19232
 
19232
19233
  /* ====== Start Braintree integration ======== */
19233
19234
  const braintreeInstanceRef = React__default['default'].useRef(null);
19234
- React.useEffect(() => {
19235
+ const braintree3DSecureInstanceRef = React__default['default'].useRef(null);
19236
+ function getClientToken() {
19237
+ return new Promise((resolve, reject) => {
19238
+ window.Pelcro.payment.generateClientToken({
19239
+ auth_token: window.Pelcro.user.read().auth_token,
19240
+ site_id: window.Pelcro.siteid
19241
+ }, (error, response) => {
19242
+ if (error) {
19243
+ reject(error);
19244
+ }
19245
+ if (response) {
19246
+ resolve(response.client_token);
19247
+ }
19248
+ });
19249
+ });
19250
+ }
19251
+ async function initializeBraintree() {
19235
19252
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
19236
19253
  if (cardProcessor === "braintree" && !selectedPaymentMethodId) {
19237
- var _window$Pelcro$site$r6;
19238
- const {
19239
- token: braintreeToken
19240
- } = (_window$Pelcro$site$r6 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r6 === void 0 ? void 0 : _window$Pelcro$site$r6.braintree_gateway_settings;
19254
+ const braintreeToken = await getClientToken();
19241
19255
  const isBraintreeEnabled = Boolean(braintreeToken);
19242
19256
  if (!isBraintreeEnabled) {
19243
19257
  console.error("Braintree integration is currently not enabled on this site's config");
19244
19258
  return;
19245
19259
  }
19246
- braintreeInstanceRef.current = new window.braintree.client.create({
19247
- authorization: braintreeToken
19248
- }).then(clientInstance => {
19249
- const options = {
19250
- client: clientInstance,
19251
- styles: {
19252
- input: {
19253
- "font-size": "14px"
19254
- },
19255
- "input.invalid": {
19256
- color: "red"
19260
+ if (type !== "updatePaymentSource") {
19261
+ braintreeInstanceRef.current = new window.braintree.client.create({
19262
+ authorization: braintreeToken
19263
+ }).then(clientInstance => {
19264
+ const options = {
19265
+ authorization: braintreeToken,
19266
+ styles: {
19267
+ input: {
19268
+ "font-size": "14px"
19269
+ },
19270
+ "input.invalid": {
19271
+ color: "red"
19272
+ },
19273
+ "input.valid": {
19274
+ color: "green"
19275
+ }
19257
19276
  },
19258
- "input.valid": {
19259
- color: "green"
19277
+ fields: {
19278
+ number: {
19279
+ container: "#card-number",
19280
+ placeholder: "4111 1111 1111 1111"
19281
+ },
19282
+ cvv: {
19283
+ container: "#cvv",
19284
+ placeholder: "123"
19285
+ },
19286
+ expirationDate: {
19287
+ container: "#expiration-date",
19288
+ placeholder: "10/2022"
19289
+ }
19260
19290
  }
19261
- },
19262
- fields: {
19263
- number: {
19264
- container: "#card-number",
19265
- placeholder: "4111 1111 1111 1111"
19266
- },
19267
- cvv: {
19268
- container: "#cvv",
19269
- placeholder: "123"
19291
+ };
19292
+ dispatch({
19293
+ type: SKELETON_LOADER,
19294
+ payload: true
19295
+ });
19296
+ braintree3DSecureInstanceRef.current = new window.braintree.threeDSecure.create({
19297
+ version: 2,
19298
+ authorization: braintreeToken
19299
+ }).then(threeDSecureInstance => {
19300
+ return threeDSecureInstance;
19301
+ });
19302
+ return window.braintree.hostedFields.create(options);
19303
+ });
19304
+ braintreeInstanceRef.current.then(hostedFieldInstance => {
19305
+ hostedFieldInstance.on("notEmpty", function (event) {
19306
+ const field = event.fields[event.emittedBy];
19307
+ if (field.isPotentiallyValid) {
19308
+ field.container.classList.remove("pelcro-input-invalid");
19309
+ }
19310
+ });
19311
+ hostedFieldInstance.on("validityChange", function (event) {
19312
+ const field = event.fields[event.emittedBy];
19313
+
19314
+ // Remove any previously applied error or warning classes
19315
+ field.container.classList.remove("is-valid");
19316
+ field.container.classList.remove("pelcro-input-invalid");
19317
+ if (field.isValid) {
19318
+ field.container.classList.add("is-valid");
19319
+ } else if (field.isPotentiallyValid) ; else {
19320
+ field.container.classList.add("pelcro-input-invalid");
19321
+ }
19322
+ });
19323
+ });
19324
+ } else if (type == "updatePaymentSource" && paymentMethodToEdit) {
19325
+ const {
19326
+ properties
19327
+ } = paymentMethodToEdit !== null && paymentMethodToEdit !== void 0 ? paymentMethodToEdit : {};
19328
+ const {
19329
+ exp_month: expMonth,
19330
+ exp_year: expYear
19331
+ } = properties !== null && properties !== void 0 ? properties : {};
19332
+ braintreeInstanceRef.current = new window.braintree.client.create({
19333
+ authorization: braintreeToken
19334
+ }).then(clientInstance => {
19335
+ const options = {
19336
+ client: clientInstance,
19337
+ styles: {
19338
+ input: {
19339
+ "font-size": "14px"
19340
+ },
19341
+ "input.invalid": {
19342
+ color: "red"
19343
+ },
19344
+ "input.valid": {
19345
+ color: "green"
19346
+ }
19270
19347
  },
19271
- expirationDate: {
19272
- container: "#expiration-date",
19273
- placeholder: "10/2022"
19348
+ fields: {
19349
+ expirationMonth: {
19350
+ container: "#expiration-month",
19351
+ prefill: expMonth
19352
+ },
19353
+ expirationYear: {
19354
+ container: "#expiration-year",
19355
+ prefill: expYear
19356
+ }
19274
19357
  }
19275
- }
19276
- };
19277
- dispatch({
19278
- type: SKELETON_LOADER,
19279
- payload: true
19358
+ };
19359
+ dispatch({
19360
+ type: SKELETON_LOADER,
19361
+ payload: true
19362
+ });
19363
+ return window.braintree.hostedFields.create(options);
19280
19364
  });
19281
- return window.braintree.hostedFields.create(options);
19282
- });
19365
+ braintreeInstanceRef.current.then(hostedFieldInstance => {
19366
+ hostedFieldInstance.on("notEmpty", function (event) {
19367
+ const field = event.fields[event.emittedBy];
19368
+ if (field.isPotentiallyValid) {
19369
+ field.container.classList.remove("pelcro-input-invalid");
19370
+ }
19371
+ });
19372
+ hostedFieldInstance.on("validityChange", function (event) {
19373
+ const field = event.fields[event.emittedBy];
19374
+
19375
+ // Remove any previously applied error or warning classes
19376
+ field.container.classList.remove("is-valid");
19377
+ field.container.classList.remove("pelcro-input-invalid");
19378
+ if (field.isValid) {
19379
+ field.container.classList.add("is-valid");
19380
+ } else if (field.isPotentiallyValid) ; else {
19381
+ field.container.classList.add("pelcro-input-invalid");
19382
+ }
19383
+ });
19384
+ });
19385
+ }
19283
19386
  }
19284
- }, [selectedPaymentMethodId]);
19387
+ }
19388
+ React.useEffect(() => {
19389
+ initializeBraintree();
19390
+ }, [selectedPaymentMethodId, paymentMethodToEdit]);
19285
19391
  const braintreeErrorHandler = tokenizeErr => {
19392
+ var _tokenizeErr$details, _tokenizeErr$details2;
19393
+ const cardNumber = document.querySelector("#card-number");
19394
+ const expirationDate = document.querySelector("#expiration-date");
19395
+ const cvv = document.querySelector("#cvv");
19396
+ const fields = tokenizeErr !== null && tokenizeErr !== void 0 && (_tokenizeErr$details = tokenizeErr.details) !== null && _tokenizeErr$details !== void 0 && _tokenizeErr$details.invalidFields ? Object.values(tokenizeErr === null || tokenizeErr === void 0 ? void 0 : (_tokenizeErr$details2 = tokenizeErr.details) === null || _tokenizeErr$details2 === void 0 ? void 0 : _tokenizeErr$details2.invalidFields) : null;
19286
19397
  switch (tokenizeErr.code) {
19287
19398
  case "HOSTED_FIELDS_FIELDS_EMPTY":
19288
19399
  // occurs when none of the fields are filled in
19400
+ cardNumber.classList.add("pelcro-input-invalid");
19401
+ expirationDate.classList.add("pelcro-input-invalid");
19402
+ cvv.classList.add("pelcro-input-invalid");
19289
19403
  return "All fields are empty! Please fill out the form.";
19290
19404
  // break;
19291
19405
  case "HOSTED_FIELDS_FIELDS_INVALID":
@@ -19298,6 +19412,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19298
19412
  // ) {
19299
19413
  // fieldContainer.className = "invalid";
19300
19414
  // });
19415
+ fields.forEach(field => {
19416
+ field.classList.add("pelcro-input-invalid");
19417
+ });
19301
19418
  return `Some fields are invalid: ${tokenizeErr.details.invalidFieldKeys.toString()}`;
19302
19419
  case "HOSTED_FIELDS_TOKENIZATION_FAIL_ON_DUPLICATE":
19303
19420
  // occurs when:
@@ -19328,6 +19445,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19328
19445
  }
19329
19446
  };
19330
19447
  const submitUsingBraintree = (state, dispatch) => {
19448
+ var _ref6, _ref7, _state$updatedPrice;
19331
19449
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
19332
19450
  if (isUsingExistingPaymentMethod) {
19333
19451
  // no need to create a new source using braintree
@@ -19336,6 +19454,22 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19336
19454
  if (!braintreeInstanceRef.current) {
19337
19455
  return console.error("Braintree sdk script wasn't loaded, you need to load braintree sdk before rendering the braintree payment flow");
19338
19456
  }
19457
+ const getOrderItemsTotal = () => {
19458
+ if (!order) {
19459
+ return null;
19460
+ }
19461
+ const isQuickPurchase = !Array.isArray(order);
19462
+ if (isQuickPurchase) {
19463
+ return order.price * order.quantity;
19464
+ }
19465
+ if (order.length === 0) {
19466
+ return null;
19467
+ }
19468
+ return order.reduce((total, item) => {
19469
+ return total + item.price * item.quantity;
19470
+ }, 0);
19471
+ };
19472
+ const totalAmount = (_ref6 = (_ref7 = (_state$updatedPrice = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice !== void 0 ? _state$updatedPrice : 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();
19339
19473
  braintreeInstanceRef.current.then(hostedFieldInstance => {
19340
19474
  hostedFieldInstance.tokenize((tokenizeErr, payload) => {
19341
19475
  if (tokenizeErr) {
@@ -19355,8 +19489,74 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19355
19489
  }
19356
19490
  });
19357
19491
  }
19358
- console.log(payload);
19359
- handleBraintreePayment(payload, state);
19492
+ if (type == "updatePaymentSource" || type == "deletePaymentSource") {
19493
+ handleBraintreePayment(payload, state);
19494
+ } else {
19495
+ braintree3DSecureInstanceRef.current.then(threeDSecureInstance => {
19496
+ threeDSecureInstance.verifyCard({
19497
+ onLookupComplete: function (data, next) {
19498
+ next();
19499
+ },
19500
+ amount: totalAmount !== null && totalAmount !== void 0 ? totalAmount : "0.00",
19501
+ nonce: payload.nonce,
19502
+ bin: payload.details.bin
19503
+ }).then(payload => {
19504
+ if (payload.liabilityShifted) {
19505
+ handleBraintreePayment(payload, state);
19506
+ } else if (payload.liabilityShiftPossible) {
19507
+ dispatch({
19508
+ type: DISABLE_SUBMIT,
19509
+ payload: false
19510
+ });
19511
+ dispatch({
19512
+ type: LOADING,
19513
+ payload: false
19514
+ });
19515
+ return dispatch({
19516
+ type: SHOW_ALERT,
19517
+ payload: {
19518
+ type: "error",
19519
+ content: "We encountered an issue verifying your transaction with 3D Secure, please try again."
19520
+ }
19521
+ });
19522
+ } else {
19523
+ // Liability has not shifted and will not shift
19524
+ dispatch({
19525
+ type: DISABLE_SUBMIT,
19526
+ payload: false
19527
+ });
19528
+ dispatch({
19529
+ type: LOADING,
19530
+ payload: false
19531
+ });
19532
+ return dispatch({
19533
+ type: SHOW_ALERT,
19534
+ payload: {
19535
+ type: "error",
19536
+ content: "We encountered an issue verifying your transaction with 3D Secure, please try another payment method."
19537
+ }
19538
+ });
19539
+ }
19540
+ }).catch(error => {
19541
+ console.error(error);
19542
+ dispatch({
19543
+ type: DISABLE_SUBMIT,
19544
+ payload: false
19545
+ });
19546
+ dispatch({
19547
+ type: LOADING,
19548
+ payload: false
19549
+ });
19550
+ return dispatch({
19551
+ type: SHOW_ALERT,
19552
+ payload: {
19553
+ type: "error",
19554
+ content: "There was a problem with your request."
19555
+ }
19556
+ });
19557
+ });
19558
+ });
19559
+ }
19360
19560
  });
19361
19561
  }).catch(error => {
19362
19562
  if (error) {
@@ -19880,9 +20080,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19880
20080
  React.useEffect(() => {
19881
20081
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
19882
20082
  if (cardProcessor === "vantiv" && !selectedPaymentMethodId) {
19883
- var _window$Pelcro$site$r7, _window$Pelcro$site$r8;
19884
- const payPageId = (_window$Pelcro$site$r7 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r7 === void 0 ? void 0 : _window$Pelcro$site$r7.vantiv_gateway_settings.pay_page_id;
19885
- const reportGroup = (_window$Pelcro$site$r8 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r8 === void 0 ? void 0 : _window$Pelcro$site$r8.vantiv_gateway_settings.report_group;
20083
+ var _window$Pelcro$site$r6, _window$Pelcro$site$r7;
20084
+ const payPageId = (_window$Pelcro$site$r6 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r6 === void 0 ? void 0 : _window$Pelcro$site$r6.vantiv_gateway_settings.pay_page_id;
20085
+ const reportGroup = (_window$Pelcro$site$r7 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r7 === void 0 ? void 0 : _window$Pelcro$site$r7.vantiv_gateway_settings.report_group;
19886
20086
  vantivInstanceRef.current = new window.EprotectIframeClient({
19887
20087
  paypageId: payPageId,
19888
20088
  reportGroup: reportGroup,
@@ -19960,13 +20160,13 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19960
20160
  });
19961
20161
 
19962
20162
  // When Google pay / Apple pay source created
19963
- paymentRequest.on("source", _ref6 => {
20163
+ paymentRequest.on("source", _ref8 => {
19964
20164
  var _source$card;
19965
20165
  let {
19966
20166
  complete,
19967
20167
  source,
19968
20168
  ...data
19969
- } = _ref6;
20169
+ } = _ref8;
19970
20170
  dispatch({
19971
20171
  type: DISABLE_COUPON_BUTTON,
19972
20172
  payload: true
@@ -19981,11 +20181,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19981
20181
  });
19982
20182
  complete("success");
19983
20183
  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") {
19984
- return generate3DSecureSource(source).then(_ref7 => {
20184
+ return generate3DSecureSource(source).then(_ref9 => {
19985
20185
  let {
19986
20186
  source,
19987
20187
  error
19988
- } = _ref7;
20188
+ } = _ref9;
19989
20189
  if (error) {
19990
20190
  handlePaymentError(error);
19991
20191
  fireBugSnag({
@@ -20021,9 +20221,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20021
20221
  * Updates the total amount after adding taxes only if site taxes are enabled
20022
20222
  */
20023
20223
  const updateTotalAmountWithTax = () => {
20024
- var _window$Pelcro$site$r9;
20224
+ var _window$Pelcro$site$r8;
20025
20225
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
20026
- const taxesEnabled = (_window$Pelcro$site$r9 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r9 === void 0 ? void 0 : _window$Pelcro$site$r9.taxes_enabled;
20226
+ const taxesEnabled = (_window$Pelcro$site$r8 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r8 === void 0 ? void 0 : _window$Pelcro$site$r8.taxes_enabled;
20027
20227
  if (taxesEnabled && type === "createPayment") {
20028
20228
  dispatch({
20029
20229
  type: DISABLE_SUBMIT,
@@ -20745,11 +20945,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20745
20945
  const createPaymentSource = (state, dispatch) => {
20746
20946
  return stripe.createSource({
20747
20947
  type: "card"
20748
- }).then(_ref8 => {
20948
+ }).then(_ref10 => {
20749
20949
  let {
20750
20950
  source,
20751
20951
  error
20752
- } = _ref8;
20952
+ } = _ref10;
20753
20953
  if (error) {
20754
20954
  return handlePaymentError(error);
20755
20955
  }
@@ -20863,11 +21063,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20863
21063
  } = paymentMethodToDelete;
20864
21064
  return stripe.createSource({
20865
21065
  type: "card"
20866
- }).then(_ref9 => {
21066
+ }).then(_ref11 => {
20867
21067
  let {
20868
21068
  source,
20869
21069
  error
20870
- } = _ref9;
21070
+ } = _ref11;
20871
21071
  if (error) {
20872
21072
  return handlePaymentError(error);
20873
21073
  }
@@ -21009,12 +21209,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
21009
21209
  }
21010
21210
  stripe.createSource({
21011
21211
  type: "card"
21012
- }).then(_ref10 => {
21013
- var _ref11, _ref12, _state$updatedPrice;
21212
+ }).then(_ref12 => {
21213
+ var _ref13, _ref14, _state$updatedPrice2;
21014
21214
  let {
21015
21215
  source,
21016
21216
  error
21017
- } = _ref10;
21217
+ } = _ref12;
21018
21218
  if (error) {
21019
21219
  return handlePaymentError(error);
21020
21220
  }
@@ -21033,7 +21233,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
21033
21233
  return total + item.price * item.quantity;
21034
21234
  }, 0);
21035
21235
  };
21036
- (_ref11 = (_ref12 = (_state$updatedPrice = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice !== void 0 ? _state$updatedPrice : 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();
21236
+ (_ref13 = (_ref14 = (_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 && _ref14 !== void 0 ? _ref14 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref13 !== void 0 ? _ref13 : getOrderItemsTotal();
21037
21237
  return handlePayment(source);
21038
21238
  }).catch(error => {
21039
21239
  return handlePaymentError(error);
@@ -21045,11 +21245,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
21045
21245
  * @return {Promise}
21046
21246
  */
21047
21247
  const resolveTaxCalculation = () => {
21048
- var _window$Pelcro$site$r10;
21248
+ var _window$Pelcro$site$r9;
21049
21249
  if (type === "invoicePayment") {
21050
21250
  return new Promise(resolve => resolve());
21051
21251
  }
21052
- const taxesEnabled = (_window$Pelcro$site$r10 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r10 === void 0 ? void 0 : _window$Pelcro$site$r10.taxes_enabled;
21252
+ const taxesEnabled = (_window$Pelcro$site$r9 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r9 === void 0 ? void 0 : _window$Pelcro$site$r9.taxes_enabled;
21053
21253
  return new Promise((resolve, reject) => {
21054
21254
  // resolve early if taxes isn't enabled
21055
21255
  if (!taxesEnabled) {
@@ -21724,35 +21924,60 @@ const CheckoutForm = _ref => {
21724
21924
  }))));
21725
21925
  }
21726
21926
  if (cardProcessor === "braintree") {
21927
+ if (type === "updatePaymentSource") {
21928
+ var _paymentMethodToEdit$;
21929
+ return /*#__PURE__*/React__default['default'].createElement("div", null, isSkeletonLoaded && paymentMethodToEdit ? /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
21930
+ htmlFor: "card-number"
21931
+ }, "Card Number *"), /*#__PURE__*/React__default['default'].createElement(Input, {
21932
+ id: "card-number",
21933
+ className: "plc-tracking-widest plc-flex-grow plc-h-12 plc-text-center",
21934
+ value: `•••• •••• •••• ${paymentMethodToEdit === null || paymentMethodToEdit === void 0 ? void 0 : (_paymentMethodToEdit$ = paymentMethodToEdit.properties) === null || _paymentMethodToEdit$ === void 0 ? void 0 : _paymentMethodToEdit$.last4}`,
21935
+ disabled: true
21936
+ }), /*#__PURE__*/React__default['default'].createElement("div", {
21937
+ className: "plc-flex plc-items-start plc-space-x-8 plc-my-6"
21938
+ }, /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
21939
+ htmlFor: "expiration-month"
21940
+ }, "Expiration Month *"), /*#__PURE__*/React__default['default'].createElement("div", {
21941
+ id: "expiration-month",
21942
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
21943
+ })), /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
21944
+ htmlFor: "expiration-year"
21945
+ }, "Expiration Year *"), /*#__PURE__*/React__default['default'].createElement("div", {
21946
+ id: "expiration-year",
21947
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
21948
+ })))) : /*#__PURE__*/React__default['default'].createElement("div", {
21949
+ className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
21950
+ }));
21951
+ }
21727
21952
  return /*#__PURE__*/React__default['default'].createElement("div", null, isSkeletonLoaded ? /*#__PURE__*/React__default['default'].createElement("div", {
21728
21953
  className: "plc-max-w-[50em]"
21729
21954
  }, /*#__PURE__*/React__default['default'].createElement("label", {
21730
21955
  htmlFor: "card-number"
21731
- }, "Card Number"), /*#__PURE__*/React__default['default'].createElement("div", {
21956
+ }, "Card Number *"), /*#__PURE__*/React__default['default'].createElement("div", {
21732
21957
  id: "card-number",
21733
21958
  className: "pelcro-input-field plc-h-12 plc-bg-white"
21734
21959
  }), /*#__PURE__*/React__default['default'].createElement("div", {
21735
- className: "plc-flex plc-items-start plc-space-x-3 plc-mb-4"
21960
+ className: "plc-flex plc-items-start plc-space-x-8 plc-my-6"
21736
21961
  }, /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
21737
21962
  htmlFor: "expiration-date"
21738
- }, "Expiration Date"), /*#__PURE__*/React__default['default'].createElement("div", {
21963
+ }, "Expiration Date *"), /*#__PURE__*/React__default['default'].createElement("div", {
21739
21964
  id: "expiration-date",
21740
21965
  className: "pelcro-input-field plc-h-12 plc-bg-white"
21741
21966
  })), /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
21742
21967
  htmlFor: "cvv"
21743
- }, "CVV"), /*#__PURE__*/React__default['default'].createElement("div", {
21968
+ }, "CVC *"), /*#__PURE__*/React__default['default'].createElement("div", {
21744
21969
  id: "cvv",
21745
21970
  className: "pelcro-input-field plc-h-12 plc-bg-white"
21746
21971
  })))) : /*#__PURE__*/React__default['default'].createElement("div", {
21747
- className: "plc-w-full plc-h-36 plc-bg-gray-300 plc-rounded plc-animate-pulse"
21972
+ className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
21748
21973
  }));
21749
21974
  }
21750
21975
  if (cardProcessor === "stripe") {
21751
21976
  if (type === "updatePaymentSource") {
21752
- var _paymentMethodToEdit$;
21977
+ var _paymentMethodToEdit$2;
21753
21978
  return /*#__PURE__*/React__default['default'].createElement("div", null, paymentMethodToEdit ? /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement(Input, {
21754
21979
  className: "plc-tracking-widest plc-flex-grow plc-text-center",
21755
- value: `•••• •••• •••• ${paymentMethodToEdit === null || paymentMethodToEdit === void 0 ? void 0 : (_paymentMethodToEdit$ = paymentMethodToEdit.properties) === null || _paymentMethodToEdit$ === void 0 ? void 0 : _paymentMethodToEdit$.last4}`,
21980
+ value: `•••• •••• •••• ${paymentMethodToEdit === null || paymentMethodToEdit === void 0 ? void 0 : (_paymentMethodToEdit$2 = paymentMethodToEdit.properties) === null || _paymentMethodToEdit$2 === void 0 ? void 0 : _paymentMethodToEdit$2.last4}`,
21756
21981
  disabled: true
21757
21982
  })) : /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement(Input, {
21758
21983
  className: "plc-bg-gray-300 plc-animate-pulse"
package/dist/index.esm.js CHANGED
@@ -12057,7 +12057,8 @@ const loadPaymentSDKs = () => {
12057
12057
  window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/paypal-checkout.min.js", "braintree-paypal-sdk");
12058
12058
  }
12059
12059
  if (supportsBraintree) {
12060
- window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/hosted-fields.min.js", "braintree-histed-fields-sdk");
12060
+ window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/three-d-secure.min.js", "braintree-3D-secure-sdk");
12061
+ window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/hosted-fields.min.js", "braintree-hosted-fields-sdk");
12061
12062
  }
12062
12063
 
12063
12064
  // Load Vantiv SDKs
@@ -19201,61 +19202,174 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19201
19202
 
19202
19203
  /* ====== Start Braintree integration ======== */
19203
19204
  const braintreeInstanceRef = React__default.useRef(null);
19204
- useEffect(() => {
19205
+ const braintree3DSecureInstanceRef = React__default.useRef(null);
19206
+ function getClientToken() {
19207
+ return new Promise((resolve, reject) => {
19208
+ window.Pelcro.payment.generateClientToken({
19209
+ auth_token: window.Pelcro.user.read().auth_token,
19210
+ site_id: window.Pelcro.siteid
19211
+ }, (error, response) => {
19212
+ if (error) {
19213
+ reject(error);
19214
+ }
19215
+ if (response) {
19216
+ resolve(response.client_token);
19217
+ }
19218
+ });
19219
+ });
19220
+ }
19221
+ async function initializeBraintree() {
19205
19222
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
19206
19223
  if (cardProcessor === "braintree" && !selectedPaymentMethodId) {
19207
- var _window$Pelcro$site$r6;
19208
- const {
19209
- token: braintreeToken
19210
- } = (_window$Pelcro$site$r6 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r6 === void 0 ? void 0 : _window$Pelcro$site$r6.braintree_gateway_settings;
19224
+ const braintreeToken = await getClientToken();
19211
19225
  const isBraintreeEnabled = Boolean(braintreeToken);
19212
19226
  if (!isBraintreeEnabled) {
19213
19227
  console.error("Braintree integration is currently not enabled on this site's config");
19214
19228
  return;
19215
19229
  }
19216
- braintreeInstanceRef.current = new window.braintree.client.create({
19217
- authorization: braintreeToken
19218
- }).then(clientInstance => {
19219
- const options = {
19220
- client: clientInstance,
19221
- styles: {
19222
- input: {
19223
- "font-size": "14px"
19224
- },
19225
- "input.invalid": {
19226
- color: "red"
19230
+ if (type !== "updatePaymentSource") {
19231
+ braintreeInstanceRef.current = new window.braintree.client.create({
19232
+ authorization: braintreeToken
19233
+ }).then(clientInstance => {
19234
+ const options = {
19235
+ authorization: braintreeToken,
19236
+ styles: {
19237
+ input: {
19238
+ "font-size": "14px"
19239
+ },
19240
+ "input.invalid": {
19241
+ color: "red"
19242
+ },
19243
+ "input.valid": {
19244
+ color: "green"
19245
+ }
19227
19246
  },
19228
- "input.valid": {
19229
- color: "green"
19247
+ fields: {
19248
+ number: {
19249
+ container: "#card-number",
19250
+ placeholder: "4111 1111 1111 1111"
19251
+ },
19252
+ cvv: {
19253
+ container: "#cvv",
19254
+ placeholder: "123"
19255
+ },
19256
+ expirationDate: {
19257
+ container: "#expiration-date",
19258
+ placeholder: "10/2022"
19259
+ }
19230
19260
  }
19231
- },
19232
- fields: {
19233
- number: {
19234
- container: "#card-number",
19235
- placeholder: "4111 1111 1111 1111"
19236
- },
19237
- cvv: {
19238
- container: "#cvv",
19239
- placeholder: "123"
19261
+ };
19262
+ dispatch({
19263
+ type: SKELETON_LOADER,
19264
+ payload: true
19265
+ });
19266
+ braintree3DSecureInstanceRef.current = new window.braintree.threeDSecure.create({
19267
+ version: 2,
19268
+ authorization: braintreeToken
19269
+ }).then(threeDSecureInstance => {
19270
+ return threeDSecureInstance;
19271
+ });
19272
+ return window.braintree.hostedFields.create(options);
19273
+ });
19274
+ braintreeInstanceRef.current.then(hostedFieldInstance => {
19275
+ hostedFieldInstance.on("notEmpty", function (event) {
19276
+ const field = event.fields[event.emittedBy];
19277
+ if (field.isPotentiallyValid) {
19278
+ field.container.classList.remove("pelcro-input-invalid");
19279
+ }
19280
+ });
19281
+ hostedFieldInstance.on("validityChange", function (event) {
19282
+ const field = event.fields[event.emittedBy];
19283
+
19284
+ // Remove any previously applied error or warning classes
19285
+ field.container.classList.remove("is-valid");
19286
+ field.container.classList.remove("pelcro-input-invalid");
19287
+ if (field.isValid) {
19288
+ field.container.classList.add("is-valid");
19289
+ } else if (field.isPotentiallyValid) ; else {
19290
+ field.container.classList.add("pelcro-input-invalid");
19291
+ }
19292
+ });
19293
+ });
19294
+ } else if (type == "updatePaymentSource" && paymentMethodToEdit) {
19295
+ const {
19296
+ properties
19297
+ } = paymentMethodToEdit !== null && paymentMethodToEdit !== void 0 ? paymentMethodToEdit : {};
19298
+ const {
19299
+ exp_month: expMonth,
19300
+ exp_year: expYear
19301
+ } = properties !== null && properties !== void 0 ? properties : {};
19302
+ braintreeInstanceRef.current = new window.braintree.client.create({
19303
+ authorization: braintreeToken
19304
+ }).then(clientInstance => {
19305
+ const options = {
19306
+ client: clientInstance,
19307
+ styles: {
19308
+ input: {
19309
+ "font-size": "14px"
19310
+ },
19311
+ "input.invalid": {
19312
+ color: "red"
19313
+ },
19314
+ "input.valid": {
19315
+ color: "green"
19316
+ }
19240
19317
  },
19241
- expirationDate: {
19242
- container: "#expiration-date",
19243
- placeholder: "10/2022"
19318
+ fields: {
19319
+ expirationMonth: {
19320
+ container: "#expiration-month",
19321
+ prefill: expMonth
19322
+ },
19323
+ expirationYear: {
19324
+ container: "#expiration-year",
19325
+ prefill: expYear
19326
+ }
19244
19327
  }
19245
- }
19246
- };
19247
- dispatch({
19248
- type: SKELETON_LOADER,
19249
- payload: true
19328
+ };
19329
+ dispatch({
19330
+ type: SKELETON_LOADER,
19331
+ payload: true
19332
+ });
19333
+ return window.braintree.hostedFields.create(options);
19250
19334
  });
19251
- return window.braintree.hostedFields.create(options);
19252
- });
19335
+ braintreeInstanceRef.current.then(hostedFieldInstance => {
19336
+ hostedFieldInstance.on("notEmpty", function (event) {
19337
+ const field = event.fields[event.emittedBy];
19338
+ if (field.isPotentiallyValid) {
19339
+ field.container.classList.remove("pelcro-input-invalid");
19340
+ }
19341
+ });
19342
+ hostedFieldInstance.on("validityChange", function (event) {
19343
+ const field = event.fields[event.emittedBy];
19344
+
19345
+ // Remove any previously applied error or warning classes
19346
+ field.container.classList.remove("is-valid");
19347
+ field.container.classList.remove("pelcro-input-invalid");
19348
+ if (field.isValid) {
19349
+ field.container.classList.add("is-valid");
19350
+ } else if (field.isPotentiallyValid) ; else {
19351
+ field.container.classList.add("pelcro-input-invalid");
19352
+ }
19353
+ });
19354
+ });
19355
+ }
19253
19356
  }
19254
- }, [selectedPaymentMethodId]);
19357
+ }
19358
+ useEffect(() => {
19359
+ initializeBraintree();
19360
+ }, [selectedPaymentMethodId, paymentMethodToEdit]);
19255
19361
  const braintreeErrorHandler = tokenizeErr => {
19362
+ var _tokenizeErr$details, _tokenizeErr$details2;
19363
+ const cardNumber = document.querySelector("#card-number");
19364
+ const expirationDate = document.querySelector("#expiration-date");
19365
+ const cvv = document.querySelector("#cvv");
19366
+ const fields = tokenizeErr !== null && tokenizeErr !== void 0 && (_tokenizeErr$details = tokenizeErr.details) !== null && _tokenizeErr$details !== void 0 && _tokenizeErr$details.invalidFields ? Object.values(tokenizeErr === null || tokenizeErr === void 0 ? void 0 : (_tokenizeErr$details2 = tokenizeErr.details) === null || _tokenizeErr$details2 === void 0 ? void 0 : _tokenizeErr$details2.invalidFields) : null;
19256
19367
  switch (tokenizeErr.code) {
19257
19368
  case "HOSTED_FIELDS_FIELDS_EMPTY":
19258
19369
  // occurs when none of the fields are filled in
19370
+ cardNumber.classList.add("pelcro-input-invalid");
19371
+ expirationDate.classList.add("pelcro-input-invalid");
19372
+ cvv.classList.add("pelcro-input-invalid");
19259
19373
  return "All fields are empty! Please fill out the form.";
19260
19374
  // break;
19261
19375
  case "HOSTED_FIELDS_FIELDS_INVALID":
@@ -19268,6 +19382,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19268
19382
  // ) {
19269
19383
  // fieldContainer.className = "invalid";
19270
19384
  // });
19385
+ fields.forEach(field => {
19386
+ field.classList.add("pelcro-input-invalid");
19387
+ });
19271
19388
  return `Some fields are invalid: ${tokenizeErr.details.invalidFieldKeys.toString()}`;
19272
19389
  case "HOSTED_FIELDS_TOKENIZATION_FAIL_ON_DUPLICATE":
19273
19390
  // occurs when:
@@ -19298,6 +19415,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19298
19415
  }
19299
19416
  };
19300
19417
  const submitUsingBraintree = (state, dispatch) => {
19418
+ var _ref6, _ref7, _state$updatedPrice;
19301
19419
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
19302
19420
  if (isUsingExistingPaymentMethod) {
19303
19421
  // no need to create a new source using braintree
@@ -19306,6 +19424,22 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19306
19424
  if (!braintreeInstanceRef.current) {
19307
19425
  return console.error("Braintree sdk script wasn't loaded, you need to load braintree sdk before rendering the braintree payment flow");
19308
19426
  }
19427
+ const getOrderItemsTotal = () => {
19428
+ if (!order) {
19429
+ return null;
19430
+ }
19431
+ const isQuickPurchase = !Array.isArray(order);
19432
+ if (isQuickPurchase) {
19433
+ return order.price * order.quantity;
19434
+ }
19435
+ if (order.length === 0) {
19436
+ return null;
19437
+ }
19438
+ return order.reduce((total, item) => {
19439
+ return total + item.price * item.quantity;
19440
+ }, 0);
19441
+ };
19442
+ const totalAmount = (_ref6 = (_ref7 = (_state$updatedPrice = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice !== void 0 ? _state$updatedPrice : 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();
19309
19443
  braintreeInstanceRef.current.then(hostedFieldInstance => {
19310
19444
  hostedFieldInstance.tokenize((tokenizeErr, payload) => {
19311
19445
  if (tokenizeErr) {
@@ -19325,8 +19459,74 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19325
19459
  }
19326
19460
  });
19327
19461
  }
19328
- console.log(payload);
19329
- handleBraintreePayment(payload, state);
19462
+ if (type == "updatePaymentSource" || type == "deletePaymentSource") {
19463
+ handleBraintreePayment(payload, state);
19464
+ } else {
19465
+ braintree3DSecureInstanceRef.current.then(threeDSecureInstance => {
19466
+ threeDSecureInstance.verifyCard({
19467
+ onLookupComplete: function (data, next) {
19468
+ next();
19469
+ },
19470
+ amount: totalAmount !== null && totalAmount !== void 0 ? totalAmount : "0.00",
19471
+ nonce: payload.nonce,
19472
+ bin: payload.details.bin
19473
+ }).then(payload => {
19474
+ if (payload.liabilityShifted) {
19475
+ handleBraintreePayment(payload, state);
19476
+ } else if (payload.liabilityShiftPossible) {
19477
+ dispatch({
19478
+ type: DISABLE_SUBMIT,
19479
+ payload: false
19480
+ });
19481
+ dispatch({
19482
+ type: LOADING,
19483
+ payload: false
19484
+ });
19485
+ return dispatch({
19486
+ type: SHOW_ALERT,
19487
+ payload: {
19488
+ type: "error",
19489
+ content: "We encountered an issue verifying your transaction with 3D Secure, please try again."
19490
+ }
19491
+ });
19492
+ } else {
19493
+ // Liability has not shifted and will not shift
19494
+ dispatch({
19495
+ type: DISABLE_SUBMIT,
19496
+ payload: false
19497
+ });
19498
+ dispatch({
19499
+ type: LOADING,
19500
+ payload: false
19501
+ });
19502
+ return dispatch({
19503
+ type: SHOW_ALERT,
19504
+ payload: {
19505
+ type: "error",
19506
+ content: "We encountered an issue verifying your transaction with 3D Secure, please try another payment method."
19507
+ }
19508
+ });
19509
+ }
19510
+ }).catch(error => {
19511
+ console.error(error);
19512
+ dispatch({
19513
+ type: DISABLE_SUBMIT,
19514
+ payload: false
19515
+ });
19516
+ dispatch({
19517
+ type: LOADING,
19518
+ payload: false
19519
+ });
19520
+ return dispatch({
19521
+ type: SHOW_ALERT,
19522
+ payload: {
19523
+ type: "error",
19524
+ content: "There was a problem with your request."
19525
+ }
19526
+ });
19527
+ });
19528
+ });
19529
+ }
19330
19530
  });
19331
19531
  }).catch(error => {
19332
19532
  if (error) {
@@ -19850,9 +20050,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19850
20050
  useEffect(() => {
19851
20051
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
19852
20052
  if (cardProcessor === "vantiv" && !selectedPaymentMethodId) {
19853
- var _window$Pelcro$site$r7, _window$Pelcro$site$r8;
19854
- const payPageId = (_window$Pelcro$site$r7 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r7 === void 0 ? void 0 : _window$Pelcro$site$r7.vantiv_gateway_settings.pay_page_id;
19855
- const reportGroup = (_window$Pelcro$site$r8 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r8 === void 0 ? void 0 : _window$Pelcro$site$r8.vantiv_gateway_settings.report_group;
20053
+ var _window$Pelcro$site$r6, _window$Pelcro$site$r7;
20054
+ const payPageId = (_window$Pelcro$site$r6 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r6 === void 0 ? void 0 : _window$Pelcro$site$r6.vantiv_gateway_settings.pay_page_id;
20055
+ const reportGroup = (_window$Pelcro$site$r7 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r7 === void 0 ? void 0 : _window$Pelcro$site$r7.vantiv_gateway_settings.report_group;
19856
20056
  vantivInstanceRef.current = new window.EprotectIframeClient({
19857
20057
  paypageId: payPageId,
19858
20058
  reportGroup: reportGroup,
@@ -19930,13 +20130,13 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19930
20130
  });
19931
20131
 
19932
20132
  // When Google pay / Apple pay source created
19933
- paymentRequest.on("source", _ref6 => {
20133
+ paymentRequest.on("source", _ref8 => {
19934
20134
  var _source$card;
19935
20135
  let {
19936
20136
  complete,
19937
20137
  source,
19938
20138
  ...data
19939
- } = _ref6;
20139
+ } = _ref8;
19940
20140
  dispatch({
19941
20141
  type: DISABLE_COUPON_BUTTON,
19942
20142
  payload: true
@@ -19951,11 +20151,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19951
20151
  });
19952
20152
  complete("success");
19953
20153
  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") {
19954
- return generate3DSecureSource(source).then(_ref7 => {
20154
+ return generate3DSecureSource(source).then(_ref9 => {
19955
20155
  let {
19956
20156
  source,
19957
20157
  error
19958
- } = _ref7;
20158
+ } = _ref9;
19959
20159
  if (error) {
19960
20160
  handlePaymentError(error);
19961
20161
  fireBugSnag({
@@ -19991,9 +20191,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19991
20191
  * Updates the total amount after adding taxes only if site taxes are enabled
19992
20192
  */
19993
20193
  const updateTotalAmountWithTax = () => {
19994
- var _window$Pelcro$site$r9;
20194
+ var _window$Pelcro$site$r8;
19995
20195
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
19996
- const taxesEnabled = (_window$Pelcro$site$r9 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r9 === void 0 ? void 0 : _window$Pelcro$site$r9.taxes_enabled;
20196
+ const taxesEnabled = (_window$Pelcro$site$r8 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r8 === void 0 ? void 0 : _window$Pelcro$site$r8.taxes_enabled;
19997
20197
  if (taxesEnabled && type === "createPayment") {
19998
20198
  dispatch({
19999
20199
  type: DISABLE_SUBMIT,
@@ -20715,11 +20915,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20715
20915
  const createPaymentSource = (state, dispatch) => {
20716
20916
  return stripe.createSource({
20717
20917
  type: "card"
20718
- }).then(_ref8 => {
20918
+ }).then(_ref10 => {
20719
20919
  let {
20720
20920
  source,
20721
20921
  error
20722
- } = _ref8;
20922
+ } = _ref10;
20723
20923
  if (error) {
20724
20924
  return handlePaymentError(error);
20725
20925
  }
@@ -20833,11 +21033,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20833
21033
  } = paymentMethodToDelete;
20834
21034
  return stripe.createSource({
20835
21035
  type: "card"
20836
- }).then(_ref9 => {
21036
+ }).then(_ref11 => {
20837
21037
  let {
20838
21038
  source,
20839
21039
  error
20840
- } = _ref9;
21040
+ } = _ref11;
20841
21041
  if (error) {
20842
21042
  return handlePaymentError(error);
20843
21043
  }
@@ -20979,12 +21179,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20979
21179
  }
20980
21180
  stripe.createSource({
20981
21181
  type: "card"
20982
- }).then(_ref10 => {
20983
- var _ref11, _ref12, _state$updatedPrice;
21182
+ }).then(_ref12 => {
21183
+ var _ref13, _ref14, _state$updatedPrice2;
20984
21184
  let {
20985
21185
  source,
20986
21186
  error
20987
- } = _ref10;
21187
+ } = _ref12;
20988
21188
  if (error) {
20989
21189
  return handlePaymentError(error);
20990
21190
  }
@@ -21003,7 +21203,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
21003
21203
  return total + item.price * item.quantity;
21004
21204
  }, 0);
21005
21205
  };
21006
- (_ref11 = (_ref12 = (_state$updatedPrice = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice !== void 0 ? _state$updatedPrice : 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();
21206
+ (_ref13 = (_ref14 = (_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 && _ref14 !== void 0 ? _ref14 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref13 !== void 0 ? _ref13 : getOrderItemsTotal();
21007
21207
  return handlePayment(source);
21008
21208
  }).catch(error => {
21009
21209
  return handlePaymentError(error);
@@ -21015,11 +21215,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
21015
21215
  * @return {Promise}
21016
21216
  */
21017
21217
  const resolveTaxCalculation = () => {
21018
- var _window$Pelcro$site$r10;
21218
+ var _window$Pelcro$site$r9;
21019
21219
  if (type === "invoicePayment") {
21020
21220
  return new Promise(resolve => resolve());
21021
21221
  }
21022
- const taxesEnabled = (_window$Pelcro$site$r10 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r10 === void 0 ? void 0 : _window$Pelcro$site$r10.taxes_enabled;
21222
+ const taxesEnabled = (_window$Pelcro$site$r9 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r9 === void 0 ? void 0 : _window$Pelcro$site$r9.taxes_enabled;
21023
21223
  return new Promise((resolve, reject) => {
21024
21224
  // resolve early if taxes isn't enabled
21025
21225
  if (!taxesEnabled) {
@@ -21694,35 +21894,60 @@ const CheckoutForm = _ref => {
21694
21894
  }))));
21695
21895
  }
21696
21896
  if (cardProcessor === "braintree") {
21897
+ if (type === "updatePaymentSource") {
21898
+ var _paymentMethodToEdit$;
21899
+ return /*#__PURE__*/React__default.createElement("div", null, isSkeletonLoaded && paymentMethodToEdit ? /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("label", {
21900
+ htmlFor: "card-number"
21901
+ }, "Card Number *"), /*#__PURE__*/React__default.createElement(Input, {
21902
+ id: "card-number",
21903
+ className: "plc-tracking-widest plc-flex-grow plc-h-12 plc-text-center",
21904
+ value: `•••• •••• •••• ${paymentMethodToEdit === null || paymentMethodToEdit === void 0 ? void 0 : (_paymentMethodToEdit$ = paymentMethodToEdit.properties) === null || _paymentMethodToEdit$ === void 0 ? void 0 : _paymentMethodToEdit$.last4}`,
21905
+ disabled: true
21906
+ }), /*#__PURE__*/React__default.createElement("div", {
21907
+ className: "plc-flex plc-items-start plc-space-x-8 plc-my-6"
21908
+ }, /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("label", {
21909
+ htmlFor: "expiration-month"
21910
+ }, "Expiration Month *"), /*#__PURE__*/React__default.createElement("div", {
21911
+ id: "expiration-month",
21912
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
21913
+ })), /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("label", {
21914
+ htmlFor: "expiration-year"
21915
+ }, "Expiration Year *"), /*#__PURE__*/React__default.createElement("div", {
21916
+ id: "expiration-year",
21917
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
21918
+ })))) : /*#__PURE__*/React__default.createElement("div", {
21919
+ className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
21920
+ }));
21921
+ }
21697
21922
  return /*#__PURE__*/React__default.createElement("div", null, isSkeletonLoaded ? /*#__PURE__*/React__default.createElement("div", {
21698
21923
  className: "plc-max-w-[50em]"
21699
21924
  }, /*#__PURE__*/React__default.createElement("label", {
21700
21925
  htmlFor: "card-number"
21701
- }, "Card Number"), /*#__PURE__*/React__default.createElement("div", {
21926
+ }, "Card Number *"), /*#__PURE__*/React__default.createElement("div", {
21702
21927
  id: "card-number",
21703
21928
  className: "pelcro-input-field plc-h-12 plc-bg-white"
21704
21929
  }), /*#__PURE__*/React__default.createElement("div", {
21705
- className: "plc-flex plc-items-start plc-space-x-3 plc-mb-4"
21930
+ className: "plc-flex plc-items-start plc-space-x-8 plc-my-6"
21706
21931
  }, /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("label", {
21707
21932
  htmlFor: "expiration-date"
21708
- }, "Expiration Date"), /*#__PURE__*/React__default.createElement("div", {
21933
+ }, "Expiration Date *"), /*#__PURE__*/React__default.createElement("div", {
21709
21934
  id: "expiration-date",
21710
21935
  className: "pelcro-input-field plc-h-12 plc-bg-white"
21711
21936
  })), /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("label", {
21712
21937
  htmlFor: "cvv"
21713
- }, "CVV"), /*#__PURE__*/React__default.createElement("div", {
21938
+ }, "CVC *"), /*#__PURE__*/React__default.createElement("div", {
21714
21939
  id: "cvv",
21715
21940
  className: "pelcro-input-field plc-h-12 plc-bg-white"
21716
21941
  })))) : /*#__PURE__*/React__default.createElement("div", {
21717
- className: "plc-w-full plc-h-36 plc-bg-gray-300 plc-rounded plc-animate-pulse"
21942
+ className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
21718
21943
  }));
21719
21944
  }
21720
21945
  if (cardProcessor === "stripe") {
21721
21946
  if (type === "updatePaymentSource") {
21722
- var _paymentMethodToEdit$;
21947
+ var _paymentMethodToEdit$2;
21723
21948
  return /*#__PURE__*/React__default.createElement("div", null, paymentMethodToEdit ? /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(Input, {
21724
21949
  className: "plc-tracking-widest plc-flex-grow plc-text-center",
21725
- value: `•••• •••• •••• ${paymentMethodToEdit === null || paymentMethodToEdit === void 0 ? void 0 : (_paymentMethodToEdit$ = paymentMethodToEdit.properties) === null || _paymentMethodToEdit$ === void 0 ? void 0 : _paymentMethodToEdit$.last4}`,
21950
+ value: `•••• •••• •••• ${paymentMethodToEdit === null || paymentMethodToEdit === void 0 ? void 0 : (_paymentMethodToEdit$2 = paymentMethodToEdit.properties) === null || _paymentMethodToEdit$2 === void 0 ? void 0 : _paymentMethodToEdit$2.last4}`,
21726
21951
  disabled: true
21727
21952
  })) : /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(Input, {
21728
21953
  className: "plc-bg-gray-300 plc-animate-pulse"
package/dist/pelcro.css CHANGED
@@ -1774,6 +1774,12 @@ apple-pay-button {
1774
1774
  margin-bottom: calc(1rem * var(--tw-space-y-reverse));
1775
1775
  }
1776
1776
 
1777
+ .pelcro-root .plc-space-x-8 > :not([hidden]) ~ :not([hidden]) {
1778
+ --tw-space-x-reverse: 0;
1779
+ margin-right: calc(2rem * var(--tw-space-x-reverse));
1780
+ margin-left: calc(2rem * calc(1 - var(--tw-space-x-reverse)));
1781
+ }
1782
+
1777
1783
  .pelcro-root .plc-appearance-none {
1778
1784
  -webkit-appearance: none;
1779
1785
  appearance: none;
@@ -2211,6 +2217,10 @@ apple-pay-button {
2211
2217
  height: 9rem;
2212
2218
  }
2213
2219
 
2220
+ .pelcro-root .plc-h-40 {
2221
+ height: 10rem;
2222
+ }
2223
+
2214
2224
  .pelcro-root .plc-h-52 {
2215
2225
  height: 13rem;
2216
2226
  }
@@ -2298,6 +2308,11 @@ apple-pay-button {
2298
2308
  margin-bottom: 1rem;
2299
2309
  }
2300
2310
 
2311
+ .pelcro-root .plc-my-6 {
2312
+ margin-top: 1.5rem;
2313
+ margin-bottom: 1.5rem;
2314
+ }
2315
+
2301
2316
  .pelcro-root .plc-my-auto {
2302
2317
  margin-top: auto;
2303
2318
  margin-bottom: auto;
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.26.0-beta.61",
4
+ "version": "3.26.0-beta.63",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",