@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.esm.js CHANGED
@@ -11605,8 +11605,8 @@ const debounce = (func, waitTime) => {
11605
11605
  timeout = setTimeout(later, waitTime);
11606
11606
  };
11607
11607
  };
11608
- function getSiteCardProcessor() {
11609
- var _window$Pelcro$site$r, _window$Pelcro$site$r2, _window$Pelcro$site$r3;
11608
+ function getSiteCardProcessor$1() {
11609
+ var _window$Pelcro$site$r, _window$Pelcro$site$r2, _window$Pelcro$site$r3, _window$Pelcro$site$r4;
11610
11610
  if ((_window$Pelcro$site$r = window.Pelcro.site.read()) !== null && _window$Pelcro$site$r !== void 0 && _window$Pelcro$site$r.vantiv_gateway_settings) {
11611
11611
  return "vantiv";
11612
11612
  }
@@ -11616,6 +11616,9 @@ function getSiteCardProcessor() {
11616
11616
  if ((_window$Pelcro$site$r3 = window.Pelcro.site.read()) !== null && _window$Pelcro$site$r3 !== void 0 && _window$Pelcro$site$r3.cybersource_gateway_settings) {
11617
11617
  return "cybersource";
11618
11618
  }
11619
+ if ((_window$Pelcro$site$r4 = window.Pelcro.site.read()) !== null && _window$Pelcro$site$r4 !== void 0 && _window$Pelcro$site$r4.braintree_gateway_settings) {
11620
+ return "braintree";
11621
+ }
11619
11622
  return "stripe";
11620
11623
  }
11621
11624
  function getFourDigitYear(lastTwoDigits) {
@@ -11718,6 +11721,7 @@ const loadPaymentSDKs = () => {
11718
11721
  } = usePelcro.getStore();
11719
11722
  const supportsVantiv = Boolean(window.Pelcro.site.read().vantiv_gateway_settings);
11720
11723
  const supportsTap = Boolean(window.Pelcro.site.read().tap_gateway_settings);
11724
+ const supportsBraintree = Boolean(window.Pelcro.site.read().braintree_gateway_settings);
11721
11725
  whenUserReady(() => {
11722
11726
  if (!window.Stripe && !supportsVantiv && !supportsTap) {
11723
11727
  pure_1(window.Pelcro.environment.stripe);
@@ -11727,9 +11731,15 @@ const loadPaymentSDKs = () => {
11727
11731
 
11728
11732
  // Load PayPal SDKs
11729
11733
  const supportsPaypal = Boolean(window.Pelcro.site.read().braintree_tokenization);
11734
+ if (supportsPaypal || supportsBraintree) {
11735
+ window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/client.min.js", "braintree-sdk");
11736
+ }
11730
11737
  if (supportsPaypal) {
11731
- window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.69.0/js/client.min.js", "braintree-sdk");
11732
- window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.69.0/js/paypal-checkout.min.js", "braintree-paypal-sdk");
11738
+ window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/paypal-checkout.min.js", "braintree-paypal-sdk");
11739
+ }
11740
+ if (supportsBraintree) {
11741
+ window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/three-d-secure.min.js", "braintree-3D-secure-sdk");
11742
+ window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/hosted-fields.min.js", "braintree-hosted-fields-sdk");
11733
11743
  }
11734
11744
 
11735
11745
  // Load Vantiv SDKs
@@ -12156,27 +12166,26 @@ const showPaymentMethodUpdateFromUrl = () => {
12156
12166
  return switchView("login");
12157
12167
  }
12158
12168
  whenUserReady(() => {
12159
- const supportsVantiv = Boolean(window.Pelcro.site.read().vantiv_gateway_settings);
12160
- const supportsTap = Boolean(window.Pelcro.site.read().tap_gateway_settings);
12161
- if (!window.Stripe && !supportsVantiv && !supportsTap) {
12162
- document.querySelector('script[src="https://js.stripe.com/v3"]').addEventListener("load", () => {
12163
- return switchView("payment-method-update");
12164
- });
12165
- return;
12169
+ const cardProcessor = getSiteCardProcessor();
12170
+
12171
+ // Only load appropriate SDK based on processor
12172
+ if (cardProcessor === "braintree" && document.querySelector("#braintree-hosted-fields-sdk")) {
12173
+ return switchView("payment-method-update");
12174
+ }
12175
+ if (cardProcessor === "vantiv" && document.querySelector("#vantiv-eprotect-sdk")) {
12176
+ return switchView("payment-method-update");
12177
+ }
12178
+ if (cardProcessor === "tap" && document.querySelector("#tap-sdk")) {
12179
+ return switchView("payment-method-update");
12166
12180
  }
12167
12181
 
12168
- //vantiv
12169
- if (supportsVantiv) {
12170
- document.querySelector("#vantiv-eprotect-sdk").addEventListener("load", () => {
12182
+ // Only load Stripe if it's the configured processor
12183
+ if (cardProcessor === "stripe" && !window.Stripe) {
12184
+ document.querySelector('script[src="https://js.stripe.com/v3"]').addEventListener("load", () => {
12171
12185
  return switchView("payment-method-update");
12172
12186
  });
12173
12187
  return;
12174
12188
  }
12175
-
12176
- //Tap
12177
- if (supportsTap && document.querySelector("#tap-sdk")) {
12178
- return switchView("payment-method-update");
12179
- }
12180
12189
  return switchView("payment-method-update");
12181
12190
  });
12182
12191
  });
@@ -16365,7 +16374,7 @@ var _isPaymentGatewayInvalid = /*#__PURE__*/new WeakMap();
16365
16374
  var _generateUserError = /*#__PURE__*/new WeakMap();
16366
16375
  class Payment {
16367
16376
  /**
16368
- * @param {(StripeGateway|PaypalGateway|VantivGateway|TapGateway|CybersourceGateway)} paymentGateway
16377
+ * @param {(StripeGateway|PaypalGateway|VantivGateway|TapGateway|CybersourceGateway|BraintreeGateway)} paymentGateway
16369
16378
  */
16370
16379
  constructor(paymentGateway) {
16371
16380
  _defineProperty$3(this, "execute", (options, callback) => {
@@ -16384,7 +16393,7 @@ class Payment {
16384
16393
  _classPrivateFieldInitSpec$1(this, _isPaymentGatewayInvalid, {
16385
16394
  writable: true,
16386
16395
  value: gateway => {
16387
- return gateway && !(gateway instanceof StripeGateway || gateway instanceof PaypalGateway || gateway instanceof VantivGateway || gateway instanceof TapGateway || gateway instanceof CybersourceGateway);
16396
+ return gateway && !(gateway instanceof StripeGateway || gateway instanceof PaypalGateway || gateway instanceof VantivGateway || gateway instanceof TapGateway || gateway instanceof CybersourceGateway || gateway instanceof BraintreeGateway);
16388
16397
  }
16389
16398
  });
16390
16399
  _classPrivateFieldInitSpec$1(this, _generateUserError, {
@@ -16439,7 +16448,8 @@ const PAYMENT_GATEWAYS_ENUM = {
16439
16448
  paypal: "braintree",
16440
16449
  vantiv: "vantiv",
16441
16450
  tap: "tap",
16442
- cybersource: "cybersource"
16451
+ cybersource: "cybersource",
16452
+ braintree: "braintree"
16443
16453
  };
16444
16454
 
16445
16455
  /**
@@ -17378,6 +17388,218 @@ class CybersourceGateway {
17378
17388
  });
17379
17389
  }
17380
17390
  }
17391
+ var _paymentGateway6 = /*#__PURE__*/new WeakMap();
17392
+ var _createSubscription6 = /*#__PURE__*/new WeakMap();
17393
+ var _renewSubscription5 = /*#__PURE__*/new WeakMap();
17394
+ var _createGiftedSubscription6 = /*#__PURE__*/new WeakMap();
17395
+ var _renewGiftedSubscription5 = /*#__PURE__*/new WeakMap();
17396
+ var _purchaseEcommerceOrder5 = /*#__PURE__*/new WeakMap();
17397
+ var _payInvoice6 = /*#__PURE__*/new WeakMap();
17398
+ class BraintreeGateway {
17399
+ constructor() {
17400
+ _classPrivateFieldInitSpec$1(this, _paymentGateway6, {
17401
+ writable: true,
17402
+ value: PAYMENT_GATEWAYS_ENUM["braintree"]
17403
+ });
17404
+ _defineProperty$3(this, "execute", (options, callback) => {
17405
+ const types = PAYMENT_TYPES;
17406
+ switch (options.type) {
17407
+ case types.CREATE_SUBSCRIPTION:
17408
+ return _classPrivateFieldGet(this, _createSubscription6).call(this, options, callback);
17409
+ case types.RENEW_SUBSCRIPTION:
17410
+ return _classPrivateFieldGet(this, _renewSubscription5).call(this, options, callback);
17411
+ case types.CREATE_GIFTED_SUBSCRIPTION:
17412
+ return _classPrivateFieldGet(this, _createGiftedSubscription6).call(this, options, callback);
17413
+ case types.RENEW_GIFTED_SUBSCRIPTION:
17414
+ return _classPrivateFieldGet(this, _renewGiftedSubscription5).call(this, options, callback);
17415
+ case types.PURCHASE_ECOMMERCE_ORDER:
17416
+ return _classPrivateFieldGet(this, _purchaseEcommerceOrder5).call(this, options, callback);
17417
+ case types.PAY_INVOICE:
17418
+ return _classPrivateFieldGet(this, _payInvoice6).call(this, options, callback);
17419
+ default:
17420
+ console.error("Unsupported payment method: braintree Gateway");
17421
+ }
17422
+ });
17423
+ _classPrivateFieldInitSpec$1(this, _createSubscription6, {
17424
+ writable: true,
17425
+ value: (options, callback) => {
17426
+ const {
17427
+ token,
17428
+ plan,
17429
+ couponCode,
17430
+ product,
17431
+ quantity = 1,
17432
+ addressId,
17433
+ isExistingSource
17434
+ } = options;
17435
+ const params = isExistingSource ? {
17436
+ source_id: token
17437
+ } : {
17438
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
17439
+ gateway_token: token
17440
+ };
17441
+ window.Pelcro.subscription.create({
17442
+ quantity,
17443
+ auth_token: window.Pelcro.user.read().auth_token,
17444
+ plan_id: plan.id,
17445
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
17446
+ coupon_code: couponCode,
17447
+ address_id: product.address_required ? addressId : null,
17448
+ ...params
17449
+ }, (err, res) => {
17450
+ callback(err, res);
17451
+ });
17452
+ }
17453
+ });
17454
+ _classPrivateFieldInitSpec$1(this, _renewSubscription5, {
17455
+ writable: true,
17456
+ value: (options, callback) => {
17457
+ const {
17458
+ subscriptionIdToRenew,
17459
+ token,
17460
+ plan,
17461
+ couponCode,
17462
+ product,
17463
+ addressId,
17464
+ isExistingSource
17465
+ } = options;
17466
+ const params = isExistingSource ? {
17467
+ source_id: token
17468
+ } : {
17469
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
17470
+ gateway_token: token
17471
+ };
17472
+ window.Pelcro.subscription.renew({
17473
+ auth_token: window.Pelcro.user.read().auth_token,
17474
+ plan_id: plan.id,
17475
+ coupon_code: couponCode,
17476
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
17477
+ subscription_id: subscriptionIdToRenew,
17478
+ address_id: product.address_required ? addressId : null,
17479
+ ...params
17480
+ }, (err, res) => {
17481
+ callback(err, res);
17482
+ });
17483
+ }
17484
+ });
17485
+ _classPrivateFieldInitSpec$1(this, _createGiftedSubscription6, {
17486
+ writable: true,
17487
+ value: (options, callback) => {
17488
+ const {
17489
+ token,
17490
+ plan,
17491
+ couponCode,
17492
+ product,
17493
+ giftRecipient,
17494
+ quantity = 1,
17495
+ addressId,
17496
+ isExistingSource
17497
+ } = options;
17498
+ const params = isExistingSource ? {
17499
+ source_id: token
17500
+ } : {
17501
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
17502
+ gateway_token: token
17503
+ };
17504
+ window.Pelcro.subscription.create({
17505
+ quantity,
17506
+ auth_token: window.Pelcro.user.read().auth_token,
17507
+ plan_id: plan.id,
17508
+ coupon_code: couponCode,
17509
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
17510
+ gift_recipient_email: giftRecipient.email,
17511
+ gift_recipient_first_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.firstName,
17512
+ gift_recipient_last_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.lastName,
17513
+ gift_start_date: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.startDate,
17514
+ gift_message: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.giftMessage,
17515
+ address_id: product.address_required ? addressId : null,
17516
+ ...params
17517
+ }, (err, res) => {
17518
+ callback(err, res);
17519
+ });
17520
+ }
17521
+ });
17522
+ _classPrivateFieldInitSpec$1(this, _renewGiftedSubscription5, {
17523
+ writable: true,
17524
+ value: (options, callback) => {
17525
+ const {
17526
+ subscriptionIdToRenew,
17527
+ token,
17528
+ product,
17529
+ plan,
17530
+ couponCode,
17531
+ addressId,
17532
+ isExistingSource
17533
+ } = options;
17534
+ const params = isExistingSource ? {
17535
+ source_id: token
17536
+ } : {
17537
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
17538
+ gateway_token: token
17539
+ };
17540
+ window.Pelcro.subscription.renewGift({
17541
+ auth_token: window.Pelcro.user.read().auth_token,
17542
+ plan_id: plan.id,
17543
+ coupon_code: couponCode,
17544
+ subscription_id: subscriptionIdToRenew,
17545
+ address_id: product.address_required ? addressId : null,
17546
+ ...params
17547
+ }, (err, res) => {
17548
+ callback(err, res);
17549
+ });
17550
+ }
17551
+ });
17552
+ _classPrivateFieldInitSpec$1(this, _purchaseEcommerceOrder5, {
17553
+ writable: true,
17554
+ value: (options, callback) => {
17555
+ const {
17556
+ token,
17557
+ items,
17558
+ couponCode,
17559
+ addressId,
17560
+ isExistingSource
17561
+ } = options;
17562
+ const params = isExistingSource ? {
17563
+ source_id: token
17564
+ } : {
17565
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
17566
+ gateway_token: token
17567
+ };
17568
+ window.Pelcro.ecommerce.order.create({
17569
+ items,
17570
+ coupon_code: couponCode,
17571
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
17572
+ ...params,
17573
+ ...(addressId && {
17574
+ address_id: addressId
17575
+ })
17576
+ }, (err, res) => {
17577
+ callback(err, res);
17578
+ });
17579
+ }
17580
+ });
17581
+ _classPrivateFieldInitSpec$1(this, _payInvoice6, {
17582
+ writable: true,
17583
+ value: (options, callback) => {
17584
+ const {
17585
+ token,
17586
+ invoiceId
17587
+ } = options;
17588
+ const params = options.isExistingSource ? {
17589
+ source_id: token,
17590
+ invoice_id: invoiceId
17591
+ } : {
17592
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
17593
+ gateway_token: token,
17594
+ invoice_id: invoiceId
17595
+ };
17596
+ window.Pelcro.invoice.pay(params, (err, res) => {
17597
+ callback(err, res);
17598
+ });
17599
+ }
17600
+ });
17601
+ }
17602
+ }
17381
17603
 
17382
17604
  /**
17383
17605
  * @typedef {Object} PaymentStateType
@@ -17401,6 +17623,7 @@ class CybersourceGateway {
17401
17623
  const initialState$l = {
17402
17624
  disableSubmit: false,
17403
17625
  isLoading: false,
17626
+ isSkeletonLoaded: false,
17404
17627
  disableCouponButton: false,
17405
17628
  couponObject: null,
17406
17629
  couponCode: "",
@@ -17470,7 +17693,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17470
17693
  const isRenewingGift = (_props$isRenewingGift = props.isRenewingGift) !== null && _props$isRenewingGift !== void 0 ? _props$isRenewingGift : pelcroStore.isRenewingGift;
17471
17694
  const invoice = (_props$invoice = props.invoice) !== null && _props$invoice !== void 0 ? _props$invoice : pelcroStore.invoice;
17472
17695
  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;
17473
- const cardProcessor = getSiteCardProcessor();
17696
+ const cardProcessor = getSiteCardProcessor$1();
17474
17697
  useEffect(() => {
17475
17698
  if (window.Pelcro.coupon.getFromUrl()) {
17476
17699
  dispatch({
@@ -18047,54 +18270,622 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18047
18270
  };
18048
18271
  /* ====== End Tap integration ======== */
18049
18272
 
18050
- const submitUsingVantiv = state => {
18051
- const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18052
- if (isUsingExistingPaymentMethod) {
18053
- // no need to create a new source using vantiv
18054
- return handleVantivPayment(null, state.couponCode);
18055
- }
18056
- if (!vantivInstanceRef.current) {
18057
- return console.error("Vantiv sdk script wasn't loaded, you need to load vantiv sdk before rendering the vantiv payment flow");
18058
- }
18059
- const orderId = `pelcro-${new Date().getTime()}`;
18060
- /*
18061
- calls handleVantivPayment to either handle a payment or update a source by simply creating a new source
18062
- */
18063
- vantivInstanceRef.current.getPaypageRegistrationId({
18064
- id: orderId,
18065
- orderId: orderId
18066
- });
18067
- };
18068
- function handleVantivPayment(paymentRequest, couponCode) {
18069
- if (paymentRequest) {
18070
- const SUCCESS_STATUS = "870";
18071
- if (paymentRequest.response !== SUCCESS_STATUS) {
18072
- switch (paymentRequest.response) {
18073
- case "871":
18074
- return handlePaymentError({
18075
- error: new Error("Invalid account number")
18076
- });
18077
- default:
18078
- return handlePaymentError({
18079
- error: new Error(paymentRequest.message)
18080
- });
18273
+ /* ====== Start Braintree integration ======== */
18274
+ const braintreeInstanceRef = React__default.useRef(null);
18275
+ const braintree3DSecureInstanceRef = React__default.useRef(null);
18276
+ function getClientToken() {
18277
+ return new Promise((resolve, reject) => {
18278
+ window.Pelcro.payment.generateClientToken({
18279
+ auth_token: window.Pelcro.user.read().auth_token,
18280
+ site_id: window.Pelcro.siteid
18281
+ }, (error, response) => {
18282
+ if (error) {
18283
+ reject(error);
18284
+ }
18285
+ if (response) {
18286
+ resolve(response.client_token);
18081
18287
  }
18288
+ });
18289
+ });
18290
+ }
18291
+ async function initializeBraintree() {
18292
+ if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
18293
+ if (cardProcessor === "braintree" && !selectedPaymentMethodId) {
18294
+ const braintreeToken = await getClientToken();
18295
+ const isBraintreeEnabled = Boolean(braintreeToken);
18296
+ if (!isBraintreeEnabled) {
18297
+ console.error("Braintree integration is currently not enabled on this site's config");
18298
+ return;
18082
18299
  }
18083
- }
18084
- const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18085
- if (type === "createPayment") {
18086
- handleVantivSubscription();
18087
- } else if (type === "orderCreate") {
18088
- purchase(new VantivGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest, state, dispatch);
18089
- } else if (type === "invoicePayment") {
18090
- payInvoice(new VantivGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest);
18091
- } else if (type === "createPaymentSource") {
18092
- createNewVantivCard();
18093
- } else if (type === "updatePaymentSource") {
18094
- updateVantivCard();
18095
- } else if (type === "deletePaymentSource") {
18096
- replaceVantivCard();
18097
- }
18300
+ if (type !== "updatePaymentSource") {
18301
+ braintreeInstanceRef.current = new window.braintree.client.create({
18302
+ authorization: braintreeToken
18303
+ }).then(clientInstance => {
18304
+ const options = {
18305
+ authorization: braintreeToken,
18306
+ styles: {
18307
+ input: {
18308
+ "font-size": "14px"
18309
+ },
18310
+ "input.invalid": {
18311
+ color: "red"
18312
+ },
18313
+ "input.valid": {
18314
+ color: "green"
18315
+ }
18316
+ },
18317
+ fields: {
18318
+ number: {
18319
+ container: "#card-number",
18320
+ placeholder: "4111 1111 1111 1111"
18321
+ },
18322
+ cvv: {
18323
+ container: "#cvv",
18324
+ placeholder: "123"
18325
+ },
18326
+ expirationDate: {
18327
+ container: "#expiration-date",
18328
+ placeholder: "10/2022"
18329
+ }
18330
+ }
18331
+ };
18332
+ dispatch({
18333
+ type: SKELETON_LOADER,
18334
+ payload: true
18335
+ });
18336
+ braintree3DSecureInstanceRef.current = new window.braintree.threeDSecure.create({
18337
+ version: 2,
18338
+ authorization: braintreeToken
18339
+ }).then(threeDSecureInstance => {
18340
+ return threeDSecureInstance;
18341
+ });
18342
+ return window.braintree.hostedFields.create(options);
18343
+ });
18344
+ braintreeInstanceRef.current.then(hostedFieldInstance => {
18345
+ hostedFieldInstance.on("notEmpty", function (event) {
18346
+ const field = event.fields[event.emittedBy];
18347
+ if (field.isPotentiallyValid) {
18348
+ field.container.classList.remove("pelcro-input-invalid");
18349
+ }
18350
+ });
18351
+ hostedFieldInstance.on("validityChange", function (event) {
18352
+ const field = event.fields[event.emittedBy];
18353
+
18354
+ // Remove any previously applied error or warning classes
18355
+ field.container.classList.remove("is-valid");
18356
+ field.container.classList.remove("pelcro-input-invalid");
18357
+ if (field.isValid) {
18358
+ field.container.classList.add("is-valid");
18359
+ } else if (field.isPotentiallyValid) ; else {
18360
+ field.container.classList.add("pelcro-input-invalid");
18361
+ }
18362
+ });
18363
+ });
18364
+ } else if (type == "updatePaymentSource" && paymentMethodToEdit) {
18365
+ const {
18366
+ properties
18367
+ } = paymentMethodToEdit !== null && paymentMethodToEdit !== void 0 ? paymentMethodToEdit : {};
18368
+ const {
18369
+ exp_month: expMonth,
18370
+ exp_year: expYear
18371
+ } = properties !== null && properties !== void 0 ? properties : {};
18372
+ braintreeInstanceRef.current = new window.braintree.client.create({
18373
+ authorization: braintreeToken
18374
+ }).then(clientInstance => {
18375
+ const options = {
18376
+ client: clientInstance,
18377
+ styles: {
18378
+ input: {
18379
+ "font-size": "14px"
18380
+ },
18381
+ "input.invalid": {
18382
+ color: "red"
18383
+ },
18384
+ "input.valid": {
18385
+ color: "green"
18386
+ }
18387
+ },
18388
+ fields: {
18389
+ expirationMonth: {
18390
+ container: "#expiration-month",
18391
+ prefill: expMonth
18392
+ },
18393
+ expirationYear: {
18394
+ container: "#expiration-year",
18395
+ prefill: expYear
18396
+ }
18397
+ }
18398
+ };
18399
+ dispatch({
18400
+ type: SKELETON_LOADER,
18401
+ payload: true
18402
+ });
18403
+ return window.braintree.hostedFields.create(options);
18404
+ });
18405
+ braintreeInstanceRef.current.then(hostedFieldInstance => {
18406
+ hostedFieldInstance.on("notEmpty", function (event) {
18407
+ const field = event.fields[event.emittedBy];
18408
+ if (field.isPotentiallyValid) {
18409
+ field.container.classList.remove("pelcro-input-invalid");
18410
+ }
18411
+ });
18412
+ hostedFieldInstance.on("validityChange", function (event) {
18413
+ const field = event.fields[event.emittedBy];
18414
+
18415
+ // Remove any previously applied error or warning classes
18416
+ field.container.classList.remove("is-valid");
18417
+ field.container.classList.remove("pelcro-input-invalid");
18418
+ if (field.isValid) {
18419
+ field.container.classList.add("is-valid");
18420
+ } else if (field.isPotentiallyValid) ; else {
18421
+ field.container.classList.add("pelcro-input-invalid");
18422
+ }
18423
+ });
18424
+ });
18425
+ }
18426
+ }
18427
+ }
18428
+ useEffect(() => {
18429
+ initializeBraintree();
18430
+ }, [selectedPaymentMethodId, paymentMethodToEdit]);
18431
+ const braintreeErrorHandler = tokenizeErr => {
18432
+ var _tokenizeErr$details, _tokenizeErr$details2;
18433
+ const cardNumber = document.querySelector("#card-number");
18434
+ const expirationDate = document.querySelector("#expiration-date");
18435
+ const cvv = document.querySelector("#cvv");
18436
+ 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;
18437
+ switch (tokenizeErr.code) {
18438
+ case "HOSTED_FIELDS_FIELDS_EMPTY":
18439
+ // occurs when none of the fields are filled in
18440
+ cardNumber.classList.add("pelcro-input-invalid");
18441
+ expirationDate.classList.add("pelcro-input-invalid");
18442
+ cvv.classList.add("pelcro-input-invalid");
18443
+ return "All fields are empty! Please fill out the form.";
18444
+ // break;
18445
+ case "HOSTED_FIELDS_FIELDS_INVALID":
18446
+ // occurs when certain fields do not pass client side validation
18447
+ console.error("Some fields are invalid:", tokenizeErr.details.invalidFieldKeys.toString());
18448
+
18449
+ // you can also programmatically access the field containers for the invalid fields
18450
+ // tokenizeErr.details.invalidFields.forEach(function (
18451
+ // fieldContainer
18452
+ // ) {
18453
+ // fieldContainer.className = "invalid";
18454
+ // });
18455
+ fields.forEach(field => {
18456
+ field.classList.add("pelcro-input-invalid");
18457
+ });
18458
+ return `Some fields are invalid: ${tokenizeErr.details.invalidFieldKeys.toString()}`;
18459
+ case "HOSTED_FIELDS_TOKENIZATION_FAIL_ON_DUPLICATE":
18460
+ // occurs when:
18461
+ // * the client token used for client authorization was generated
18462
+ // with a customer ID and the fail on duplicate payment method
18463
+ // option is set to true
18464
+ // * the card being tokenized has previously been vaulted (with any customer)
18465
+ // See: https://developer.paypal.com/braintree/docs/reference/request/client-token/generate#options.fail_on_duplicate_payment_method
18466
+ return "This payment method already exists in your vault.";
18467
+ case "HOSTED_FIELDS_TOKENIZATION_CVV_VERIFICATION_FAILED":
18468
+ // occurs when:
18469
+ // * the client token used for client authorization was generated
18470
+ // with a customer ID and the verify card option is set to true
18471
+ // and you have credit card verification turned on in the Braintree
18472
+ // control panel
18473
+ // * the cvv does not pass verification (https://developer.paypal.com/braintree/docs/reference/general/testing#avs-and-cvv/cid-responses)
18474
+ // See: https://developer.paypal.com/braintree/docs/reference/request/client-token/generate#options.verify_card
18475
+ return "CVV did not pass verification";
18476
+ case "HOSTED_FIELDS_FAILED_TOKENIZATION":
18477
+ // occurs for any other tokenization error on the server
18478
+ return "Tokenization failed server side. Is the card valid?";
18479
+ case "HOSTED_FIELDS_TOKENIZATION_NETWORK_ERROR":
18480
+ // occurs when the Braintree gateway cannot be contacted
18481
+ return "Network error occurred when tokenizing.";
18482
+ default:
18483
+ console.error("Something bad happened!", tokenizeErr);
18484
+ return "Something bad happened!";
18485
+ }
18486
+ };
18487
+ const submitUsingBraintree = (state, dispatch) => {
18488
+ var _ref6, _ref7, _state$updatedPrice2;
18489
+ const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18490
+ if (isUsingExistingPaymentMethod) {
18491
+ // no need to create a new source using braintree
18492
+ return handleBraintreePayment(null, state.couponCode);
18493
+ }
18494
+ if (!braintreeInstanceRef.current) {
18495
+ return console.error("Braintree sdk script wasn't loaded, you need to load braintree sdk before rendering the braintree payment flow");
18496
+ }
18497
+ const getOrderItemsTotal = () => {
18498
+ if (!order) {
18499
+ return null;
18500
+ }
18501
+ const isQuickPurchase = !Array.isArray(order);
18502
+ if (isQuickPurchase) {
18503
+ return order.price * order.quantity;
18504
+ }
18505
+ if (order.length === 0) {
18506
+ return null;
18507
+ }
18508
+ return order.reduce((total, item) => {
18509
+ return total + item.price * item.quantity;
18510
+ }, 0);
18511
+ };
18512
+ const totalAmount = (_ref6 = (_ref7 = (_state$updatedPrice2 = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice2 !== void 0 ? _state$updatedPrice2 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref7 !== void 0 ? _ref7 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref6 !== void 0 ? _ref6 : getOrderItemsTotal();
18513
+ braintreeInstanceRef.current.then(hostedFieldInstance => {
18514
+ hostedFieldInstance.tokenize((tokenizeErr, payload) => {
18515
+ if (tokenizeErr) {
18516
+ dispatch({
18517
+ type: DISABLE_SUBMIT,
18518
+ payload: false
18519
+ });
18520
+ dispatch({
18521
+ type: LOADING,
18522
+ payload: false
18523
+ });
18524
+ return dispatch({
18525
+ type: SHOW_ALERT,
18526
+ payload: {
18527
+ type: "error",
18528
+ content: braintreeErrorHandler(tokenizeErr)
18529
+ }
18530
+ });
18531
+ }
18532
+ if (type == "updatePaymentSource" || type == "deletePaymentSource") {
18533
+ handleBraintreePayment(payload, state.couponCode);
18534
+ } else {
18535
+ braintree3DSecureInstanceRef.current.then(threeDSecureInstance => {
18536
+ threeDSecureInstance.verifyCard({
18537
+ onLookupComplete: function (data, next) {
18538
+ next();
18539
+ },
18540
+ amount: totalAmount !== null && totalAmount !== void 0 ? totalAmount : "0.00",
18541
+ nonce: payload.nonce,
18542
+ bin: payload.details.bin
18543
+ }).then(payload => {
18544
+ if (payload.liabilityShifted) {
18545
+ handleBraintreePayment(payload, state.couponCode);
18546
+ } else if (payload.liabilityShiftPossible) {
18547
+ dispatch({
18548
+ type: DISABLE_SUBMIT,
18549
+ payload: false
18550
+ });
18551
+ dispatch({
18552
+ type: LOADING,
18553
+ payload: false
18554
+ });
18555
+ return dispatch({
18556
+ type: SHOW_ALERT,
18557
+ payload: {
18558
+ type: "error",
18559
+ content: "We encountered an issue verifying your transaction with 3D Secure, please try again."
18560
+ }
18561
+ });
18562
+ } else {
18563
+ // Liability has not shifted and will not shift
18564
+ dispatch({
18565
+ type: DISABLE_SUBMIT,
18566
+ payload: false
18567
+ });
18568
+ dispatch({
18569
+ type: LOADING,
18570
+ payload: false
18571
+ });
18572
+ return dispatch({
18573
+ type: SHOW_ALERT,
18574
+ payload: {
18575
+ type: "error",
18576
+ content: "We encountered an issue verifying your transaction with 3D Secure, please try another payment method."
18577
+ }
18578
+ });
18579
+ }
18580
+ }).catch(error => {
18581
+ console.error(error);
18582
+ dispatch({
18583
+ type: DISABLE_SUBMIT,
18584
+ payload: false
18585
+ });
18586
+ dispatch({
18587
+ type: LOADING,
18588
+ payload: false
18589
+ });
18590
+ return dispatch({
18591
+ type: SHOW_ALERT,
18592
+ payload: {
18593
+ type: "error",
18594
+ content: "There was a problem with your request."
18595
+ }
18596
+ });
18597
+ });
18598
+ });
18599
+ }
18600
+ });
18601
+ }).catch(error => {
18602
+ if (error) {
18603
+ console.error(error);
18604
+ return;
18605
+ }
18606
+ });
18607
+ };
18608
+ const handleBraintreePayment = (braintreePaymentRequest, couponCode) => {
18609
+ const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18610
+ const braintreeNonce = braintreePaymentRequest === null || braintreePaymentRequest === void 0 ? void 0 : braintreePaymentRequest.nonce;
18611
+ if (type === "createPayment") {
18612
+ handleBraintreeSubscription();
18613
+ } else if (type === "orderCreate") {
18614
+ purchase(new BraintreeGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce, state, dispatch);
18615
+ } else if (type === "invoicePayment") {
18616
+ payInvoice(new BraintreeGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce);
18617
+ } else if (type === "createPaymentSource") {
18618
+ createNewBraintreeCard();
18619
+ } else if (type === "updatePaymentSource") {
18620
+ updateBraintreeCard();
18621
+ } else if (type === "deletePaymentSource") {
18622
+ replaceBraintreeCard();
18623
+ }
18624
+ function createNewBraintreeCard() {
18625
+ window.Pelcro.paymentMethods.create({
18626
+ auth_token: window.Pelcro.user.read().auth_token,
18627
+ token: braintreeNonce,
18628
+ gateway: "braintree"
18629
+ }, (err, res) => {
18630
+ dispatch({
18631
+ type: DISABLE_SUBMIT,
18632
+ payload: false
18633
+ });
18634
+ dispatch({
18635
+ type: LOADING,
18636
+ payload: false
18637
+ });
18638
+ if (err) {
18639
+ onFailure(err);
18640
+ return dispatch({
18641
+ type: SHOW_ALERT,
18642
+ payload: {
18643
+ type: "error",
18644
+ content: getErrorMessages(err)
18645
+ }
18646
+ });
18647
+ }
18648
+ dispatch({
18649
+ type: SHOW_ALERT,
18650
+ payload: {
18651
+ type: "success",
18652
+ content: t("messages.sourceCreated")
18653
+ }
18654
+ });
18655
+ onSuccess(res);
18656
+ });
18657
+ }
18658
+ function replaceBraintreeCard() {
18659
+ const {
18660
+ id: paymentMethodId
18661
+ } = paymentMethodToDelete;
18662
+ window.Pelcro.paymentMethods.create({
18663
+ auth_token: window.Pelcro.user.read().auth_token,
18664
+ token: braintreeNonce,
18665
+ gateway: "braintree"
18666
+ }, (err, res) => {
18667
+ if (err) {
18668
+ dispatch({
18669
+ type: DISABLE_SUBMIT,
18670
+ payload: false
18671
+ });
18672
+ dispatch({
18673
+ type: LOADING,
18674
+ payload: false
18675
+ });
18676
+ onFailure(err);
18677
+ return dispatch({
18678
+ type: SHOW_ALERT,
18679
+ payload: {
18680
+ type: "error",
18681
+ content: getErrorMessages(err)
18682
+ }
18683
+ });
18684
+ }
18685
+ if (res) {
18686
+ setTimeout(() => {
18687
+ window.Pelcro.paymentMethods.deletePaymentMethod({
18688
+ auth_token: window.Pelcro.user.read().auth_token,
18689
+ payment_method_id: paymentMethodId
18690
+ }, (err, res) => {
18691
+ dispatch({
18692
+ type: DISABLE_SUBMIT,
18693
+ payload: false
18694
+ });
18695
+ dispatch({
18696
+ type: LOADING,
18697
+ payload: false
18698
+ });
18699
+ if (err) {
18700
+ onFailure === null || onFailure === void 0 ? void 0 : onFailure(err);
18701
+ return dispatch({
18702
+ type: SHOW_ALERT,
18703
+ payload: {
18704
+ type: "error",
18705
+ content: getErrorMessages(err)
18706
+ }
18707
+ });
18708
+ }
18709
+ onSuccess(res);
18710
+ });
18711
+ }, 2000);
18712
+ }
18713
+ });
18714
+ }
18715
+ function updateBraintreeCard() {
18716
+ const {
18717
+ id: paymentMethodId
18718
+ } = paymentMethodToEdit;
18719
+ const {
18720
+ expirationMonth,
18721
+ expirationYear
18722
+ } = braintreePaymentRequest === null || braintreePaymentRequest === void 0 ? void 0 : braintreePaymentRequest.details;
18723
+ const {
18724
+ isDefault
18725
+ } = state;
18726
+ window.Pelcro.paymentMethods.update({
18727
+ auth_token: window.Pelcro.user.read().auth_token,
18728
+ payment_method_id: paymentMethodId,
18729
+ token: braintreeNonce,
18730
+ gateway: "braintree",
18731
+ exp_month: expirationMonth,
18732
+ exp_year: expirationYear,
18733
+ is_default: isDefault
18734
+ }, (err, res) => {
18735
+ dispatch({
18736
+ type: DISABLE_SUBMIT,
18737
+ payload: false
18738
+ });
18739
+ dispatch({
18740
+ type: LOADING,
18741
+ payload: false
18742
+ });
18743
+ if (err) {
18744
+ onFailure(err);
18745
+ return dispatch({
18746
+ type: SHOW_ALERT,
18747
+ payload: {
18748
+ type: "error",
18749
+ content: getErrorMessages(err)
18750
+ }
18751
+ });
18752
+ }
18753
+ dispatch({
18754
+ type: SHOW_ALERT,
18755
+ payload: {
18756
+ type: "success",
18757
+ content: t("messages.sourceUpdated")
18758
+ }
18759
+ });
18760
+ onSuccess(res);
18761
+ });
18762
+ }
18763
+ function handleBraintreeSubscription() {
18764
+ const payment = new Payment(new BraintreeGateway());
18765
+ const createSubscription = !isGift && !subscriptionIdToRenew;
18766
+ const renewSubscription = !isGift && subscriptionIdToRenew;
18767
+ const giftSubscriprition = isGift && !subscriptionIdToRenew;
18768
+ const renewGift = isRenewingGift;
18769
+ if (renewGift) {
18770
+ return payment.execute({
18771
+ type: PAYMENT_TYPES.RENEW_GIFTED_SUBSCRIPTION,
18772
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
18773
+ plan,
18774
+ couponCode,
18775
+ product,
18776
+ isExistingSource: isUsingExistingPaymentMethod,
18777
+ subscriptionIdToRenew,
18778
+ addressId: selectedAddressId
18779
+ }, (err, res) => {
18780
+ if (err) {
18781
+ return handlePaymentError(err);
18782
+ }
18783
+ onSuccess(res);
18784
+ });
18785
+ } else if (giftSubscriprition) {
18786
+ return payment.execute({
18787
+ type: PAYMENT_TYPES.CREATE_GIFTED_SUBSCRIPTION,
18788
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
18789
+ quantity: plan.quantity,
18790
+ plan,
18791
+ couponCode,
18792
+ product,
18793
+ isExistingSource: isUsingExistingPaymentMethod,
18794
+ giftRecipient,
18795
+ addressId: selectedAddressId
18796
+ }, (err, res) => {
18797
+ if (err) {
18798
+ return handlePaymentError(err);
18799
+ }
18800
+ onSuccess(res);
18801
+ });
18802
+ } else if (renewSubscription) {
18803
+ return payment.execute({
18804
+ type: PAYMENT_TYPES.RENEW_SUBSCRIPTION,
18805
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
18806
+ quantity: plan.quantity,
18807
+ plan,
18808
+ couponCode,
18809
+ product,
18810
+ isExistingSource: isUsingExistingPaymentMethod,
18811
+ subscriptionIdToRenew,
18812
+ addressId: selectedAddressId
18813
+ }, (err, res) => {
18814
+ if (err) {
18815
+ return handlePaymentError(err);
18816
+ }
18817
+ onSuccess(res);
18818
+ });
18819
+ } else if (createSubscription) {
18820
+ return payment.execute({
18821
+ type: PAYMENT_TYPES.CREATE_SUBSCRIPTION,
18822
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
18823
+ quantity: plan.quantity,
18824
+ plan,
18825
+ couponCode,
18826
+ product,
18827
+ isExistingSource: isUsingExistingPaymentMethod,
18828
+ addressId: selectedAddressId
18829
+ }, (err, res) => {
18830
+ if (err) {
18831
+ return handlePaymentError(err);
18832
+ }
18833
+ onSuccess(res);
18834
+ });
18835
+ }
18836
+ }
18837
+ };
18838
+
18839
+ /* ====== End Braintree integration ======== */
18840
+
18841
+ const submitUsingVantiv = state => {
18842
+ const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18843
+ if (isUsingExistingPaymentMethod) {
18844
+ // no need to create a new source using vantiv
18845
+ return handleVantivPayment(null, state.couponCode);
18846
+ }
18847
+ if (!vantivInstanceRef.current) {
18848
+ return console.error("Vantiv sdk script wasn't loaded, you need to load vantiv sdk before rendering the vantiv payment flow");
18849
+ }
18850
+ const orderId = `pelcro-${new Date().getTime()}`;
18851
+ /*
18852
+ calls handleVantivPayment to either handle a payment or update a source by simply creating a new source
18853
+ */
18854
+ vantivInstanceRef.current.getPaypageRegistrationId({
18855
+ id: orderId,
18856
+ orderId: orderId
18857
+ });
18858
+ };
18859
+ function handleVantivPayment(paymentRequest, couponCode) {
18860
+ if (paymentRequest) {
18861
+ const SUCCESS_STATUS = "870";
18862
+ if (paymentRequest.response !== SUCCESS_STATUS) {
18863
+ switch (paymentRequest.response) {
18864
+ case "871":
18865
+ return handlePaymentError({
18866
+ error: new Error("Invalid account number")
18867
+ });
18868
+ default:
18869
+ return handlePaymentError({
18870
+ error: new Error(paymentRequest.message)
18871
+ });
18872
+ }
18873
+ }
18874
+ }
18875
+ const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18876
+ if (type === "createPayment") {
18877
+ handleVantivSubscription();
18878
+ } else if (type === "orderCreate") {
18879
+ purchase(new VantivGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest, state, dispatch);
18880
+ } else if (type === "invoicePayment") {
18881
+ payInvoice(new VantivGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest);
18882
+ } else if (type === "createPaymentSource") {
18883
+ createNewVantivCard();
18884
+ } else if (type === "updatePaymentSource") {
18885
+ updateVantivCard();
18886
+ } else if (type === "deletePaymentSource") {
18887
+ replaceVantivCard();
18888
+ }
18098
18889
  function createNewVantivCard() {
18099
18890
  window.Pelcro.paymentMethods.create({
18100
18891
  auth_token: window.Pelcro.user.read().auth_token,
@@ -18401,13 +19192,13 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18401
19192
  });
18402
19193
 
18403
19194
  // When Google pay / Apple pay source created
18404
- paymentRequest.on("source", _ref6 => {
19195
+ paymentRequest.on("source", _ref8 => {
18405
19196
  var _source$card;
18406
19197
  let {
18407
19198
  complete,
18408
19199
  source,
18409
19200
  ...data
18410
- } = _ref6;
19201
+ } = _ref8;
18411
19202
  dispatch({
18412
19203
  type: DISABLE_COUPON_BUTTON,
18413
19204
  payload: true
@@ -18422,11 +19213,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18422
19213
  });
18423
19214
  complete("success");
18424
19215
  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") {
18425
- return generate3DSecureSource(source).then(_ref7 => {
19216
+ return generate3DSecureSource(source).then(_ref9 => {
18426
19217
  let {
18427
19218
  source,
18428
19219
  error
18429
- } = _ref7;
19220
+ } = _ref9;
18430
19221
  if (error) {
18431
19222
  return handlePaymentError(error);
18432
19223
  }
@@ -19143,11 +19934,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19143
19934
  const createPaymentSource = (state, dispatch) => {
19144
19935
  return stripe.createSource({
19145
19936
  type: "card"
19146
- }).then(_ref8 => {
19937
+ }).then(_ref10 => {
19147
19938
  let {
19148
19939
  source,
19149
19940
  error
19150
- } = _ref8;
19941
+ } = _ref10;
19151
19942
  if (error) {
19152
19943
  return handlePaymentError(error);
19153
19944
  }
@@ -19261,11 +20052,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19261
20052
  } = paymentMethodToDelete;
19262
20053
  return stripe.createSource({
19263
20054
  type: "card"
19264
- }).then(_ref9 => {
20055
+ }).then(_ref11 => {
19265
20056
  let {
19266
20057
  source,
19267
20058
  error
19268
- } = _ref9;
20059
+ } = _ref11;
19269
20060
  if (error) {
19270
20061
  return handlePaymentError(error);
19271
20062
  }
@@ -19363,12 +20154,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19363
20154
  }
19364
20155
  stripe.createSource({
19365
20156
  type: "card"
19366
- }).then(_ref10 => {
19367
- var _ref11, _ref12, _state$updatedPrice2;
20157
+ }).then(_ref12 => {
20158
+ var _ref13, _ref14, _state$updatedPrice3;
19368
20159
  let {
19369
20160
  source,
19370
20161
  error
19371
- } = _ref10;
20162
+ } = _ref12;
19372
20163
  if (error) {
19373
20164
  return handlePaymentError(error);
19374
20165
  }
@@ -19387,7 +20178,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19387
20178
  return total + item.price * item.quantity;
19388
20179
  }, 0);
19389
20180
  };
19390
- (_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();
20181
+ (_ref13 = (_ref14 = (_state$updatedPrice3 = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice3 !== void 0 ? _state$updatedPrice3 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref14 !== void 0 ? _ref14 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref13 !== void 0 ? _ref13 : getOrderItemsTotal();
19391
20182
  return handlePayment(source);
19392
20183
  }).catch(error => {
19393
20184
  return handlePaymentError(error);
@@ -19569,6 +20360,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19569
20360
  ...state,
19570
20361
  isLoading: action.payload
19571
20362
  });
20363
+ case SKELETON_LOADER:
20364
+ return lib_7({
20365
+ ...state,
20366
+ isSkeletonLoaded: action.payload
20367
+ });
19572
20368
  case SHOW_COUPON_FIELD:
19573
20369
  return lib_7({
19574
20370
  ...state,
@@ -19597,15 +20393,18 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19597
20393
  if (skipPayment && props !== null && props !== void 0 && props.freeOrders) {
19598
20394
  return submitPayment(state);
19599
20395
  }
19600
- if (getSiteCardProcessor() === "vantiv") {
20396
+ if (getSiteCardProcessor$1() === "vantiv") {
19601
20397
  return submitUsingVantiv(state);
19602
20398
  }
19603
- if (getSiteCardProcessor() === "tap") {
20399
+ if (getSiteCardProcessor$1() === "tap") {
19604
20400
  return submitUsingTap(state);
19605
20401
  }
19606
- if (getSiteCardProcessor() === "cybersource") {
20402
+ if (getSiteCardProcessor$1() === "cybersource") {
19607
20403
  return submitUsingCybersource(state, dispatch);
19608
20404
  }
20405
+ if (getSiteCardProcessor$1() === "braintree") {
20406
+ return submitUsingBraintree(state, dispatch);
20407
+ }
19609
20408
  if (selectedPaymentMethodId) {
19610
20409
  // pay with selected method (source) if exists already
19611
20410
  return handlePayment({
@@ -19780,9 +20579,10 @@ const PaymentMethodContainer = props => {
19780
20579
  const {
19781
20580
  whenUserReady
19782
20581
  } = usePelcro.getStore();
19783
- const cardProcessor = getSiteCardProcessor();
20582
+ const cardProcessor = getSiteCardProcessor$1();
19784
20583
  useEffect(() => {
19785
20584
  whenUserReady(() => {
20585
+ // Only load Stripe if it's the configured processor
19786
20586
  if (!window.Stripe && cardProcessor === "stripe") {
19787
20587
  document.querySelector('script[src="https://js.stripe.com/v3"]').addEventListener("load", () => {
19788
20588
  setIsStripeLoaded(true);
@@ -19790,7 +20590,9 @@ const PaymentMethodContainer = props => {
19790
20590
  }
19791
20591
  });
19792
20592
  }, []);
19793
- if (isStripeLoaded) {
20593
+
20594
+ // Ensure we only render Stripe components when Stripe is the processor
20595
+ if (isStripeLoaded && cardProcessor === "stripe") {
19794
20596
  return /*#__PURE__*/React__default.createElement(es_13, {
19795
20597
  apiKey: window.Pelcro.environment.stripe,
19796
20598
  stripeAccount: window.Pelcro.site.read().account_id,
@@ -19993,7 +20795,12 @@ const CheckoutForm = _ref => {
19993
20795
  selectedPaymentMethodId,
19994
20796
  paymentMethodToEdit
19995
20797
  } = usePelcro();
19996
- const cardProcessor = getSiteCardProcessor();
20798
+ const cardProcessor = getSiteCardProcessor$1();
20799
+ const {
20800
+ state: {
20801
+ isSkeletonLoaded
20802
+ }
20803
+ } = useContext(store$l);
19997
20804
  if (selectedPaymentMethodId) {
19998
20805
  return null;
19999
20806
  }
@@ -20025,12 +20832,65 @@ const CheckoutForm = _ref => {
20025
20832
  placeholder: "Exp Year *"
20026
20833
  }))));
20027
20834
  }
20028
- if (cardProcessor === "stripe") {
20835
+ if (cardProcessor === "braintree") {
20029
20836
  if (type === "updatePaymentSource") {
20030
20837
  var _paymentMethodToEdit$;
20838
+ return /*#__PURE__*/React__default.createElement("div", null, isSkeletonLoaded && paymentMethodToEdit ? /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("label", {
20839
+ htmlFor: "card-number"
20840
+ }, "Card Number *"), /*#__PURE__*/React__default.createElement(Input, {
20841
+ id: "card-number",
20842
+ className: "plc-tracking-widest plc-flex-grow plc-h-12 plc-text-center",
20843
+ value: `•••• •••• •••• ${paymentMethodToEdit === null || paymentMethodToEdit === void 0 ? void 0 : (_paymentMethodToEdit$ = paymentMethodToEdit.properties) === null || _paymentMethodToEdit$ === void 0 ? void 0 : _paymentMethodToEdit$.last4}`,
20844
+ disabled: true
20845
+ }), /*#__PURE__*/React__default.createElement("div", {
20846
+ className: "plc-flex plc-items-start plc-space-x-8 plc-my-6"
20847
+ }, /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("label", {
20848
+ htmlFor: "expiration-month"
20849
+ }, "Expiration Month *"), /*#__PURE__*/React__default.createElement("div", {
20850
+ id: "expiration-month",
20851
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
20852
+ })), /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("label", {
20853
+ htmlFor: "expiration-year"
20854
+ }, "Expiration Year *"), /*#__PURE__*/React__default.createElement("div", {
20855
+ id: "expiration-year",
20856
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
20857
+ })))) : /*#__PURE__*/React__default.createElement("div", {
20858
+ className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
20859
+ }));
20860
+ }
20861
+ return /*#__PURE__*/React__default.createElement("div", null, isSkeletonLoaded ? /*#__PURE__*/React__default.createElement("div", {
20862
+ className: "plc-max-w-[50em]"
20863
+ }, /*#__PURE__*/React__default.createElement("label", {
20864
+ htmlFor: "card-number"
20865
+ }, "Card Number *"), /*#__PURE__*/React__default.createElement("div", {
20866
+ id: "card-number",
20867
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
20868
+ }), /*#__PURE__*/React__default.createElement("div", {
20869
+ className: "plc-flex plc-items-start plc-space-x-8 plc-my-6"
20870
+ }, /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("label", {
20871
+ htmlFor: "expiration-date"
20872
+ }, "Expiration Date *"), /*#__PURE__*/React__default.createElement("div", {
20873
+ id: "expiration-date",
20874
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
20875
+ })), /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("label", {
20876
+ htmlFor: "cvv"
20877
+ }, "CVC *"), /*#__PURE__*/React__default.createElement("div", {
20878
+ id: "cvv",
20879
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
20880
+ })))) : /*#__PURE__*/React__default.createElement("div", {
20881
+ className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
20882
+ }));
20883
+ }
20884
+ if (cardProcessor === "stripe") {
20885
+ if (type === "updatePaymentSource") {
20886
+ var _paymentMethodToEdit$2;
20887
+ const currentProcessor = getSiteCardProcessor$1();
20888
+ if (currentProcessor !== "stripe") {
20889
+ return null;
20890
+ }
20031
20891
  return /*#__PURE__*/React__default.createElement("div", null, paymentMethodToEdit ? /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(Input, {
20032
20892
  className: "plc-tracking-widest plc-flex-grow plc-text-center",
20033
- value: `•••• •••• •••• ${paymentMethodToEdit === null || paymentMethodToEdit === void 0 ? void 0 : (_paymentMethodToEdit$ = paymentMethodToEdit.properties) === null || _paymentMethodToEdit$ === void 0 ? void 0 : _paymentMethodToEdit$.last4}`,
20893
+ value: `•••• •••• •••• ${paymentMethodToEdit === null || paymentMethodToEdit === void 0 ? void 0 : (_paymentMethodToEdit$2 = paymentMethodToEdit.properties) === null || _paymentMethodToEdit$2 === void 0 ? void 0 : _paymentMethodToEdit$2.last4}`,
20034
20894
  disabled: true
20035
20895
  })) : /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(Input, {
20036
20896
  className: "plc-bg-gray-300 plc-animate-pulse"
@@ -21153,7 +22013,7 @@ function PaymentMethodUpdateSetDefault(props) {
21153
22013
  *
21154
22014
  */
21155
22015
  function PaymentMethodView(_ref) {
21156
- var _window$Pelcro$site$r, _window$Pelcro$site$r2, _window$Pelcro$site$r3, _calcAndFormatItemsTo, _order$;
22016
+ var _window$Pelcro, _window$Pelcro$uiSett, _window$Pelcro$site$r, _window$Pelcro$site$r2, _window$Pelcro$site$r3, _calcAndFormatItemsTo, _order$;
21157
22017
  let {
21158
22018
  onSuccess,
21159
22019
  onGiftRenewalSuccess,
@@ -21169,7 +22029,8 @@ function PaymentMethodView(_ref) {
21169
22029
  const {
21170
22030
  t
21171
22031
  } = useTranslation("checkoutForm");
21172
- const cardProcessor = getSiteCardProcessor();
22032
+ const cardProcessor = getSiteCardProcessor$1();
22033
+ 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;
21173
22034
  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);
21174
22035
  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);
21175
22036
  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);
@@ -21197,7 +22058,9 @@ function PaymentMethodView(_ref) {
21197
22058
  target: "_blank",
21198
22059
  href: "https://www.stripe.com/us/customers",
21199
22060
  isButton: false
21200
- }, "Stripe"))), /*#__PURE__*/React__default.createElement("form", {
22061
+ }, "Stripe"))), show3DSWarning && /*#__PURE__*/React__default.createElement("div", {
22062
+ 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"
22063
+ }, "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.createElement("form", {
21201
22064
  action: "javascript:void(0);",
21202
22065
  className: "plc-w-full plc-mt-2 plc-font-semibold plc-text-gray-600 pelcro-form"
21203
22066
  }, /*#__PURE__*/React__default.createElement(PaymentMethodContainer, {