@pelcro/react-pelcro-js 3.26.0-beta.52 → 3.26.0-beta.54

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
@@ -11928,7 +11928,7 @@ const debounce = (func, waitTime) => {
11928
11928
  };
11929
11929
  };
11930
11930
  function getSiteCardProcessor() {
11931
- var _window$Pelcro$site$r, _window$Pelcro$site$r2, _window$Pelcro$site$r3;
11931
+ var _window$Pelcro$site$r, _window$Pelcro$site$r2, _window$Pelcro$site$r3, _window$Pelcro$site$r4;
11932
11932
  if ((_window$Pelcro$site$r = window.Pelcro.site.read()) !== null && _window$Pelcro$site$r !== void 0 && _window$Pelcro$site$r.vantiv_gateway_settings) {
11933
11933
  return "vantiv";
11934
11934
  }
@@ -11938,6 +11938,9 @@ function getSiteCardProcessor() {
11938
11938
  if ((_window$Pelcro$site$r3 = window.Pelcro.site.read()) !== null && _window$Pelcro$site$r3 !== void 0 && _window$Pelcro$site$r3.cybersource_gateway_settings) {
11939
11939
  return "cybersource";
11940
11940
  }
11941
+ if ((_window$Pelcro$site$r4 = window.Pelcro.site.read()) !== null && _window$Pelcro$site$r4 !== void 0 && _window$Pelcro$site$r4.braintree_gateway_settings) {
11942
+ return "braintree";
11943
+ }
11941
11944
  return "stripe";
11942
11945
  }
11943
11946
  function getFourDigitYear(lastTwoDigits) {
@@ -12038,6 +12041,7 @@ const loadPaymentSDKs = () => {
12038
12041
  usePelcro.getStore();
12039
12042
  const supportsVantiv = Boolean(window.Pelcro.site.read().vantiv_gateway_settings);
12040
12043
  const supportsTap = Boolean(window.Pelcro.site.read().tap_gateway_settings);
12044
+ const supportsBraintree = Boolean(window.Pelcro.site.read().braintree_gateway_settings);
12041
12045
  if (!window.Stripe && !supportsVantiv && !supportsTap) {
12042
12046
  pure_1(window.Pelcro.environment.stripe);
12043
12047
  }
@@ -12045,9 +12049,14 @@ const loadPaymentSDKs = () => {
12045
12049
 
12046
12050
  // Load PayPal SDKs
12047
12051
  const supportsPaypal = Boolean(window.Pelcro.site.read().braintree_tokenization);
12052
+ if (supportsPaypal || supportsBraintree) {
12053
+ window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/client.min.js", "braintree-sdk");
12054
+ }
12048
12055
  if (supportsPaypal) {
12049
- window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.69.0/js/client.min.js", "braintree-sdk");
12050
- window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.69.0/js/paypal-checkout.min.js", "braintree-paypal-sdk");
12056
+ window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/paypal-checkout.min.js", "braintree-paypal-sdk");
12057
+ }
12058
+ if (supportsBraintree) {
12059
+ window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/hosted-fields.min.js", "braintree-histed-fields-sdk");
12051
12060
  }
12052
12061
 
12053
12062
  // Load Vantiv SDKs
@@ -17252,7 +17261,7 @@ var _isPaymentGatewayInvalid = /*#__PURE__*/new WeakMap();
17252
17261
  var _generateUserError = /*#__PURE__*/new WeakMap();
17253
17262
  class Payment {
17254
17263
  /**
17255
- * @param {(StripeGateway|PaypalGateway|VantivGateway|TapGateway|CybersourceGateway)} paymentGateway
17264
+ * @param {(StripeGateway|PaypalGateway|VantivGateway|TapGateway|CybersourceGateway|BraintreeGateway)} paymentGateway
17256
17265
  */
17257
17266
  constructor(paymentGateway) {
17258
17267
  _defineProperty$3(this, "execute", (options, callback) => {
@@ -17271,7 +17280,7 @@ class Payment {
17271
17280
  _classPrivateFieldInitSpec$1(this, _isPaymentGatewayInvalid, {
17272
17281
  writable: true,
17273
17282
  value: gateway => {
17274
- return gateway && !(gateway instanceof StripeGateway || gateway instanceof PaypalGateway || gateway instanceof VantivGateway || gateway instanceof TapGateway || gateway instanceof CybersourceGateway);
17283
+ return gateway && !(gateway instanceof StripeGateway || gateway instanceof PaypalGateway || gateway instanceof VantivGateway || gateway instanceof TapGateway || gateway instanceof CybersourceGateway || gateway instanceof BraintreeGateway);
17275
17284
  }
17276
17285
  });
17277
17286
  _classPrivateFieldInitSpec$1(this, _generateUserError, {
@@ -17326,7 +17335,8 @@ const PAYMENT_GATEWAYS_ENUM = {
17326
17335
  paypal: "braintree",
17327
17336
  vantiv: "vantiv",
17328
17337
  tap: "tap",
17329
- cybersource: "cybersource"
17338
+ cybersource: "cybersource",
17339
+ braintree: "braintree"
17330
17340
  };
17331
17341
 
17332
17342
  /**
@@ -18265,6 +18275,218 @@ class CybersourceGateway {
18265
18275
  });
18266
18276
  }
18267
18277
  }
18278
+ var _paymentGateway6 = /*#__PURE__*/new WeakMap();
18279
+ var _createSubscription6 = /*#__PURE__*/new WeakMap();
18280
+ var _renewSubscription5 = /*#__PURE__*/new WeakMap();
18281
+ var _createGiftedSubscription6 = /*#__PURE__*/new WeakMap();
18282
+ var _renewGiftedSubscription5 = /*#__PURE__*/new WeakMap();
18283
+ var _purchaseEcommerceOrder5 = /*#__PURE__*/new WeakMap();
18284
+ var _payInvoice6 = /*#__PURE__*/new WeakMap();
18285
+ class BraintreeGateway {
18286
+ constructor() {
18287
+ _classPrivateFieldInitSpec$1(this, _paymentGateway6, {
18288
+ writable: true,
18289
+ value: PAYMENT_GATEWAYS_ENUM["braintree"]
18290
+ });
18291
+ _defineProperty$3(this, "execute", (options, callback) => {
18292
+ const types = PAYMENT_TYPES;
18293
+ switch (options.type) {
18294
+ case types.CREATE_SUBSCRIPTION:
18295
+ return _classPrivateFieldGet(this, _createSubscription6).call(this, options, callback);
18296
+ case types.RENEW_SUBSCRIPTION:
18297
+ return _classPrivateFieldGet(this, _renewSubscription5).call(this, options, callback);
18298
+ case types.CREATE_GIFTED_SUBSCRIPTION:
18299
+ return _classPrivateFieldGet(this, _createGiftedSubscription6).call(this, options, callback);
18300
+ case types.RENEW_GIFTED_SUBSCRIPTION:
18301
+ return _classPrivateFieldGet(this, _renewGiftedSubscription5).call(this, options, callback);
18302
+ case types.PURCHASE_ECOMMERCE_ORDER:
18303
+ return _classPrivateFieldGet(this, _purchaseEcommerceOrder5).call(this, options, callback);
18304
+ case types.PAY_INVOICE:
18305
+ return _classPrivateFieldGet(this, _payInvoice6).call(this, options, callback);
18306
+ default:
18307
+ console.error("Unsupported payment method: braintree Gateway");
18308
+ }
18309
+ });
18310
+ _classPrivateFieldInitSpec$1(this, _createSubscription6, {
18311
+ writable: true,
18312
+ value: (options, callback) => {
18313
+ const {
18314
+ token,
18315
+ plan,
18316
+ couponCode,
18317
+ product,
18318
+ quantity = 1,
18319
+ addressId,
18320
+ isExistingSource
18321
+ } = options;
18322
+ const params = isExistingSource ? {
18323
+ source_id: token
18324
+ } : {
18325
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
18326
+ gateway_token: token
18327
+ };
18328
+ window.Pelcro.subscription.create({
18329
+ quantity,
18330
+ auth_token: window.Pelcro.user.read().auth_token,
18331
+ plan_id: plan.id,
18332
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
18333
+ coupon_code: couponCode,
18334
+ address_id: product.address_required ? addressId : null,
18335
+ ...params
18336
+ }, (err, res) => {
18337
+ callback(err, res);
18338
+ });
18339
+ }
18340
+ });
18341
+ _classPrivateFieldInitSpec$1(this, _renewSubscription5, {
18342
+ writable: true,
18343
+ value: (options, callback) => {
18344
+ const {
18345
+ subscriptionIdToRenew,
18346
+ token,
18347
+ plan,
18348
+ couponCode,
18349
+ product,
18350
+ addressId,
18351
+ isExistingSource
18352
+ } = options;
18353
+ const params = isExistingSource ? {
18354
+ source_id: token
18355
+ } : {
18356
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
18357
+ gateway_token: token
18358
+ };
18359
+ window.Pelcro.subscription.renew({
18360
+ auth_token: window.Pelcro.user.read().auth_token,
18361
+ plan_id: plan.id,
18362
+ coupon_code: couponCode,
18363
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
18364
+ subscription_id: subscriptionIdToRenew,
18365
+ address_id: product.address_required ? addressId : null,
18366
+ ...params
18367
+ }, (err, res) => {
18368
+ callback(err, res);
18369
+ });
18370
+ }
18371
+ });
18372
+ _classPrivateFieldInitSpec$1(this, _createGiftedSubscription6, {
18373
+ writable: true,
18374
+ value: (options, callback) => {
18375
+ const {
18376
+ token,
18377
+ plan,
18378
+ couponCode,
18379
+ product,
18380
+ giftRecipient,
18381
+ quantity = 1,
18382
+ addressId,
18383
+ isExistingSource
18384
+ } = options;
18385
+ const params = isExistingSource ? {
18386
+ source_id: token
18387
+ } : {
18388
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
18389
+ gateway_token: token
18390
+ };
18391
+ window.Pelcro.subscription.create({
18392
+ quantity,
18393
+ auth_token: window.Pelcro.user.read().auth_token,
18394
+ plan_id: plan.id,
18395
+ coupon_code: couponCode,
18396
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
18397
+ gift_recipient_email: giftRecipient.email,
18398
+ gift_recipient_first_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.firstName,
18399
+ gift_recipient_last_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.lastName,
18400
+ gift_start_date: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.startDate,
18401
+ gift_message: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.giftMessage,
18402
+ address_id: product.address_required ? addressId : null,
18403
+ ...params
18404
+ }, (err, res) => {
18405
+ callback(err, res);
18406
+ });
18407
+ }
18408
+ });
18409
+ _classPrivateFieldInitSpec$1(this, _renewGiftedSubscription5, {
18410
+ writable: true,
18411
+ value: (options, callback) => {
18412
+ const {
18413
+ subscriptionIdToRenew,
18414
+ token,
18415
+ product,
18416
+ plan,
18417
+ couponCode,
18418
+ addressId,
18419
+ isExistingSource
18420
+ } = options;
18421
+ const params = isExistingSource ? {
18422
+ source_id: token
18423
+ } : {
18424
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
18425
+ gateway_token: token
18426
+ };
18427
+ window.Pelcro.subscription.renewGift({
18428
+ auth_token: window.Pelcro.user.read().auth_token,
18429
+ plan_id: plan.id,
18430
+ coupon_code: couponCode,
18431
+ subscription_id: subscriptionIdToRenew,
18432
+ address_id: product.address_required ? addressId : null,
18433
+ ...params
18434
+ }, (err, res) => {
18435
+ callback(err, res);
18436
+ });
18437
+ }
18438
+ });
18439
+ _classPrivateFieldInitSpec$1(this, _purchaseEcommerceOrder5, {
18440
+ writable: true,
18441
+ value: (options, callback) => {
18442
+ const {
18443
+ token,
18444
+ items,
18445
+ couponCode,
18446
+ addressId,
18447
+ isExistingSource
18448
+ } = options;
18449
+ const params = isExistingSource ? {
18450
+ source_id: token
18451
+ } : {
18452
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
18453
+ gateway_token: token
18454
+ };
18455
+ window.Pelcro.ecommerce.order.create({
18456
+ items,
18457
+ coupon_code: couponCode,
18458
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
18459
+ ...params,
18460
+ ...(addressId && {
18461
+ address_id: addressId
18462
+ })
18463
+ }, (err, res) => {
18464
+ callback(err, res);
18465
+ });
18466
+ }
18467
+ });
18468
+ _classPrivateFieldInitSpec$1(this, _payInvoice6, {
18469
+ writable: true,
18470
+ value: (options, callback) => {
18471
+ const {
18472
+ token,
18473
+ invoiceId
18474
+ } = options;
18475
+ const params = options.isExistingSource ? {
18476
+ source_id: token,
18477
+ invoice_id: invoiceId
18478
+ } : {
18479
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
18480
+ gateway_token: token,
18481
+ invoice_id: invoiceId
18482
+ };
18483
+ window.Pelcro.invoice.pay(params, (err, res) => {
18484
+ callback(err, res);
18485
+ });
18486
+ }
18487
+ });
18488
+ }
18489
+ }
18268
18490
 
18269
18491
  /**
18270
18492
  * @typedef {Object} PaymentStateType
@@ -18288,6 +18510,7 @@ class CybersourceGateway {
18288
18510
  const initialState$l = {
18289
18511
  disableSubmit: false,
18290
18512
  isLoading: false,
18513
+ isSkeletonLoaded: false,
18291
18514
  disableCouponButton: false,
18292
18515
  couponObject: null,
18293
18516
  couponCode: "",
@@ -18966,6 +19189,375 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18966
19189
  };
18967
19190
  /* ====== End Tap integration ======== */
18968
19191
 
19192
+ /* ====== Start Braintree integration ======== */
19193
+ const braintreeInstanceRef = React__default['default'].useRef(null);
19194
+ React.useEffect(() => {
19195
+ if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
19196
+ if (cardProcessor === "braintree" && !selectedPaymentMethodId) {
19197
+ var _window$Pelcro$site$r6;
19198
+ const {
19199
+ token: braintreeToken
19200
+ } = (_window$Pelcro$site$r6 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r6 === void 0 ? void 0 : _window$Pelcro$site$r6.braintree_gateway_settings;
19201
+ const isBraintreeEnabled = Boolean(braintreeToken);
19202
+ if (!isBraintreeEnabled) {
19203
+ console.error("Braintree integration is currently not enabled on this site's config");
19204
+ return;
19205
+ }
19206
+ braintreeInstanceRef.current = new window.braintree.client.create({
19207
+ authorization: braintreeToken
19208
+ }).then(clientInstance => {
19209
+ const options = {
19210
+ client: clientInstance,
19211
+ styles: {
19212
+ input: {
19213
+ "font-size": "14px"
19214
+ },
19215
+ "input.invalid": {
19216
+ color: "red"
19217
+ },
19218
+ "input.valid": {
19219
+ color: "green"
19220
+ }
19221
+ },
19222
+ fields: {
19223
+ number: {
19224
+ container: "#card-number",
19225
+ placeholder: "4111 1111 1111 1111"
19226
+ },
19227
+ cvv: {
19228
+ container: "#cvv",
19229
+ placeholder: "123"
19230
+ },
19231
+ expirationDate: {
19232
+ container: "#expiration-date",
19233
+ placeholder: "10/2022"
19234
+ }
19235
+ }
19236
+ };
19237
+ dispatch({
19238
+ type: SKELETON_LOADER,
19239
+ payload: true
19240
+ });
19241
+ return window.braintree.hostedFields.create(options);
19242
+ });
19243
+ }
19244
+ }, [selectedPaymentMethodId]);
19245
+ const braintreeErrorHandler = tokenizeErr => {
19246
+ switch (tokenizeErr.code) {
19247
+ case "HOSTED_FIELDS_FIELDS_EMPTY":
19248
+ // occurs when none of the fields are filled in
19249
+ return "All fields are empty! Please fill out the form.";
19250
+ // break;
19251
+ case "HOSTED_FIELDS_FIELDS_INVALID":
19252
+ // occurs when certain fields do not pass client side validation
19253
+ console.error("Some fields are invalid:", tokenizeErr.details.invalidFieldKeys.toString());
19254
+
19255
+ // you can also programmatically access the field containers for the invalid fields
19256
+ // tokenizeErr.details.invalidFields.forEach(function (
19257
+ // fieldContainer
19258
+ // ) {
19259
+ // fieldContainer.className = "invalid";
19260
+ // });
19261
+ return `Some fields are invalid: ${tokenizeErr.details.invalidFieldKeys.toString()}`;
19262
+ case "HOSTED_FIELDS_TOKENIZATION_FAIL_ON_DUPLICATE":
19263
+ // occurs when:
19264
+ // * the client token used for client authorization was generated
19265
+ // with a customer ID and the fail on duplicate payment method
19266
+ // option is set to true
19267
+ // * the card being tokenized has previously been vaulted (with any customer)
19268
+ // See: https://developer.paypal.com/braintree/docs/reference/request/client-token/generate#options.fail_on_duplicate_payment_method
19269
+ return "This payment method already exists in your vault.";
19270
+ case "HOSTED_FIELDS_TOKENIZATION_CVV_VERIFICATION_FAILED":
19271
+ // occurs when:
19272
+ // * the client token used for client authorization was generated
19273
+ // with a customer ID and the verify card option is set to true
19274
+ // and you have credit card verification turned on in the Braintree
19275
+ // control panel
19276
+ // * the cvv does not pass verification (https://developer.paypal.com/braintree/docs/reference/general/testing#avs-and-cvv/cid-responses)
19277
+ // See: https://developer.paypal.com/braintree/docs/reference/request/client-token/generate#options.verify_card
19278
+ return "CVV did not pass verification";
19279
+ case "HOSTED_FIELDS_FAILED_TOKENIZATION":
19280
+ // occurs for any other tokenization error on the server
19281
+ return "Tokenization failed server side. Is the card valid?";
19282
+ case "HOSTED_FIELDS_TOKENIZATION_NETWORK_ERROR":
19283
+ // occurs when the Braintree gateway cannot be contacted
19284
+ return "Network error occurred when tokenizing.";
19285
+ default:
19286
+ console.error("Something bad happened!", tokenizeErr);
19287
+ return "Something bad happened!";
19288
+ }
19289
+ };
19290
+ const submitUsingBraintree = (state, dispatch) => {
19291
+ const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
19292
+ if (isUsingExistingPaymentMethod) {
19293
+ // no need to create a new source using braintree
19294
+ return handleBraintreePayment(null, state.couponCode);
19295
+ }
19296
+ if (!braintreeInstanceRef.current) {
19297
+ return console.error("Braintree sdk script wasn't loaded, you need to load braintree sdk before rendering the braintree payment flow");
19298
+ }
19299
+ braintreeInstanceRef.current.then(hostedFieldInstance => {
19300
+ hostedFieldInstance.tokenize((tokenizeErr, payload) => {
19301
+ if (tokenizeErr) {
19302
+ dispatch({
19303
+ type: DISABLE_SUBMIT,
19304
+ payload: false
19305
+ });
19306
+ dispatch({
19307
+ type: LOADING,
19308
+ payload: false
19309
+ });
19310
+ return dispatch({
19311
+ type: SHOW_ALERT,
19312
+ payload: {
19313
+ type: "error",
19314
+ content: braintreeErrorHandler(tokenizeErr)
19315
+ }
19316
+ });
19317
+ }
19318
+ console.log(payload);
19319
+ handleBraintreePayment(payload, state);
19320
+ });
19321
+ }).catch(error => {
19322
+ if (error) {
19323
+ console.error(error);
19324
+ return;
19325
+ }
19326
+ });
19327
+ };
19328
+ const handleBraintreePayment = (braintreePaymentRequest, state) => {
19329
+ const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
19330
+ const braintreeNonce = braintreePaymentRequest === null || braintreePaymentRequest === void 0 ? void 0 : braintreePaymentRequest.nonce;
19331
+ if (type === "createPayment") {
19332
+ handleBraintreeSubscription();
19333
+ } else if (type === "orderCreate") {
19334
+ purchase(new BraintreeGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce, state, dispatch);
19335
+ } else if (type === "invoicePayment") {
19336
+ payInvoice(new BraintreeGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce, dispatch);
19337
+ } else if (type === "createPaymentSource") {
19338
+ createNewBraintreeCard();
19339
+ } else if (type === "updatePaymentSource") {
19340
+ updateBraintreeCard();
19341
+ } else if (type === "deletePaymentSource") {
19342
+ replaceBraintreeCard();
19343
+ }
19344
+ function createNewBraintreeCard() {
19345
+ window.Pelcro.paymentMethods.create({
19346
+ auth_token: window.Pelcro.user.read().auth_token,
19347
+ token: braintreeNonce,
19348
+ gateway: "braintree"
19349
+ }, (err, res) => {
19350
+ dispatch({
19351
+ type: DISABLE_SUBMIT,
19352
+ payload: false
19353
+ });
19354
+ dispatch({
19355
+ type: LOADING,
19356
+ payload: false
19357
+ });
19358
+ if (err) {
19359
+ onFailure(err);
19360
+ return dispatch({
19361
+ type: SHOW_ALERT,
19362
+ payload: {
19363
+ type: "error",
19364
+ content: getErrorMessages(err)
19365
+ }
19366
+ });
19367
+ }
19368
+ dispatch({
19369
+ type: SHOW_ALERT,
19370
+ payload: {
19371
+ type: "success",
19372
+ content: t("messages.sourceCreated")
19373
+ }
19374
+ });
19375
+ onSuccess(res);
19376
+ });
19377
+ }
19378
+ function replaceBraintreeCard() {
19379
+ const {
19380
+ id: paymentMethodId
19381
+ } = paymentMethodToDelete;
19382
+ window.Pelcro.paymentMethods.create({
19383
+ auth_token: window.Pelcro.user.read().auth_token,
19384
+ token: braintreeNonce,
19385
+ gateway: "braintree"
19386
+ }, (err, res) => {
19387
+ if (err) {
19388
+ dispatch({
19389
+ type: DISABLE_SUBMIT,
19390
+ payload: false
19391
+ });
19392
+ dispatch({
19393
+ type: LOADING,
19394
+ payload: false
19395
+ });
19396
+ onFailure(err);
19397
+ return dispatch({
19398
+ type: SHOW_ALERT,
19399
+ payload: {
19400
+ type: "error",
19401
+ content: getErrorMessages(err)
19402
+ }
19403
+ });
19404
+ }
19405
+ if (res) {
19406
+ setTimeout(() => {
19407
+ window.Pelcro.paymentMethods.deletePaymentMethod({
19408
+ auth_token: window.Pelcro.user.read().auth_token,
19409
+ payment_method_id: paymentMethodId
19410
+ }, (err, res) => {
19411
+ dispatch({
19412
+ type: DISABLE_SUBMIT,
19413
+ payload: false
19414
+ });
19415
+ dispatch({
19416
+ type: LOADING,
19417
+ payload: false
19418
+ });
19419
+ if (err) {
19420
+ onFailure === null || onFailure === void 0 ? void 0 : onFailure(err);
19421
+ return dispatch({
19422
+ type: SHOW_ALERT,
19423
+ payload: {
19424
+ type: "error",
19425
+ content: getErrorMessages(err)
19426
+ }
19427
+ });
19428
+ }
19429
+ onSuccess(res);
19430
+ });
19431
+ }, 2000);
19432
+ }
19433
+ });
19434
+ }
19435
+ function updateBraintreeCard() {
19436
+ const {
19437
+ id: paymentMethodId
19438
+ } = paymentMethodToEdit;
19439
+ const {
19440
+ expirationMonth,
19441
+ expirationYear
19442
+ } = braintreePaymentRequest === null || braintreePaymentRequest === void 0 ? void 0 : braintreePaymentRequest.details;
19443
+ const {
19444
+ isDefault
19445
+ } = state;
19446
+ window.Pelcro.paymentMethods.update({
19447
+ auth_token: window.Pelcro.user.read().auth_token,
19448
+ payment_method_id: paymentMethodId,
19449
+ token: braintreeNonce,
19450
+ gateway: "braintree",
19451
+ exp_month: expirationMonth,
19452
+ exp_year: expirationYear,
19453
+ is_default: isDefault
19454
+ }, (err, res) => {
19455
+ dispatch({
19456
+ type: DISABLE_SUBMIT,
19457
+ payload: false
19458
+ });
19459
+ dispatch({
19460
+ type: LOADING,
19461
+ payload: false
19462
+ });
19463
+ if (err) {
19464
+ onFailure(err);
19465
+ return dispatch({
19466
+ type: SHOW_ALERT,
19467
+ payload: {
19468
+ type: "error",
19469
+ content: getErrorMessages(err)
19470
+ }
19471
+ });
19472
+ }
19473
+ dispatch({
19474
+ type: SHOW_ALERT,
19475
+ payload: {
19476
+ type: "success",
19477
+ content: t("messages.sourceUpdated")
19478
+ }
19479
+ });
19480
+ onSuccess(res);
19481
+ });
19482
+ }
19483
+ function handleBraintreeSubscription() {
19484
+ const payment = new Payment(new BraintreeGateway());
19485
+ const createSubscription = !isGift && !subscriptionIdToRenew;
19486
+ const renewSubscription = !isGift && subscriptionIdToRenew;
19487
+ const giftSubscriprition = isGift && !subscriptionIdToRenew;
19488
+ const renewGift = isRenewingGift;
19489
+ if (renewGift) {
19490
+ return payment.execute({
19491
+ type: PAYMENT_TYPES.RENEW_GIFTED_SUBSCRIPTION,
19492
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
19493
+ plan,
19494
+ couponCode,
19495
+ product,
19496
+ isExistingSource: isUsingExistingPaymentMethod,
19497
+ subscriptionIdToRenew,
19498
+ addressId: selectedAddressId
19499
+ }, (err, res) => {
19500
+ if (err) {
19501
+ return handlePaymentError(err);
19502
+ }
19503
+ onSuccess(res);
19504
+ });
19505
+ } else if (giftSubscriprition) {
19506
+ return payment.execute({
19507
+ type: PAYMENT_TYPES.CREATE_GIFTED_SUBSCRIPTION,
19508
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
19509
+ quantity: plan.quantity,
19510
+ plan,
19511
+ couponCode,
19512
+ product,
19513
+ isExistingSource: isUsingExistingPaymentMethod,
19514
+ giftRecipient,
19515
+ addressId: selectedAddressId
19516
+ }, (err, res) => {
19517
+ if (err) {
19518
+ return handlePaymentError(err);
19519
+ }
19520
+ onSuccess(res);
19521
+ });
19522
+ } else if (renewSubscription) {
19523
+ return payment.execute({
19524
+ type: PAYMENT_TYPES.RENEW_SUBSCRIPTION,
19525
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
19526
+ quantity: plan.quantity,
19527
+ plan,
19528
+ couponCode,
19529
+ product,
19530
+ isExistingSource: isUsingExistingPaymentMethod,
19531
+ subscriptionIdToRenew,
19532
+ addressId: selectedAddressId
19533
+ }, (err, res) => {
19534
+ if (err) {
19535
+ return handlePaymentError(err);
19536
+ }
19537
+ onSuccess(res);
19538
+ });
19539
+ } else if (createSubscription) {
19540
+ return payment.execute({
19541
+ type: PAYMENT_TYPES.CREATE_SUBSCRIPTION,
19542
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
19543
+ quantity: plan.quantity,
19544
+ plan,
19545
+ couponCode,
19546
+ product,
19547
+ isExistingSource: isUsingExistingPaymentMethod,
19548
+ addressId: selectedAddressId
19549
+ }, (err, res) => {
19550
+ if (err) {
19551
+ return handlePaymentError(err);
19552
+ }
19553
+ onSuccess(res);
19554
+ });
19555
+ }
19556
+ }
19557
+ };
19558
+
19559
+ /* ====== End Braintree integration ======== */
19560
+
18969
19561
  const submitUsingVantiv = state => {
18970
19562
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18971
19563
  if (isUsingExistingPaymentMethod) {
@@ -19245,9 +19837,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19245
19837
  React.useEffect(() => {
19246
19838
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
19247
19839
  if (cardProcessor === "vantiv" && !selectedPaymentMethodId) {
19248
- var _window$Pelcro$site$r6, _window$Pelcro$site$r7;
19249
- const payPageId = (_window$Pelcro$site$r6 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r6 === void 0 ? void 0 : _window$Pelcro$site$r6.vantiv_gateway_settings.pay_page_id;
19250
- const reportGroup = (_window$Pelcro$site$r7 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r7 === void 0 ? void 0 : _window$Pelcro$site$r7.vantiv_gateway_settings.report_group;
19840
+ var _window$Pelcro$site$r7, _window$Pelcro$site$r8;
19841
+ const payPageId = (_window$Pelcro$site$r7 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r7 === void 0 ? void 0 : _window$Pelcro$site$r7.vantiv_gateway_settings.pay_page_id;
19842
+ const reportGroup = (_window$Pelcro$site$r8 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r8 === void 0 ? void 0 : _window$Pelcro$site$r8.vantiv_gateway_settings.report_group;
19251
19843
  vantivInstanceRef.current = new window.EprotectIframeClient({
19252
19844
  paypageId: payPageId,
19253
19845
  reportGroup: reportGroup,
@@ -19386,9 +19978,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19386
19978
  * Updates the total amount after adding taxes only if site taxes are enabled
19387
19979
  */
19388
19980
  const updateTotalAmountWithTax = () => {
19389
- var _window$Pelcro$site$r8;
19981
+ var _window$Pelcro$site$r9;
19390
19982
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
19391
- const taxesEnabled = (_window$Pelcro$site$r8 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r8 === void 0 ? void 0 : _window$Pelcro$site$r8.taxes_enabled;
19983
+ const taxesEnabled = (_window$Pelcro$site$r9 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r9 === void 0 ? void 0 : _window$Pelcro$site$r9.taxes_enabled;
19392
19984
  if (taxesEnabled && type === "createPayment") {
19393
19985
  dispatch({
19394
19986
  type: DISABLE_SUBMIT,
@@ -20402,11 +20994,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20402
20994
  * @return {Promise}
20403
20995
  */
20404
20996
  const resolveTaxCalculation = () => {
20405
- var _window$Pelcro$site$r9;
20997
+ var _window$Pelcro$site$r10;
20406
20998
  if (type === "invoicePayment") {
20407
20999
  return new Promise(resolve => resolve());
20408
21000
  }
20409
- const taxesEnabled = (_window$Pelcro$site$r9 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r9 === void 0 ? void 0 : _window$Pelcro$site$r9.taxes_enabled;
21001
+ const taxesEnabled = (_window$Pelcro$site$r10 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r10 === void 0 ? void 0 : _window$Pelcro$site$r10.taxes_enabled;
20410
21002
  return new Promise((resolve, reject) => {
20411
21003
  // resolve early if taxes isn't enabled
20412
21004
  if (!taxesEnabled) {
@@ -20572,6 +21164,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20572
21164
  ...state,
20573
21165
  isLoading: action.payload
20574
21166
  });
21167
+ case SKELETON_LOADER:
21168
+ return lib_7({
21169
+ ...state,
21170
+ isSkeletonLoaded: action.payload
21171
+ });
20575
21172
  case SHOW_COUPON_FIELD:
20576
21173
  return lib_7({
20577
21174
  ...state,
@@ -20617,8 +21214,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20617
21214
  if (getSiteCardProcessor() === "cybersource") {
20618
21215
  return submitUsingCybersource(state, dispatch);
20619
21216
  }
20620
- if (getSiteCardProcessor() === "cybersource") {
20621
- return submitUsingCybersource(state, dispatch);
21217
+ if (getSiteCardProcessor() === "braintree") {
21218
+ return submitUsingBraintree(state, dispatch);
20622
21219
  }
20623
21220
  if (selectedPaymentMethodId) {
20624
21221
  if (!isAuthenticated() && plan.type === "donation") {
@@ -21039,6 +21636,11 @@ const CheckoutForm = _ref => {
21039
21636
  paymentMethodToEdit
21040
21637
  } = usePelcro();
21041
21638
  const cardProcessor = getSiteCardProcessor();
21639
+ const {
21640
+ state: {
21641
+ isSkeletonLoaded
21642
+ }
21643
+ } = React.useContext(store$l);
21042
21644
  if (selectedPaymentMethodId) {
21043
21645
  return null;
21044
21646
  }
@@ -21070,6 +21672,30 @@ const CheckoutForm = _ref => {
21070
21672
  placeholder: "Exp Year *"
21071
21673
  }))));
21072
21674
  }
21675
+ if (cardProcessor === "braintree") {
21676
+ return /*#__PURE__*/React__default['default'].createElement("div", null, isSkeletonLoaded ? /*#__PURE__*/React__default['default'].createElement("div", {
21677
+ className: "plc-max-w-[50em]"
21678
+ }, /*#__PURE__*/React__default['default'].createElement("label", {
21679
+ htmlFor: "card-number"
21680
+ }, "Card Number"), /*#__PURE__*/React__default['default'].createElement("div", {
21681
+ id: "card-number",
21682
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
21683
+ }), /*#__PURE__*/React__default['default'].createElement("div", {
21684
+ className: "plc-flex plc-items-start plc-space-x-3 plc-mb-4"
21685
+ }, /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
21686
+ htmlFor: "expiration-date"
21687
+ }, "Expiration Date"), /*#__PURE__*/React__default['default'].createElement("div", {
21688
+ id: "expiration-date",
21689
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
21690
+ })), /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
21691
+ htmlFor: "cvv"
21692
+ }, "CVV"), /*#__PURE__*/React__default['default'].createElement("div", {
21693
+ id: "cvv",
21694
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
21695
+ })))) : /*#__PURE__*/React__default['default'].createElement("div", {
21696
+ className: "plc-w-full plc-h-36 plc-bg-gray-300 plc-rounded plc-animate-pulse"
21697
+ }));
21698
+ }
21073
21699
  if (cardProcessor === "stripe") {
21074
21700
  if (type === "updatePaymentSource") {
21075
21701
  var _paymentMethodToEdit$;