@pelcro/react-pelcro-js 3.26.0-beta.51 → 3.26.0-beta.53

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
@@ -18966,6 +19188,358 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18966
19188
  };
18967
19189
  /* ====== End Tap integration ======== */
18968
19190
 
19191
+ /* ====== Start Braintree integration ======== */
19192
+ const braintreeInstanceRef = React__default['default'].useRef(null);
19193
+ React.useEffect(() => {
19194
+ if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
19195
+ if (cardProcessor === "braintree" && !selectedPaymentMethodId) {
19196
+ var _window$Pelcro$site$r6;
19197
+ const {
19198
+ token: braintreeToken
19199
+ } = (_window$Pelcro$site$r6 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r6 === void 0 ? void 0 : _window$Pelcro$site$r6.braintree_gateway_settings;
19200
+ const isBraintreeEnabled = Boolean(braintreeToken);
19201
+ if (!isBraintreeEnabled) {
19202
+ console.error("Braintree integration is currently not enabled on this site's config");
19203
+ return;
19204
+ }
19205
+ braintreeInstanceRef.current = new window.braintree.client.create({
19206
+ authorization: braintreeToken
19207
+ }).then(clientInstance => {
19208
+ const options = {
19209
+ client: clientInstance,
19210
+ styles: {
19211
+ input: {
19212
+ "font-size": "14px"
19213
+ },
19214
+ "input.invalid": {
19215
+ color: "red"
19216
+ },
19217
+ "input.valid": {
19218
+ color: "green"
19219
+ }
19220
+ },
19221
+ fields: {
19222
+ number: {
19223
+ container: "#card-number",
19224
+ placeholder: "4111 1111 1111 1111"
19225
+ },
19226
+ cvv: {
19227
+ container: "#cvv",
19228
+ placeholder: "123"
19229
+ },
19230
+ expirationDate: {
19231
+ container: "#expiration-date",
19232
+ placeholder: "10/2022"
19233
+ }
19234
+ }
19235
+ };
19236
+ return window.braintree.hostedFields.create(options);
19237
+ });
19238
+ }
19239
+ }, [selectedPaymentMethodId]);
19240
+ const braintreeErrorHandler = tokenizeErr => {
19241
+ switch (tokenizeErr.code) {
19242
+ case "HOSTED_FIELDS_FIELDS_EMPTY":
19243
+ // occurs when none of the fields are filled in
19244
+ return "All fields are empty! Please fill out the form.";
19245
+ // break;
19246
+ case "HOSTED_FIELDS_FIELDS_INVALID":
19247
+ // occurs when certain fields do not pass client side validation
19248
+ console.error("Some fields are invalid:", tokenizeErr.details.invalidFieldKeys.toString());
19249
+
19250
+ // you can also programmatically access the field containers for the invalid fields
19251
+ // tokenizeErr.details.invalidFields.forEach(function (
19252
+ // fieldContainer
19253
+ // ) {
19254
+ // fieldContainer.className = "invalid";
19255
+ // });
19256
+ return `Some fields are invalid: ${tokenizeErr.details.invalidFieldKeys.toString()}`;
19257
+ case "HOSTED_FIELDS_TOKENIZATION_FAIL_ON_DUPLICATE":
19258
+ // occurs when:
19259
+ // * the client token used for client authorization was generated
19260
+ // with a customer ID and the fail on duplicate payment method
19261
+ // option is set to true
19262
+ // * the card being tokenized has previously been vaulted (with any customer)
19263
+ // See: https://developer.paypal.com/braintree/docs/reference/request/client-token/generate#options.fail_on_duplicate_payment_method
19264
+ return "This payment method already exists in your vault.";
19265
+ case "HOSTED_FIELDS_TOKENIZATION_CVV_VERIFICATION_FAILED":
19266
+ // occurs when:
19267
+ // * the client token used for client authorization was generated
19268
+ // with a customer ID and the verify card option is set to true
19269
+ // and you have credit card verification turned on in the Braintree
19270
+ // control panel
19271
+ // * the cvv does not pass verification (https://developer.paypal.com/braintree/docs/reference/general/testing#avs-and-cvv/cid-responses)
19272
+ // See: https://developer.paypal.com/braintree/docs/reference/request/client-token/generate#options.verify_card
19273
+ return "CVV did not pass verification";
19274
+ case "HOSTED_FIELDS_FAILED_TOKENIZATION":
19275
+ // occurs for any other tokenization error on the server
19276
+ return "Tokenization failed server side. Is the card valid?";
19277
+ case "HOSTED_FIELDS_TOKENIZATION_NETWORK_ERROR":
19278
+ // occurs when the Braintree gateway cannot be contacted
19279
+ return "Network error occurred when tokenizing.";
19280
+ default:
19281
+ console.error("Something bad happened!", tokenizeErr);
19282
+ return "Something bad happened!";
19283
+ }
19284
+ };
19285
+ const submitUsingBraintree = (state, dispatch) => {
19286
+ const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
19287
+ if (isUsingExistingPaymentMethod) {
19288
+ // no need to create a new source using braintree
19289
+ return handleBraintreePayment(null, state.couponCode);
19290
+ }
19291
+ if (!braintreeInstanceRef.current) {
19292
+ return console.error("Braintree sdk script wasn't loaded, you need to load braintree sdk before rendering the braintree payment flow");
19293
+ }
19294
+ braintreeInstanceRef.current.then(hostedFieldInstance => {
19295
+ hostedFieldInstance.tokenize((tokenizeErr, payload) => {
19296
+ if (tokenizeErr) {
19297
+ dispatch({
19298
+ type: DISABLE_SUBMIT,
19299
+ payload: false
19300
+ });
19301
+ dispatch({
19302
+ type: LOADING,
19303
+ payload: false
19304
+ });
19305
+ return dispatch({
19306
+ type: SHOW_ALERT,
19307
+ payload: {
19308
+ type: "error",
19309
+ content: braintreeErrorHandler(tokenizeErr)
19310
+ }
19311
+ });
19312
+ }
19313
+ handleBraintreePayment(payload.nonce, state);
19314
+ });
19315
+ }).catch(error => {
19316
+ if (error) {
19317
+ console.error(error);
19318
+ return;
19319
+ }
19320
+ });
19321
+ };
19322
+ const handleBraintreePayment = (braintreeNonce, state) => {
19323
+ const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
19324
+ if (type === "createPayment") {
19325
+ handleBraintreeSubscription();
19326
+ } else if (type === "orderCreate") {
19327
+ purchase(new BraintreeGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce, state, dispatch);
19328
+ } else if (type === "invoicePayment") {
19329
+ payInvoice(new BraintreeGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce, dispatch);
19330
+ } else if (type === "createPaymentSource" || type === "updatePaymentSource") {
19331
+ createNewBraintreeCard();
19332
+ } else if (type === "deletePaymentSource") {
19333
+ replaceBraintreeCard();
19334
+ }
19335
+ function createNewBraintreeCard() {
19336
+ window.Pelcro.paymentMethods.create({
19337
+ auth_token: window.Pelcro.user.read().auth_token,
19338
+ token: braintreeNonce,
19339
+ gateway: "braintree"
19340
+ }, (err, res) => {
19341
+ dispatch({
19342
+ type: DISABLE_SUBMIT,
19343
+ payload: false
19344
+ });
19345
+ dispatch({
19346
+ type: LOADING,
19347
+ payload: false
19348
+ });
19349
+ if (err) {
19350
+ onFailure(err);
19351
+ return dispatch({
19352
+ type: SHOW_ALERT,
19353
+ payload: {
19354
+ type: "error",
19355
+ content: getErrorMessages(err)
19356
+ }
19357
+ });
19358
+ }
19359
+ dispatch({
19360
+ type: SHOW_ALERT,
19361
+ payload: {
19362
+ type: "success",
19363
+ content: t("messages.sourceCreated")
19364
+ }
19365
+ });
19366
+ onSuccess(res);
19367
+ });
19368
+ }
19369
+ function replaceBraintreeCard() {
19370
+ const {
19371
+ id: paymentMethodId
19372
+ } = paymentMethodToDelete;
19373
+ window.Pelcro.paymentMethods.create({
19374
+ auth_token: window.Pelcro.user.read().auth_token,
19375
+ token: braintreeNonce,
19376
+ gateway: "braintree"
19377
+ }, (err, res) => {
19378
+ if (err) {
19379
+ dispatch({
19380
+ type: DISABLE_SUBMIT,
19381
+ payload: false
19382
+ });
19383
+ dispatch({
19384
+ type: LOADING,
19385
+ payload: false
19386
+ });
19387
+ onFailure(err);
19388
+ return dispatch({
19389
+ type: SHOW_ALERT,
19390
+ payload: {
19391
+ type: "error",
19392
+ content: getErrorMessages(err)
19393
+ }
19394
+ });
19395
+ }
19396
+ if (res) {
19397
+ setTimeout(() => {
19398
+ window.Pelcro.paymentMethods.deletePaymentMethod({
19399
+ auth_token: window.Pelcro.user.read().auth_token,
19400
+ payment_method_id: paymentMethodId
19401
+ }, (err, res) => {
19402
+ dispatch({
19403
+ type: DISABLE_SUBMIT,
19404
+ payload: false
19405
+ });
19406
+ dispatch({
19407
+ type: LOADING,
19408
+ payload: false
19409
+ });
19410
+ if (err) {
19411
+ onFailure === null || onFailure === void 0 ? void 0 : onFailure(err);
19412
+ return dispatch({
19413
+ type: SHOW_ALERT,
19414
+ payload: {
19415
+ type: "error",
19416
+ content: getErrorMessages(err)
19417
+ }
19418
+ });
19419
+ }
19420
+ onSuccess(res);
19421
+ });
19422
+ }, 2000);
19423
+ }
19424
+ });
19425
+ }
19426
+
19427
+ // TODO: Implement card update
19428
+ // function updateBraintreeCard() {
19429
+ // const { id: paymentMethodId } = paymentMethodToEdit;
19430
+
19431
+ // const { isDefault } = state;
19432
+ // window.Pelcro.paymentMethods.update(
19433
+ // {
19434
+ // auth_token: window.Pelcro.user.read().auth_token,
19435
+ // payment_method_id: paymentMethodId,
19436
+ // gateway: "braintree",
19437
+ // is_default: isDefault
19438
+ // },
19439
+ // (err, res) => {
19440
+ // dispatch({ type: DISABLE_SUBMIT, payload: false });
19441
+ // dispatch({ type: LOADING, payload: false });
19442
+ // if (err) {
19443
+ // onFailure(err);
19444
+ // return dispatch({
19445
+ // type: SHOW_ALERT,
19446
+ // payload: {
19447
+ // type: "error",
19448
+ // content: getErrorMessages(err)
19449
+ // }
19450
+ // });
19451
+ // }
19452
+
19453
+ // dispatch({
19454
+ // type: SHOW_ALERT,
19455
+ // payload: {
19456
+ // type: "success",
19457
+ // content: t("messages.sourceUpdated")
19458
+ // }
19459
+ // });
19460
+ // onSuccess(res);
19461
+ // }
19462
+ // );
19463
+ // }
19464
+
19465
+ function handleBraintreeSubscription() {
19466
+ const payment = new Payment(new BraintreeGateway());
19467
+ const createSubscription = !isGift && !subscriptionIdToRenew;
19468
+ const renewSubscription = !isGift && subscriptionIdToRenew;
19469
+ const giftSubscriprition = isGift && !subscriptionIdToRenew;
19470
+ const renewGift = isRenewingGift;
19471
+ if (renewGift) {
19472
+ return payment.execute({
19473
+ type: PAYMENT_TYPES.RENEW_GIFTED_SUBSCRIPTION,
19474
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
19475
+ plan,
19476
+ couponCode,
19477
+ product,
19478
+ isExistingSource: isUsingExistingPaymentMethod,
19479
+ subscriptionIdToRenew,
19480
+ addressId: selectedAddressId
19481
+ }, (err, res) => {
19482
+ if (err) {
19483
+ return handlePaymentError(err);
19484
+ }
19485
+ onSuccess(res);
19486
+ });
19487
+ } else if (giftSubscriprition) {
19488
+ return payment.execute({
19489
+ type: PAYMENT_TYPES.CREATE_GIFTED_SUBSCRIPTION,
19490
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
19491
+ quantity: plan.quantity,
19492
+ plan,
19493
+ couponCode,
19494
+ product,
19495
+ isExistingSource: isUsingExistingPaymentMethod,
19496
+ giftRecipient,
19497
+ addressId: selectedAddressId
19498
+ }, (err, res) => {
19499
+ if (err) {
19500
+ return handlePaymentError(err);
19501
+ }
19502
+ onSuccess(res);
19503
+ });
19504
+ } else if (renewSubscription) {
19505
+ return payment.execute({
19506
+ type: PAYMENT_TYPES.RENEW_SUBSCRIPTION,
19507
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
19508
+ quantity: plan.quantity,
19509
+ plan,
19510
+ couponCode,
19511
+ product,
19512
+ isExistingSource: isUsingExistingPaymentMethod,
19513
+ subscriptionIdToRenew,
19514
+ addressId: selectedAddressId
19515
+ }, (err, res) => {
19516
+ if (err) {
19517
+ return handlePaymentError(err);
19518
+ }
19519
+ onSuccess(res);
19520
+ });
19521
+ } else if (createSubscription) {
19522
+ return payment.execute({
19523
+ type: PAYMENT_TYPES.CREATE_SUBSCRIPTION,
19524
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
19525
+ quantity: plan.quantity,
19526
+ plan,
19527
+ couponCode,
19528
+ product,
19529
+ isExistingSource: isUsingExistingPaymentMethod,
19530
+ addressId: selectedAddressId
19531
+ }, (err, res) => {
19532
+ if (err) {
19533
+ return handlePaymentError(err);
19534
+ }
19535
+ onSuccess(res);
19536
+ });
19537
+ }
19538
+ }
19539
+ };
19540
+
19541
+ /* ====== End Braintree integration ======== */
19542
+
18969
19543
  const submitUsingVantiv = state => {
18970
19544
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18971
19545
  if (isUsingExistingPaymentMethod) {
@@ -19245,9 +19819,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19245
19819
  React.useEffect(() => {
19246
19820
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
19247
19821
  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;
19822
+ var _window$Pelcro$site$r7, _window$Pelcro$site$r8;
19823
+ 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;
19824
+ 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
19825
  vantivInstanceRef.current = new window.EprotectIframeClient({
19252
19826
  paypageId: payPageId,
19253
19827
  reportGroup: reportGroup,
@@ -19386,9 +19960,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19386
19960
  * Updates the total amount after adding taxes only if site taxes are enabled
19387
19961
  */
19388
19962
  const updateTotalAmountWithTax = () => {
19389
- var _window$Pelcro$site$r8;
19963
+ var _window$Pelcro$site$r9;
19390
19964
  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;
19965
+ 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
19966
  if (taxesEnabled && type === "createPayment") {
19393
19967
  dispatch({
19394
19968
  type: DISABLE_SUBMIT,
@@ -19720,6 +20294,10 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19720
20294
  }).then(res => {
19721
20295
  var _response$data4;
19722
20296
  if (res.error) {
20297
+ dispatch({
20298
+ type: DISABLE_SUBMIT,
20299
+ payload: false
20300
+ });
19723
20301
  dispatch({
19724
20302
  type: LOADING,
19725
20303
  payload: false
@@ -19746,10 +20324,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19746
20324
  return;
19747
20325
  }
19748
20326
  if (flow === "create") {
19749
- dispatch({
19750
- type: DISABLE_SUBMIT,
19751
- payload: false
19752
- });
19753
20327
  dispatch({
19754
20328
  type: LOADING,
19755
20329
  payload: false
@@ -20128,15 +20702,15 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20128
20702
  token: source.id
20129
20703
  }, (err, res) => {
20130
20704
  var _res$data, _res$data$setup_inten, _res$data2, _res$data2$setup_inte;
20131
- dispatch({
20132
- type: DISABLE_SUBMIT,
20133
- payload: false
20134
- });
20135
- dispatch({
20136
- type: LOADING,
20137
- payload: false
20138
- });
20139
20705
  if (err) {
20706
+ dispatch({
20707
+ type: DISABLE_SUBMIT,
20708
+ payload: false
20709
+ });
20710
+ dispatch({
20711
+ type: LOADING,
20712
+ payload: false
20713
+ });
20140
20714
  onFailure(err);
20141
20715
  return dispatch({
20142
20716
  type: SHOW_ALERT,
@@ -20149,6 +20723,10 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20149
20723
  if (((_res$data = res.data) === null || _res$data === void 0 ? void 0 : (_res$data$setup_inten = _res$data.setup_intent) === null || _res$data$setup_inten === void 0 ? void 0 : _res$data$setup_inten.status) === "requires_action" || ((_res$data2 = res.data) === null || _res$data2 === void 0 ? void 0 : (_res$data2$setup_inte = _res$data2.setup_intent) === null || _res$data2$setup_inte === void 0 ? void 0 : _res$data2$setup_inte.status) === "requires_confirmation") {
20150
20724
  confirmStripeIntentSetup(res, "create");
20151
20725
  } else {
20726
+ dispatch({
20727
+ type: LOADING,
20728
+ payload: false
20729
+ });
20152
20730
  dispatch({
20153
20731
  type: SHOW_ALERT,
20154
20732
  payload: {
@@ -20398,11 +20976,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20398
20976
  * @return {Promise}
20399
20977
  */
20400
20978
  const resolveTaxCalculation = () => {
20401
- var _window$Pelcro$site$r9;
20979
+ var _window$Pelcro$site$r10;
20402
20980
  if (type === "invoicePayment") {
20403
20981
  return new Promise(resolve => resolve());
20404
20982
  }
20405
- 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;
20983
+ 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;
20406
20984
  return new Promise((resolve, reject) => {
20407
20985
  // resolve early if taxes isn't enabled
20408
20986
  if (!taxesEnabled) {
@@ -20613,8 +21191,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20613
21191
  if (getSiteCardProcessor() === "cybersource") {
20614
21192
  return submitUsingCybersource(state, dispatch);
20615
21193
  }
20616
- if (getSiteCardProcessor() === "cybersource") {
20617
- return submitUsingCybersource(state, dispatch);
21194
+ if (getSiteCardProcessor() === "braintree") {
21195
+ return submitUsingBraintree(state, dispatch);
20618
21196
  }
20619
21197
  if (selectedPaymentMethodId) {
20620
21198
  if (!isAuthenticated() && plan.type === "donation") {
@@ -21066,6 +21644,28 @@ const CheckoutForm = _ref => {
21066
21644
  placeholder: "Exp Year *"
21067
21645
  }))));
21068
21646
  }
21647
+ if (cardProcessor === "braintree") {
21648
+ return /*#__PURE__*/React__default['default'].createElement("div", {
21649
+ className: "plc-max-w-[50em]"
21650
+ }, /*#__PURE__*/React__default['default'].createElement("label", {
21651
+ htmlFor: "card-number"
21652
+ }, "Card Number"), /*#__PURE__*/React__default['default'].createElement("div", {
21653
+ id: "card-number",
21654
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
21655
+ }), /*#__PURE__*/React__default['default'].createElement("div", {
21656
+ className: "plc-flex plc-items-start plc-space-x-3 plc-mb-4"
21657
+ }, /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
21658
+ htmlFor: "expiration-date"
21659
+ }, "Expiration Date"), /*#__PURE__*/React__default['default'].createElement("div", {
21660
+ id: "expiration-date",
21661
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
21662
+ })), /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
21663
+ htmlFor: "cvv"
21664
+ }, "CVV"), /*#__PURE__*/React__default['default'].createElement("div", {
21665
+ id: "cvv",
21666
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
21667
+ }))));
21668
+ }
21069
21669
  if (cardProcessor === "stripe") {
21070
21670
  if (type === "updatePaymentSource") {
21071
21671
  var _paymentMethodToEdit$;