@pelcro/react-pelcro-js 3.37.0 → 3.39.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
@@ -11635,8 +11635,8 @@ const debounce = (func, waitTime) => {
11635
11635
  timeout = setTimeout(later, waitTime);
11636
11636
  };
11637
11637
  };
11638
- function getSiteCardProcessor() {
11639
- var _window$Pelcro$site$r, _window$Pelcro$site$r2, _window$Pelcro$site$r3;
11638
+ function getSiteCardProcessor$1() {
11639
+ var _window$Pelcro$site$r, _window$Pelcro$site$r2, _window$Pelcro$site$r3, _window$Pelcro$site$r4;
11640
11640
  if ((_window$Pelcro$site$r = window.Pelcro.site.read()) !== null && _window$Pelcro$site$r !== void 0 && _window$Pelcro$site$r.vantiv_gateway_settings) {
11641
11641
  return "vantiv";
11642
11642
  }
@@ -11646,6 +11646,9 @@ function getSiteCardProcessor() {
11646
11646
  if ((_window$Pelcro$site$r3 = window.Pelcro.site.read()) !== null && _window$Pelcro$site$r3 !== void 0 && _window$Pelcro$site$r3.cybersource_gateway_settings) {
11647
11647
  return "cybersource";
11648
11648
  }
11649
+ if ((_window$Pelcro$site$r4 = window.Pelcro.site.read()) !== null && _window$Pelcro$site$r4 !== void 0 && _window$Pelcro$site$r4.braintree_gateway_settings) {
11650
+ return "braintree";
11651
+ }
11649
11652
  return "stripe";
11650
11653
  }
11651
11654
  function getFourDigitYear(lastTwoDigits) {
@@ -11748,6 +11751,7 @@ const loadPaymentSDKs = () => {
11748
11751
  } = usePelcro.getStore();
11749
11752
  const supportsVantiv = Boolean(window.Pelcro.site.read().vantiv_gateway_settings);
11750
11753
  const supportsTap = Boolean(window.Pelcro.site.read().tap_gateway_settings);
11754
+ const supportsBraintree = Boolean(window.Pelcro.site.read().braintree_gateway_settings);
11751
11755
  whenUserReady(() => {
11752
11756
  if (!window.Stripe && !supportsVantiv && !supportsTap) {
11753
11757
  pure_1(window.Pelcro.environment.stripe);
@@ -11757,9 +11761,15 @@ const loadPaymentSDKs = () => {
11757
11761
 
11758
11762
  // Load PayPal SDKs
11759
11763
  const supportsPaypal = Boolean(window.Pelcro.site.read().braintree_tokenization);
11764
+ if (supportsPaypal || supportsBraintree) {
11765
+ window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/client.min.js", "braintree-sdk");
11766
+ }
11760
11767
  if (supportsPaypal) {
11761
- window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.69.0/js/client.min.js", "braintree-sdk");
11762
- window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.69.0/js/paypal-checkout.min.js", "braintree-paypal-sdk");
11768
+ window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/paypal-checkout.min.js", "braintree-paypal-sdk");
11769
+ }
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");
11772
+ window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/hosted-fields.min.js", "braintree-hosted-fields-sdk");
11763
11773
  }
11764
11774
 
11765
11775
  // Load Vantiv SDKs
@@ -12186,27 +12196,26 @@ const showPaymentMethodUpdateFromUrl = () => {
12186
12196
  return switchView("login");
12187
12197
  }
12188
12198
  whenUserReady(() => {
12189
- const supportsVantiv = Boolean(window.Pelcro.site.read().vantiv_gateway_settings);
12190
- const supportsTap = Boolean(window.Pelcro.site.read().tap_gateway_settings);
12191
- if (!window.Stripe && !supportsVantiv && !supportsTap) {
12192
- document.querySelector('script[src="https://js.stripe.com/v3"]').addEventListener("load", () => {
12193
- return switchView("payment-method-update");
12194
- });
12195
- return;
12199
+ const cardProcessor = getSiteCardProcessor();
12200
+
12201
+ // Only load appropriate SDK based on processor
12202
+ if (cardProcessor === "braintree" && document.querySelector("#braintree-hosted-fields-sdk")) {
12203
+ return switchView("payment-method-update");
12204
+ }
12205
+ if (cardProcessor === "vantiv" && document.querySelector("#vantiv-eprotect-sdk")) {
12206
+ return switchView("payment-method-update");
12207
+ }
12208
+ if (cardProcessor === "tap" && document.querySelector("#tap-sdk")) {
12209
+ return switchView("payment-method-update");
12196
12210
  }
12197
12211
 
12198
- //vantiv
12199
- if (supportsVantiv) {
12200
- document.querySelector("#vantiv-eprotect-sdk").addEventListener("load", () => {
12212
+ // Only load Stripe if it's the configured processor
12213
+ if (cardProcessor === "stripe" && !window.Stripe) {
12214
+ document.querySelector('script[src="https://js.stripe.com/v3"]').addEventListener("load", () => {
12201
12215
  return switchView("payment-method-update");
12202
12216
  });
12203
12217
  return;
12204
12218
  }
12205
-
12206
- //Tap
12207
- if (supportsTap && document.querySelector("#tap-sdk")) {
12208
- return switchView("payment-method-update");
12209
- }
12210
12219
  return switchView("payment-method-update");
12211
12220
  });
12212
12221
  });
@@ -16395,7 +16404,7 @@ var _isPaymentGatewayInvalid = /*#__PURE__*/new WeakMap();
16395
16404
  var _generateUserError = /*#__PURE__*/new WeakMap();
16396
16405
  class Payment {
16397
16406
  /**
16398
- * @param {(StripeGateway|PaypalGateway|VantivGateway|TapGateway|CybersourceGateway)} paymentGateway
16407
+ * @param {(StripeGateway|PaypalGateway|VantivGateway|TapGateway|CybersourceGateway|BraintreeGateway)} paymentGateway
16399
16408
  */
16400
16409
  constructor(paymentGateway) {
16401
16410
  _defineProperty$3(this, "execute", (options, callback) => {
@@ -16414,7 +16423,7 @@ class Payment {
16414
16423
  _classPrivateFieldInitSpec$1(this, _isPaymentGatewayInvalid, {
16415
16424
  writable: true,
16416
16425
  value: gateway => {
16417
- return gateway && !(gateway instanceof StripeGateway || gateway instanceof PaypalGateway || gateway instanceof VantivGateway || gateway instanceof TapGateway || gateway instanceof CybersourceGateway);
16426
+ return gateway && !(gateway instanceof StripeGateway || gateway instanceof PaypalGateway || gateway instanceof VantivGateway || gateway instanceof TapGateway || gateway instanceof CybersourceGateway || gateway instanceof BraintreeGateway);
16418
16427
  }
16419
16428
  });
16420
16429
  _classPrivateFieldInitSpec$1(this, _generateUserError, {
@@ -16469,7 +16478,8 @@ const PAYMENT_GATEWAYS_ENUM = {
16469
16478
  paypal: "braintree",
16470
16479
  vantiv: "vantiv",
16471
16480
  tap: "tap",
16472
- cybersource: "cybersource"
16481
+ cybersource: "cybersource",
16482
+ braintree: "braintree"
16473
16483
  };
16474
16484
 
16475
16485
  /**
@@ -17408,6 +17418,218 @@ class CybersourceGateway {
17408
17418
  });
17409
17419
  }
17410
17420
  }
17421
+ var _paymentGateway6 = /*#__PURE__*/new WeakMap();
17422
+ var _createSubscription6 = /*#__PURE__*/new WeakMap();
17423
+ var _renewSubscription5 = /*#__PURE__*/new WeakMap();
17424
+ var _createGiftedSubscription6 = /*#__PURE__*/new WeakMap();
17425
+ var _renewGiftedSubscription5 = /*#__PURE__*/new WeakMap();
17426
+ var _purchaseEcommerceOrder5 = /*#__PURE__*/new WeakMap();
17427
+ var _payInvoice6 = /*#__PURE__*/new WeakMap();
17428
+ class BraintreeGateway {
17429
+ constructor() {
17430
+ _classPrivateFieldInitSpec$1(this, _paymentGateway6, {
17431
+ writable: true,
17432
+ value: PAYMENT_GATEWAYS_ENUM["braintree"]
17433
+ });
17434
+ _defineProperty$3(this, "execute", (options, callback) => {
17435
+ const types = PAYMENT_TYPES;
17436
+ switch (options.type) {
17437
+ case types.CREATE_SUBSCRIPTION:
17438
+ return _classPrivateFieldGet(this, _createSubscription6).call(this, options, callback);
17439
+ case types.RENEW_SUBSCRIPTION:
17440
+ return _classPrivateFieldGet(this, _renewSubscription5).call(this, options, callback);
17441
+ case types.CREATE_GIFTED_SUBSCRIPTION:
17442
+ return _classPrivateFieldGet(this, _createGiftedSubscription6).call(this, options, callback);
17443
+ case types.RENEW_GIFTED_SUBSCRIPTION:
17444
+ return _classPrivateFieldGet(this, _renewGiftedSubscription5).call(this, options, callback);
17445
+ case types.PURCHASE_ECOMMERCE_ORDER:
17446
+ return _classPrivateFieldGet(this, _purchaseEcommerceOrder5).call(this, options, callback);
17447
+ case types.PAY_INVOICE:
17448
+ return _classPrivateFieldGet(this, _payInvoice6).call(this, options, callback);
17449
+ default:
17450
+ console.error("Unsupported payment method: braintree Gateway");
17451
+ }
17452
+ });
17453
+ _classPrivateFieldInitSpec$1(this, _createSubscription6, {
17454
+ writable: true,
17455
+ value: (options, callback) => {
17456
+ const {
17457
+ token,
17458
+ plan,
17459
+ couponCode,
17460
+ product,
17461
+ quantity = 1,
17462
+ addressId,
17463
+ isExistingSource
17464
+ } = options;
17465
+ const params = isExistingSource ? {
17466
+ source_id: token
17467
+ } : {
17468
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
17469
+ gateway_token: token
17470
+ };
17471
+ window.Pelcro.subscription.create({
17472
+ quantity,
17473
+ auth_token: window.Pelcro.user.read().auth_token,
17474
+ plan_id: plan.id,
17475
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
17476
+ coupon_code: couponCode,
17477
+ address_id: product.address_required ? addressId : null,
17478
+ ...params
17479
+ }, (err, res) => {
17480
+ callback(err, res);
17481
+ });
17482
+ }
17483
+ });
17484
+ _classPrivateFieldInitSpec$1(this, _renewSubscription5, {
17485
+ writable: true,
17486
+ value: (options, callback) => {
17487
+ const {
17488
+ subscriptionIdToRenew,
17489
+ token,
17490
+ plan,
17491
+ couponCode,
17492
+ product,
17493
+ addressId,
17494
+ isExistingSource
17495
+ } = options;
17496
+ const params = isExistingSource ? {
17497
+ source_id: token
17498
+ } : {
17499
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
17500
+ gateway_token: token
17501
+ };
17502
+ window.Pelcro.subscription.renew({
17503
+ auth_token: window.Pelcro.user.read().auth_token,
17504
+ plan_id: plan.id,
17505
+ coupon_code: couponCode,
17506
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
17507
+ subscription_id: subscriptionIdToRenew,
17508
+ address_id: product.address_required ? addressId : null,
17509
+ ...params
17510
+ }, (err, res) => {
17511
+ callback(err, res);
17512
+ });
17513
+ }
17514
+ });
17515
+ _classPrivateFieldInitSpec$1(this, _createGiftedSubscription6, {
17516
+ writable: true,
17517
+ value: (options, callback) => {
17518
+ const {
17519
+ token,
17520
+ plan,
17521
+ couponCode,
17522
+ product,
17523
+ giftRecipient,
17524
+ quantity = 1,
17525
+ addressId,
17526
+ isExistingSource
17527
+ } = options;
17528
+ const params = isExistingSource ? {
17529
+ source_id: token
17530
+ } : {
17531
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
17532
+ gateway_token: token
17533
+ };
17534
+ window.Pelcro.subscription.create({
17535
+ quantity,
17536
+ auth_token: window.Pelcro.user.read().auth_token,
17537
+ plan_id: plan.id,
17538
+ coupon_code: couponCode,
17539
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
17540
+ gift_recipient_email: giftRecipient.email,
17541
+ gift_recipient_first_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.firstName,
17542
+ gift_recipient_last_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.lastName,
17543
+ gift_start_date: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.startDate,
17544
+ gift_message: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.giftMessage,
17545
+ address_id: product.address_required ? addressId : null,
17546
+ ...params
17547
+ }, (err, res) => {
17548
+ callback(err, res);
17549
+ });
17550
+ }
17551
+ });
17552
+ _classPrivateFieldInitSpec$1(this, _renewGiftedSubscription5, {
17553
+ writable: true,
17554
+ value: (options, callback) => {
17555
+ const {
17556
+ subscriptionIdToRenew,
17557
+ token,
17558
+ product,
17559
+ plan,
17560
+ couponCode,
17561
+ addressId,
17562
+ isExistingSource
17563
+ } = options;
17564
+ const params = isExistingSource ? {
17565
+ source_id: token
17566
+ } : {
17567
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
17568
+ gateway_token: token
17569
+ };
17570
+ window.Pelcro.subscription.renewGift({
17571
+ auth_token: window.Pelcro.user.read().auth_token,
17572
+ plan_id: plan.id,
17573
+ coupon_code: couponCode,
17574
+ subscription_id: subscriptionIdToRenew,
17575
+ address_id: product.address_required ? addressId : null,
17576
+ ...params
17577
+ }, (err, res) => {
17578
+ callback(err, res);
17579
+ });
17580
+ }
17581
+ });
17582
+ _classPrivateFieldInitSpec$1(this, _purchaseEcommerceOrder5, {
17583
+ writable: true,
17584
+ value: (options, callback) => {
17585
+ const {
17586
+ token,
17587
+ items,
17588
+ couponCode,
17589
+ addressId,
17590
+ isExistingSource
17591
+ } = options;
17592
+ const params = isExistingSource ? {
17593
+ source_id: token
17594
+ } : {
17595
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
17596
+ gateway_token: token
17597
+ };
17598
+ window.Pelcro.ecommerce.order.create({
17599
+ items,
17600
+ coupon_code: couponCode,
17601
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
17602
+ ...params,
17603
+ ...(addressId && {
17604
+ address_id: addressId
17605
+ })
17606
+ }, (err, res) => {
17607
+ callback(err, res);
17608
+ });
17609
+ }
17610
+ });
17611
+ _classPrivateFieldInitSpec$1(this, _payInvoice6, {
17612
+ writable: true,
17613
+ value: (options, callback) => {
17614
+ const {
17615
+ token,
17616
+ invoiceId
17617
+ } = options;
17618
+ const params = options.isExistingSource ? {
17619
+ source_id: token,
17620
+ invoice_id: invoiceId
17621
+ } : {
17622
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
17623
+ gateway_token: token,
17624
+ invoice_id: invoiceId
17625
+ };
17626
+ window.Pelcro.invoice.pay(params, (err, res) => {
17627
+ callback(err, res);
17628
+ });
17629
+ }
17630
+ });
17631
+ }
17632
+ }
17411
17633
 
17412
17634
  /**
17413
17635
  * @typedef {Object} PaymentStateType
@@ -17431,6 +17653,7 @@ class CybersourceGateway {
17431
17653
  const initialState$l = {
17432
17654
  disableSubmit: false,
17433
17655
  isLoading: false,
17656
+ isSkeletonLoaded: false,
17434
17657
  disableCouponButton: false,
17435
17658
  couponObject: null,
17436
17659
  couponCode: "",
@@ -17500,7 +17723,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17500
17723
  const isRenewingGift = (_props$isRenewingGift = props.isRenewingGift) !== null && _props$isRenewingGift !== void 0 ? _props$isRenewingGift : pelcroStore.isRenewingGift;
17501
17724
  const invoice = (_props$invoice = props.invoice) !== null && _props$invoice !== void 0 ? _props$invoice : pelcroStore.invoice;
17502
17725
  const skipPayment = (_window$Pelcro = window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$uiSett = _window$Pelcro.uiSettings) === null || _window$Pelcro$uiSett === void 0 ? void 0 : _window$Pelcro$uiSett.skipPaymentForFreePlans;
17503
- const cardProcessor = getSiteCardProcessor();
17726
+ const cardProcessor = getSiteCardProcessor$1();
17504
17727
  React.useEffect(() => {
17505
17728
  if (window.Pelcro.coupon.getFromUrl()) {
17506
17729
  dispatch({
@@ -18077,54 +18300,622 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18077
18300
  };
18078
18301
  /* ====== End Tap integration ======== */
18079
18302
 
18080
- const submitUsingVantiv = state => {
18081
- const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18082
- if (isUsingExistingPaymentMethod) {
18083
- // no need to create a new source using vantiv
18084
- return handleVantivPayment(null, state.couponCode);
18085
- }
18086
- if (!vantivInstanceRef.current) {
18087
- return console.error("Vantiv sdk script wasn't loaded, you need to load vantiv sdk before rendering the vantiv payment flow");
18088
- }
18089
- const orderId = `pelcro-${new Date().getTime()}`;
18090
- /*
18091
- calls handleVantivPayment to either handle a payment or update a source by simply creating a new source
18092
- */
18093
- vantivInstanceRef.current.getPaypageRegistrationId({
18094
- id: orderId,
18095
- orderId: orderId
18096
- });
18097
- };
18098
- function handleVantivPayment(paymentRequest, couponCode) {
18099
- if (paymentRequest) {
18100
- const SUCCESS_STATUS = "870";
18101
- if (paymentRequest.response !== SUCCESS_STATUS) {
18102
- switch (paymentRequest.response) {
18103
- case "871":
18104
- return handlePaymentError({
18105
- error: new Error("Invalid account number")
18106
- });
18107
- default:
18108
- return handlePaymentError({
18109
- error: new Error(paymentRequest.message)
18110
- });
18303
+ /* ====== Start Braintree integration ======== */
18304
+ const braintreeInstanceRef = React__default['default'].useRef(null);
18305
+ const braintree3DSecureInstanceRef = React__default['default'].useRef(null);
18306
+ function getClientToken() {
18307
+ return new Promise((resolve, reject) => {
18308
+ window.Pelcro.payment.generateClientToken({
18309
+ auth_token: window.Pelcro.user.read().auth_token,
18310
+ site_id: window.Pelcro.siteid
18311
+ }, (error, response) => {
18312
+ if (error) {
18313
+ reject(error);
18314
+ }
18315
+ if (response) {
18316
+ resolve(response.client_token);
18111
18317
  }
18318
+ });
18319
+ });
18320
+ }
18321
+ async function initializeBraintree() {
18322
+ if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
18323
+ if (cardProcessor === "braintree" && !selectedPaymentMethodId) {
18324
+ const braintreeToken = await getClientToken();
18325
+ const isBraintreeEnabled = Boolean(braintreeToken);
18326
+ if (!isBraintreeEnabled) {
18327
+ console.error("Braintree integration is currently not enabled on this site's config");
18328
+ return;
18112
18329
  }
18113
- }
18114
- const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18115
- if (type === "createPayment") {
18116
- handleVantivSubscription();
18117
- } else if (type === "orderCreate") {
18118
- purchase(new VantivGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest, state, dispatch);
18119
- } else if (type === "invoicePayment") {
18120
- payInvoice(new VantivGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest);
18121
- } else if (type === "createPaymentSource") {
18122
- createNewVantivCard();
18123
- } else if (type === "updatePaymentSource") {
18124
- updateVantivCard();
18125
- } else if (type === "deletePaymentSource") {
18126
- replaceVantivCard();
18127
- }
18330
+ if (type !== "updatePaymentSource") {
18331
+ braintreeInstanceRef.current = new window.braintree.client.create({
18332
+ authorization: braintreeToken
18333
+ }).then(clientInstance => {
18334
+ const options = {
18335
+ authorization: braintreeToken,
18336
+ styles: {
18337
+ input: {
18338
+ "font-size": "14px"
18339
+ },
18340
+ "input.invalid": {
18341
+ color: "red"
18342
+ },
18343
+ "input.valid": {
18344
+ color: "green"
18345
+ }
18346
+ },
18347
+ fields: {
18348
+ number: {
18349
+ container: "#card-number",
18350
+ placeholder: "4111 1111 1111 1111"
18351
+ },
18352
+ cvv: {
18353
+ container: "#cvv",
18354
+ placeholder: "123"
18355
+ },
18356
+ expirationDate: {
18357
+ container: "#expiration-date",
18358
+ placeholder: "10/2022"
18359
+ }
18360
+ }
18361
+ };
18362
+ dispatch({
18363
+ type: SKELETON_LOADER,
18364
+ payload: true
18365
+ });
18366
+ braintree3DSecureInstanceRef.current = new window.braintree.threeDSecure.create({
18367
+ version: 2,
18368
+ authorization: braintreeToken
18369
+ }).then(threeDSecureInstance => {
18370
+ return threeDSecureInstance;
18371
+ });
18372
+ return window.braintree.hostedFields.create(options);
18373
+ });
18374
+ braintreeInstanceRef.current.then(hostedFieldInstance => {
18375
+ hostedFieldInstance.on("notEmpty", function (event) {
18376
+ const field = event.fields[event.emittedBy];
18377
+ if (field.isPotentiallyValid) {
18378
+ field.container.classList.remove("pelcro-input-invalid");
18379
+ }
18380
+ });
18381
+ hostedFieldInstance.on("validityChange", function (event) {
18382
+ const field = event.fields[event.emittedBy];
18383
+
18384
+ // Remove any previously applied error or warning classes
18385
+ field.container.classList.remove("is-valid");
18386
+ field.container.classList.remove("pelcro-input-invalid");
18387
+ if (field.isValid) {
18388
+ field.container.classList.add("is-valid");
18389
+ } else if (field.isPotentiallyValid) ; else {
18390
+ field.container.classList.add("pelcro-input-invalid");
18391
+ }
18392
+ });
18393
+ });
18394
+ } else if (type == "updatePaymentSource" && paymentMethodToEdit) {
18395
+ const {
18396
+ properties
18397
+ } = paymentMethodToEdit !== null && paymentMethodToEdit !== void 0 ? paymentMethodToEdit : {};
18398
+ const {
18399
+ exp_month: expMonth,
18400
+ exp_year: expYear
18401
+ } = properties !== null && properties !== void 0 ? properties : {};
18402
+ braintreeInstanceRef.current = new window.braintree.client.create({
18403
+ authorization: braintreeToken
18404
+ }).then(clientInstance => {
18405
+ const options = {
18406
+ client: clientInstance,
18407
+ styles: {
18408
+ input: {
18409
+ "font-size": "14px"
18410
+ },
18411
+ "input.invalid": {
18412
+ color: "red"
18413
+ },
18414
+ "input.valid": {
18415
+ color: "green"
18416
+ }
18417
+ },
18418
+ fields: {
18419
+ expirationMonth: {
18420
+ container: "#expiration-month",
18421
+ prefill: expMonth
18422
+ },
18423
+ expirationYear: {
18424
+ container: "#expiration-year",
18425
+ prefill: expYear
18426
+ }
18427
+ }
18428
+ };
18429
+ dispatch({
18430
+ type: SKELETON_LOADER,
18431
+ payload: true
18432
+ });
18433
+ return window.braintree.hostedFields.create(options);
18434
+ });
18435
+ braintreeInstanceRef.current.then(hostedFieldInstance => {
18436
+ hostedFieldInstance.on("notEmpty", function (event) {
18437
+ const field = event.fields[event.emittedBy];
18438
+ if (field.isPotentiallyValid) {
18439
+ field.container.classList.remove("pelcro-input-invalid");
18440
+ }
18441
+ });
18442
+ hostedFieldInstance.on("validityChange", function (event) {
18443
+ const field = event.fields[event.emittedBy];
18444
+
18445
+ // Remove any previously applied error or warning classes
18446
+ field.container.classList.remove("is-valid");
18447
+ field.container.classList.remove("pelcro-input-invalid");
18448
+ if (field.isValid) {
18449
+ field.container.classList.add("is-valid");
18450
+ } else if (field.isPotentiallyValid) ; else {
18451
+ field.container.classList.add("pelcro-input-invalid");
18452
+ }
18453
+ });
18454
+ });
18455
+ }
18456
+ }
18457
+ }
18458
+ React.useEffect(() => {
18459
+ initializeBraintree();
18460
+ }, [selectedPaymentMethodId, paymentMethodToEdit]);
18461
+ const braintreeErrorHandler = tokenizeErr => {
18462
+ var _tokenizeErr$details, _tokenizeErr$details2;
18463
+ const cardNumber = document.querySelector("#card-number");
18464
+ const expirationDate = document.querySelector("#expiration-date");
18465
+ const cvv = document.querySelector("#cvv");
18466
+ 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;
18467
+ switch (tokenizeErr.code) {
18468
+ case "HOSTED_FIELDS_FIELDS_EMPTY":
18469
+ // occurs when none of the fields are filled in
18470
+ cardNumber.classList.add("pelcro-input-invalid");
18471
+ expirationDate.classList.add("pelcro-input-invalid");
18472
+ cvv.classList.add("pelcro-input-invalid");
18473
+ return "All fields are empty! Please fill out the form.";
18474
+ // break;
18475
+ case "HOSTED_FIELDS_FIELDS_INVALID":
18476
+ // occurs when certain fields do not pass client side validation
18477
+ console.error("Some fields are invalid:", tokenizeErr.details.invalidFieldKeys.toString());
18478
+
18479
+ // you can also programmatically access the field containers for the invalid fields
18480
+ // tokenizeErr.details.invalidFields.forEach(function (
18481
+ // fieldContainer
18482
+ // ) {
18483
+ // fieldContainer.className = "invalid";
18484
+ // });
18485
+ fields.forEach(field => {
18486
+ field.classList.add("pelcro-input-invalid");
18487
+ });
18488
+ return `Some fields are invalid: ${tokenizeErr.details.invalidFieldKeys.toString()}`;
18489
+ case "HOSTED_FIELDS_TOKENIZATION_FAIL_ON_DUPLICATE":
18490
+ // occurs when:
18491
+ // * the client token used for client authorization was generated
18492
+ // with a customer ID and the fail on duplicate payment method
18493
+ // option is set to true
18494
+ // * the card being tokenized has previously been vaulted (with any customer)
18495
+ // See: https://developer.paypal.com/braintree/docs/reference/request/client-token/generate#options.fail_on_duplicate_payment_method
18496
+ return "This payment method already exists in your vault.";
18497
+ case "HOSTED_FIELDS_TOKENIZATION_CVV_VERIFICATION_FAILED":
18498
+ // occurs when:
18499
+ // * the client token used for client authorization was generated
18500
+ // with a customer ID and the verify card option is set to true
18501
+ // and you have credit card verification turned on in the Braintree
18502
+ // control panel
18503
+ // * the cvv does not pass verification (https://developer.paypal.com/braintree/docs/reference/general/testing#avs-and-cvv/cid-responses)
18504
+ // See: https://developer.paypal.com/braintree/docs/reference/request/client-token/generate#options.verify_card
18505
+ return "CVV did not pass verification";
18506
+ case "HOSTED_FIELDS_FAILED_TOKENIZATION":
18507
+ // occurs for any other tokenization error on the server
18508
+ return "Tokenization failed server side. Is the card valid?";
18509
+ case "HOSTED_FIELDS_TOKENIZATION_NETWORK_ERROR":
18510
+ // occurs when the Braintree gateway cannot be contacted
18511
+ return "Network error occurred when tokenizing.";
18512
+ default:
18513
+ console.error("Something bad happened!", tokenizeErr);
18514
+ return "Something bad happened!";
18515
+ }
18516
+ };
18517
+ const submitUsingBraintree = (state, dispatch) => {
18518
+ var _ref6, _ref7, _state$updatedPrice2;
18519
+ const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18520
+ if (isUsingExistingPaymentMethod) {
18521
+ // no need to create a new source using braintree
18522
+ return handleBraintreePayment(null, state.couponCode);
18523
+ }
18524
+ if (!braintreeInstanceRef.current) {
18525
+ return console.error("Braintree sdk script wasn't loaded, you need to load braintree sdk before rendering the braintree payment flow");
18526
+ }
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
+ braintreeInstanceRef.current.then(hostedFieldInstance => {
18544
+ hostedFieldInstance.tokenize((tokenizeErr, payload) => {
18545
+ if (tokenizeErr) {
18546
+ dispatch({
18547
+ type: DISABLE_SUBMIT,
18548
+ payload: false
18549
+ });
18550
+ dispatch({
18551
+ type: LOADING,
18552
+ payload: false
18553
+ });
18554
+ return dispatch({
18555
+ type: SHOW_ALERT,
18556
+ payload: {
18557
+ type: "error",
18558
+ content: braintreeErrorHandler(tokenizeErr)
18559
+ }
18560
+ });
18561
+ }
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
+ }
18630
+ });
18631
+ }).catch(error => {
18632
+ if (error) {
18633
+ console.error(error);
18634
+ return;
18635
+ }
18636
+ });
18637
+ };
18638
+ const handleBraintreePayment = (braintreePaymentRequest, couponCode) => {
18639
+ const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18640
+ const braintreeNonce = braintreePaymentRequest === null || braintreePaymentRequest === void 0 ? void 0 : braintreePaymentRequest.nonce;
18641
+ if (type === "createPayment") {
18642
+ handleBraintreeSubscription();
18643
+ } else if (type === "orderCreate") {
18644
+ purchase(new BraintreeGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce, state, dispatch);
18645
+ } else if (type === "invoicePayment") {
18646
+ payInvoice(new BraintreeGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce);
18647
+ } else if (type === "createPaymentSource") {
18648
+ createNewBraintreeCard();
18649
+ } else if (type === "updatePaymentSource") {
18650
+ updateBraintreeCard();
18651
+ } else if (type === "deletePaymentSource") {
18652
+ replaceBraintreeCard();
18653
+ }
18654
+ function createNewBraintreeCard() {
18655
+ window.Pelcro.paymentMethods.create({
18656
+ auth_token: window.Pelcro.user.read().auth_token,
18657
+ token: braintreeNonce,
18658
+ gateway: "braintree"
18659
+ }, (err, res) => {
18660
+ dispatch({
18661
+ type: DISABLE_SUBMIT,
18662
+ payload: false
18663
+ });
18664
+ dispatch({
18665
+ type: LOADING,
18666
+ payload: false
18667
+ });
18668
+ if (err) {
18669
+ onFailure(err);
18670
+ return dispatch({
18671
+ type: SHOW_ALERT,
18672
+ payload: {
18673
+ type: "error",
18674
+ content: getErrorMessages(err)
18675
+ }
18676
+ });
18677
+ }
18678
+ dispatch({
18679
+ type: SHOW_ALERT,
18680
+ payload: {
18681
+ type: "success",
18682
+ content: t("messages.sourceCreated")
18683
+ }
18684
+ });
18685
+ onSuccess(res);
18686
+ });
18687
+ }
18688
+ function replaceBraintreeCard() {
18689
+ const {
18690
+ id: paymentMethodId
18691
+ } = paymentMethodToDelete;
18692
+ window.Pelcro.paymentMethods.create({
18693
+ auth_token: window.Pelcro.user.read().auth_token,
18694
+ token: braintreeNonce,
18695
+ gateway: "braintree"
18696
+ }, (err, res) => {
18697
+ if (err) {
18698
+ dispatch({
18699
+ type: DISABLE_SUBMIT,
18700
+ payload: false
18701
+ });
18702
+ dispatch({
18703
+ type: LOADING,
18704
+ payload: false
18705
+ });
18706
+ onFailure(err);
18707
+ return dispatch({
18708
+ type: SHOW_ALERT,
18709
+ payload: {
18710
+ type: "error",
18711
+ content: getErrorMessages(err)
18712
+ }
18713
+ });
18714
+ }
18715
+ if (res) {
18716
+ setTimeout(() => {
18717
+ window.Pelcro.paymentMethods.deletePaymentMethod({
18718
+ auth_token: window.Pelcro.user.read().auth_token,
18719
+ payment_method_id: paymentMethodId
18720
+ }, (err, res) => {
18721
+ dispatch({
18722
+ type: DISABLE_SUBMIT,
18723
+ payload: false
18724
+ });
18725
+ dispatch({
18726
+ type: LOADING,
18727
+ payload: false
18728
+ });
18729
+ if (err) {
18730
+ onFailure === null || onFailure === void 0 ? void 0 : onFailure(err);
18731
+ return dispatch({
18732
+ type: SHOW_ALERT,
18733
+ payload: {
18734
+ type: "error",
18735
+ content: getErrorMessages(err)
18736
+ }
18737
+ });
18738
+ }
18739
+ onSuccess(res);
18740
+ });
18741
+ }, 2000);
18742
+ }
18743
+ });
18744
+ }
18745
+ function updateBraintreeCard() {
18746
+ const {
18747
+ id: paymentMethodId
18748
+ } = paymentMethodToEdit;
18749
+ const {
18750
+ expirationMonth,
18751
+ expirationYear
18752
+ } = braintreePaymentRequest === null || braintreePaymentRequest === void 0 ? void 0 : braintreePaymentRequest.details;
18753
+ const {
18754
+ isDefault
18755
+ } = state;
18756
+ window.Pelcro.paymentMethods.update({
18757
+ auth_token: window.Pelcro.user.read().auth_token,
18758
+ payment_method_id: paymentMethodId,
18759
+ token: braintreeNonce,
18760
+ gateway: "braintree",
18761
+ exp_month: expirationMonth,
18762
+ exp_year: expirationYear,
18763
+ is_default: isDefault
18764
+ }, (err, res) => {
18765
+ dispatch({
18766
+ type: DISABLE_SUBMIT,
18767
+ payload: false
18768
+ });
18769
+ dispatch({
18770
+ type: LOADING,
18771
+ payload: false
18772
+ });
18773
+ if (err) {
18774
+ onFailure(err);
18775
+ return dispatch({
18776
+ type: SHOW_ALERT,
18777
+ payload: {
18778
+ type: "error",
18779
+ content: getErrorMessages(err)
18780
+ }
18781
+ });
18782
+ }
18783
+ dispatch({
18784
+ type: SHOW_ALERT,
18785
+ payload: {
18786
+ type: "success",
18787
+ content: t("messages.sourceUpdated")
18788
+ }
18789
+ });
18790
+ onSuccess(res);
18791
+ });
18792
+ }
18793
+ function handleBraintreeSubscription() {
18794
+ const payment = new Payment(new BraintreeGateway());
18795
+ const createSubscription = !isGift && !subscriptionIdToRenew;
18796
+ const renewSubscription = !isGift && subscriptionIdToRenew;
18797
+ const giftSubscriprition = isGift && !subscriptionIdToRenew;
18798
+ const renewGift = isRenewingGift;
18799
+ if (renewGift) {
18800
+ return payment.execute({
18801
+ type: PAYMENT_TYPES.RENEW_GIFTED_SUBSCRIPTION,
18802
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
18803
+ plan,
18804
+ couponCode,
18805
+ product,
18806
+ isExistingSource: isUsingExistingPaymentMethod,
18807
+ subscriptionIdToRenew,
18808
+ addressId: selectedAddressId
18809
+ }, (err, res) => {
18810
+ if (err) {
18811
+ return handlePaymentError(err);
18812
+ }
18813
+ onSuccess(res);
18814
+ });
18815
+ } else if (giftSubscriprition) {
18816
+ return payment.execute({
18817
+ type: PAYMENT_TYPES.CREATE_GIFTED_SUBSCRIPTION,
18818
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
18819
+ quantity: plan.quantity,
18820
+ plan,
18821
+ couponCode,
18822
+ product,
18823
+ isExistingSource: isUsingExistingPaymentMethod,
18824
+ giftRecipient,
18825
+ addressId: selectedAddressId
18826
+ }, (err, res) => {
18827
+ if (err) {
18828
+ return handlePaymentError(err);
18829
+ }
18830
+ onSuccess(res);
18831
+ });
18832
+ } else if (renewSubscription) {
18833
+ return payment.execute({
18834
+ type: PAYMENT_TYPES.RENEW_SUBSCRIPTION,
18835
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
18836
+ quantity: plan.quantity,
18837
+ plan,
18838
+ couponCode,
18839
+ product,
18840
+ isExistingSource: isUsingExistingPaymentMethod,
18841
+ subscriptionIdToRenew,
18842
+ addressId: selectedAddressId
18843
+ }, (err, res) => {
18844
+ if (err) {
18845
+ return handlePaymentError(err);
18846
+ }
18847
+ onSuccess(res);
18848
+ });
18849
+ } else if (createSubscription) {
18850
+ return payment.execute({
18851
+ type: PAYMENT_TYPES.CREATE_SUBSCRIPTION,
18852
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
18853
+ quantity: plan.quantity,
18854
+ plan,
18855
+ couponCode,
18856
+ product,
18857
+ isExistingSource: isUsingExistingPaymentMethod,
18858
+ addressId: selectedAddressId
18859
+ }, (err, res) => {
18860
+ if (err) {
18861
+ return handlePaymentError(err);
18862
+ }
18863
+ onSuccess(res);
18864
+ });
18865
+ }
18866
+ }
18867
+ };
18868
+
18869
+ /* ====== End Braintree integration ======== */
18870
+
18871
+ const submitUsingVantiv = state => {
18872
+ const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18873
+ if (isUsingExistingPaymentMethod) {
18874
+ // no need to create a new source using vantiv
18875
+ return handleVantivPayment(null, state.couponCode);
18876
+ }
18877
+ if (!vantivInstanceRef.current) {
18878
+ return console.error("Vantiv sdk script wasn't loaded, you need to load vantiv sdk before rendering the vantiv payment flow");
18879
+ }
18880
+ const orderId = `pelcro-${new Date().getTime()}`;
18881
+ /*
18882
+ calls handleVantivPayment to either handle a payment or update a source by simply creating a new source
18883
+ */
18884
+ vantivInstanceRef.current.getPaypageRegistrationId({
18885
+ id: orderId,
18886
+ orderId: orderId
18887
+ });
18888
+ };
18889
+ function handleVantivPayment(paymentRequest, couponCode) {
18890
+ if (paymentRequest) {
18891
+ const SUCCESS_STATUS = "870";
18892
+ if (paymentRequest.response !== SUCCESS_STATUS) {
18893
+ switch (paymentRequest.response) {
18894
+ case "871":
18895
+ return handlePaymentError({
18896
+ error: new Error("Invalid account number")
18897
+ });
18898
+ default:
18899
+ return handlePaymentError({
18900
+ error: new Error(paymentRequest.message)
18901
+ });
18902
+ }
18903
+ }
18904
+ }
18905
+ const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18906
+ if (type === "createPayment") {
18907
+ handleVantivSubscription();
18908
+ } else if (type === "orderCreate") {
18909
+ purchase(new VantivGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest, state, dispatch);
18910
+ } else if (type === "invoicePayment") {
18911
+ payInvoice(new VantivGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest);
18912
+ } else if (type === "createPaymentSource") {
18913
+ createNewVantivCard();
18914
+ } else if (type === "updatePaymentSource") {
18915
+ updateVantivCard();
18916
+ } else if (type === "deletePaymentSource") {
18917
+ replaceVantivCard();
18918
+ }
18128
18919
  function createNewVantivCard() {
18129
18920
  window.Pelcro.paymentMethods.create({
18130
18921
  auth_token: window.Pelcro.user.read().auth_token,
@@ -18431,13 +19222,13 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18431
19222
  });
18432
19223
 
18433
19224
  // When Google pay / Apple pay source created
18434
- paymentRequest.on("source", _ref6 => {
19225
+ paymentRequest.on("source", _ref8 => {
18435
19226
  var _source$card;
18436
19227
  let {
18437
19228
  complete,
18438
19229
  source,
18439
19230
  ...data
18440
- } = _ref6;
19231
+ } = _ref8;
18441
19232
  dispatch({
18442
19233
  type: DISABLE_COUPON_BUTTON,
18443
19234
  payload: true
@@ -18452,11 +19243,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18452
19243
  });
18453
19244
  complete("success");
18454
19245
  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") {
18455
- return generate3DSecureSource(source).then(_ref7 => {
19246
+ return generate3DSecureSource(source).then(_ref9 => {
18456
19247
  let {
18457
19248
  source,
18458
19249
  error
18459
- } = _ref7;
19250
+ } = _ref9;
18460
19251
  if (error) {
18461
19252
  return handlePaymentError(error);
18462
19253
  }
@@ -19173,11 +19964,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19173
19964
  const createPaymentSource = (state, dispatch) => {
19174
19965
  return stripe.createSource({
19175
19966
  type: "card"
19176
- }).then(_ref8 => {
19967
+ }).then(_ref10 => {
19177
19968
  let {
19178
19969
  source,
19179
19970
  error
19180
- } = _ref8;
19971
+ } = _ref10;
19181
19972
  if (error) {
19182
19973
  return handlePaymentError(error);
19183
19974
  }
@@ -19291,11 +20082,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19291
20082
  } = paymentMethodToDelete;
19292
20083
  return stripe.createSource({
19293
20084
  type: "card"
19294
- }).then(_ref9 => {
20085
+ }).then(_ref11 => {
19295
20086
  let {
19296
20087
  source,
19297
20088
  error
19298
- } = _ref9;
20089
+ } = _ref11;
19299
20090
  if (error) {
19300
20091
  return handlePaymentError(error);
19301
20092
  }
@@ -19393,12 +20184,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19393
20184
  }
19394
20185
  stripe.createSource({
19395
20186
  type: "card"
19396
- }).then(_ref10 => {
19397
- var _ref11, _ref12, _state$updatedPrice2;
20187
+ }).then(_ref12 => {
20188
+ var _ref13, _ref14, _state$updatedPrice3;
19398
20189
  let {
19399
20190
  source,
19400
20191
  error
19401
- } = _ref10;
20192
+ } = _ref12;
19402
20193
  if (error) {
19403
20194
  return handlePaymentError(error);
19404
20195
  }
@@ -19417,7 +20208,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19417
20208
  return total + item.price * item.quantity;
19418
20209
  }, 0);
19419
20210
  };
19420
- (_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();
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();
19421
20212
  return handlePayment(source);
19422
20213
  }).catch(error => {
19423
20214
  return handlePaymentError(error);
@@ -19599,6 +20390,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19599
20390
  ...state,
19600
20391
  isLoading: action.payload
19601
20392
  });
20393
+ case SKELETON_LOADER:
20394
+ return lib_7({
20395
+ ...state,
20396
+ isSkeletonLoaded: action.payload
20397
+ });
19602
20398
  case SHOW_COUPON_FIELD:
19603
20399
  return lib_7({
19604
20400
  ...state,
@@ -19627,15 +20423,18 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19627
20423
  if (skipPayment && props !== null && props !== void 0 && props.freeOrders) {
19628
20424
  return submitPayment(state);
19629
20425
  }
19630
- if (getSiteCardProcessor() === "vantiv") {
20426
+ if (getSiteCardProcessor$1() === "vantiv") {
19631
20427
  return submitUsingVantiv(state);
19632
20428
  }
19633
- if (getSiteCardProcessor() === "tap") {
20429
+ if (getSiteCardProcessor$1() === "tap") {
19634
20430
  return submitUsingTap(state);
19635
20431
  }
19636
- if (getSiteCardProcessor() === "cybersource") {
20432
+ if (getSiteCardProcessor$1() === "cybersource") {
19637
20433
  return submitUsingCybersource(state, dispatch);
19638
20434
  }
20435
+ if (getSiteCardProcessor$1() === "braintree") {
20436
+ return submitUsingBraintree(state, dispatch);
20437
+ }
19639
20438
  if (selectedPaymentMethodId) {
19640
20439
  // pay with selected method (source) if exists already
19641
20440
  return handlePayment({
@@ -19810,9 +20609,10 @@ const PaymentMethodContainer = props => {
19810
20609
  const {
19811
20610
  whenUserReady
19812
20611
  } = usePelcro.getStore();
19813
- const cardProcessor = getSiteCardProcessor();
20612
+ const cardProcessor = getSiteCardProcessor$1();
19814
20613
  React.useEffect(() => {
19815
20614
  whenUserReady(() => {
20615
+ // Only load Stripe if it's the configured processor
19816
20616
  if (!window.Stripe && cardProcessor === "stripe") {
19817
20617
  document.querySelector('script[src="https://js.stripe.com/v3"]').addEventListener("load", () => {
19818
20618
  setIsStripeLoaded(true);
@@ -19820,7 +20620,9 @@ const PaymentMethodContainer = props => {
19820
20620
  }
19821
20621
  });
19822
20622
  }, []);
19823
- if (isStripeLoaded) {
20623
+
20624
+ // Ensure we only render Stripe components when Stripe is the processor
20625
+ if (isStripeLoaded && cardProcessor === "stripe") {
19824
20626
  return /*#__PURE__*/React__default['default'].createElement(es_13, {
19825
20627
  apiKey: window.Pelcro.environment.stripe,
19826
20628
  stripeAccount: window.Pelcro.site.read().account_id,
@@ -20023,7 +20825,12 @@ const CheckoutForm = _ref => {
20023
20825
  selectedPaymentMethodId,
20024
20826
  paymentMethodToEdit
20025
20827
  } = usePelcro();
20026
- const cardProcessor = getSiteCardProcessor();
20828
+ const cardProcessor = getSiteCardProcessor$1();
20829
+ const {
20830
+ state: {
20831
+ isSkeletonLoaded
20832
+ }
20833
+ } = React.useContext(store$l);
20027
20834
  if (selectedPaymentMethodId) {
20028
20835
  return null;
20029
20836
  }
@@ -20055,12 +20862,65 @@ const CheckoutForm = _ref => {
20055
20862
  placeholder: "Exp Year *"
20056
20863
  }))));
20057
20864
  }
20058
- if (cardProcessor === "stripe") {
20865
+ if (cardProcessor === "braintree") {
20059
20866
  if (type === "updatePaymentSource") {
20060
20867
  var _paymentMethodToEdit$;
20868
+ return /*#__PURE__*/React__default['default'].createElement("div", null, isSkeletonLoaded && paymentMethodToEdit ? /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
20869
+ htmlFor: "card-number"
20870
+ }, "Card Number *"), /*#__PURE__*/React__default['default'].createElement(Input, {
20871
+ id: "card-number",
20872
+ className: "plc-tracking-widest plc-flex-grow plc-h-12 plc-text-center",
20873
+ value: `•••• •••• •••• ${paymentMethodToEdit === null || paymentMethodToEdit === void 0 ? void 0 : (_paymentMethodToEdit$ = paymentMethodToEdit.properties) === null || _paymentMethodToEdit$ === void 0 ? void 0 : _paymentMethodToEdit$.last4}`,
20874
+ disabled: true
20875
+ }), /*#__PURE__*/React__default['default'].createElement("div", {
20876
+ className: "plc-flex plc-items-start plc-space-x-8 plc-my-6"
20877
+ }, /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
20878
+ htmlFor: "expiration-month"
20879
+ }, "Expiration Month *"), /*#__PURE__*/React__default['default'].createElement("div", {
20880
+ id: "expiration-month",
20881
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
20882
+ })), /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
20883
+ htmlFor: "expiration-year"
20884
+ }, "Expiration Year *"), /*#__PURE__*/React__default['default'].createElement("div", {
20885
+ id: "expiration-year",
20886
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
20887
+ })))) : /*#__PURE__*/React__default['default'].createElement("div", {
20888
+ className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
20889
+ }));
20890
+ }
20891
+ return /*#__PURE__*/React__default['default'].createElement("div", null, isSkeletonLoaded ? /*#__PURE__*/React__default['default'].createElement("div", {
20892
+ className: "plc-max-w-[50em]"
20893
+ }, /*#__PURE__*/React__default['default'].createElement("label", {
20894
+ htmlFor: "card-number"
20895
+ }, "Card Number *"), /*#__PURE__*/React__default['default'].createElement("div", {
20896
+ id: "card-number",
20897
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
20898
+ }), /*#__PURE__*/React__default['default'].createElement("div", {
20899
+ className: "plc-flex plc-items-start plc-space-x-8 plc-my-6"
20900
+ }, /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
20901
+ htmlFor: "expiration-date"
20902
+ }, "Expiration Date *"), /*#__PURE__*/React__default['default'].createElement("div", {
20903
+ id: "expiration-date",
20904
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
20905
+ })), /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
20906
+ htmlFor: "cvv"
20907
+ }, "CVC *"), /*#__PURE__*/React__default['default'].createElement("div", {
20908
+ id: "cvv",
20909
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
20910
+ })))) : /*#__PURE__*/React__default['default'].createElement("div", {
20911
+ className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
20912
+ }));
20913
+ }
20914
+ if (cardProcessor === "stripe") {
20915
+ if (type === "updatePaymentSource") {
20916
+ var _paymentMethodToEdit$2;
20917
+ const currentProcessor = getSiteCardProcessor$1();
20918
+ if (currentProcessor !== "stripe") {
20919
+ return null;
20920
+ }
20061
20921
  return /*#__PURE__*/React__default['default'].createElement("div", null, paymentMethodToEdit ? /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement(Input, {
20062
20922
  className: "plc-tracking-widest plc-flex-grow plc-text-center",
20063
- value: `•••• •••• •••• ${paymentMethodToEdit === null || paymentMethodToEdit === void 0 ? void 0 : (_paymentMethodToEdit$ = paymentMethodToEdit.properties) === null || _paymentMethodToEdit$ === void 0 ? void 0 : _paymentMethodToEdit$.last4}`,
20923
+ value: `•••• •••• •••• ${paymentMethodToEdit === null || paymentMethodToEdit === void 0 ? void 0 : (_paymentMethodToEdit$2 = paymentMethodToEdit.properties) === null || _paymentMethodToEdit$2 === void 0 ? void 0 : _paymentMethodToEdit$2.last4}`,
20064
20924
  disabled: true
20065
20925
  })) : /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement(Input, {
20066
20926
  className: "plc-bg-gray-300 plc-animate-pulse"
@@ -21183,7 +22043,7 @@ function PaymentMethodUpdateSetDefault(props) {
21183
22043
  *
21184
22044
  */
21185
22045
  function PaymentMethodView(_ref) {
21186
- var _window$Pelcro$site$r, _window$Pelcro$site$r2, _window$Pelcro$site$r3, _calcAndFormatItemsTo, _order$;
22046
+ var _window$Pelcro, _window$Pelcro$uiSett, _window$Pelcro$site$r, _window$Pelcro$site$r2, _window$Pelcro$site$r3, _calcAndFormatItemsTo, _order$;
21187
22047
  let {
21188
22048
  onSuccess,
21189
22049
  onGiftRenewalSuccess,
@@ -21199,7 +22059,8 @@ function PaymentMethodView(_ref) {
21199
22059
  const {
21200
22060
  t
21201
22061
  } = useTranslation("checkoutForm");
21202
- const cardProcessor = getSiteCardProcessor();
22062
+ const cardProcessor = getSiteCardProcessor$1();
22063
+ const show3DSWarning = (_window$Pelcro = window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$uiSett = _window$Pelcro.uiSettings) === null || _window$Pelcro$uiSett === void 0 ? void 0 : _window$Pelcro$uiSett.show3DSWarning;
21203
22064
  const supportsVantiv = Boolean((_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.vantiv_gateway_settings);
21204
22065
  const supportsTap = Boolean((_window$Pelcro$site$r2 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : _window$Pelcro$site$r2.tap_gateway_settings);
21205
22066
  const supportsCybersource = Boolean((_window$Pelcro$site$r3 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r3 === void 0 ? void 0 : _window$Pelcro$site$r3.cybersource_gateway_settings);
@@ -21227,7 +22088,9 @@ function PaymentMethodView(_ref) {
21227
22088
  target: "_blank",
21228
22089
  href: "https://www.stripe.com/us/customers",
21229
22090
  isButton: false
21230
- }, "Stripe"))), /*#__PURE__*/React__default['default'].createElement("form", {
22091
+ }, "Stripe"))), show3DSWarning && /*#__PURE__*/React__default['default'].createElement("div", {
22092
+ className: "plc-flex plc-items-center plc-w-full plc-px-4 plc-py-2 plc-text-center plc-text-yellow-600 plc-border plc-border-yellow-400 plc-rounded plc-bg-yellow-50 plc-mt-4"
22093
+ }, "Note: If your card or bank requires 3D Secure (3DS) authentication, your payment might not go through at the moment. We are actively working on resolving this issue."), /*#__PURE__*/React__default['default'].createElement("form", {
21231
22094
  action: "javascript:void(0);",
21232
22095
  className: "plc-w-full plc-mt-2 plc-font-semibold plc-text-gray-600 pelcro-form"
21233
22096
  }, /*#__PURE__*/React__default['default'].createElement(PaymentMethodContainer, {