@pelcro/react-pelcro-js 3.37.0 → 3.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +887 -33
- package/dist/index.esm.js +887 -33
- package/dist/pelcro.css +15 -0
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -11636,7 +11636,7 @@ const debounce = (func, waitTime) => {
|
|
|
11636
11636
|
};
|
|
11637
11637
|
};
|
|
11638
11638
|
function getSiteCardProcessor() {
|
|
11639
|
-
var _window$Pelcro$site$r, _window$Pelcro$site$r2, _window$Pelcro$site$r3;
|
|
11639
|
+
var _window$Pelcro$site$r, _window$Pelcro$site$r2, _window$Pelcro$site$r3, _window$Pelcro$site$r4;
|
|
11640
11640
|
if ((_window$Pelcro$site$r = window.Pelcro.site.read()) !== null && _window$Pelcro$site$r !== void 0 && _window$Pelcro$site$r.vantiv_gateway_settings) {
|
|
11641
11641
|
return "vantiv";
|
|
11642
11642
|
}
|
|
@@ -11646,6 +11646,9 @@ function getSiteCardProcessor() {
|
|
|
11646
11646
|
if ((_window$Pelcro$site$r3 = window.Pelcro.site.read()) !== null && _window$Pelcro$site$r3 !== void 0 && _window$Pelcro$site$r3.cybersource_gateway_settings) {
|
|
11647
11647
|
return "cybersource";
|
|
11648
11648
|
}
|
|
11649
|
+
if ((_window$Pelcro$site$r4 = window.Pelcro.site.read()) !== null && _window$Pelcro$site$r4 !== void 0 && _window$Pelcro$site$r4.braintree_gateway_settings) {
|
|
11650
|
+
return "braintree";
|
|
11651
|
+
}
|
|
11649
11652
|
return "stripe";
|
|
11650
11653
|
}
|
|
11651
11654
|
function getFourDigitYear(lastTwoDigits) {
|
|
@@ -11748,6 +11751,7 @@ const loadPaymentSDKs = () => {
|
|
|
11748
11751
|
} = usePelcro.getStore();
|
|
11749
11752
|
const supportsVantiv = Boolean(window.Pelcro.site.read().vantiv_gateway_settings);
|
|
11750
11753
|
const supportsTap = Boolean(window.Pelcro.site.read().tap_gateway_settings);
|
|
11754
|
+
const supportsBraintree = Boolean(window.Pelcro.site.read().braintree_gateway_settings);
|
|
11751
11755
|
whenUserReady(() => {
|
|
11752
11756
|
if (!window.Stripe && !supportsVantiv && !supportsTap) {
|
|
11753
11757
|
pure_1(window.Pelcro.environment.stripe);
|
|
@@ -11757,9 +11761,15 @@ const loadPaymentSDKs = () => {
|
|
|
11757
11761
|
|
|
11758
11762
|
// Load PayPal SDKs
|
|
11759
11763
|
const supportsPaypal = Boolean(window.Pelcro.site.read().braintree_tokenization);
|
|
11764
|
+
if (supportsPaypal || supportsBraintree) {
|
|
11765
|
+
window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/client.min.js", "braintree-sdk");
|
|
11766
|
+
}
|
|
11760
11767
|
if (supportsPaypal) {
|
|
11761
|
-
window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.
|
|
11762
|
-
|
|
11768
|
+
window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/paypal-checkout.min.js", "braintree-paypal-sdk");
|
|
11769
|
+
}
|
|
11770
|
+
if (supportsBraintree) {
|
|
11771
|
+
window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/three-d-secure.min.js", "braintree-3D-secure-sdk");
|
|
11772
|
+
window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/hosted-fields.min.js", "braintree-hosted-fields-sdk");
|
|
11763
11773
|
}
|
|
11764
11774
|
|
|
11765
11775
|
// Load Vantiv SDKs
|
|
@@ -16395,7 +16405,7 @@ var _isPaymentGatewayInvalid = /*#__PURE__*/new WeakMap();
|
|
|
16395
16405
|
var _generateUserError = /*#__PURE__*/new WeakMap();
|
|
16396
16406
|
class Payment {
|
|
16397
16407
|
/**
|
|
16398
|
-
* @param {(StripeGateway|PaypalGateway|VantivGateway|TapGateway|CybersourceGateway)} paymentGateway
|
|
16408
|
+
* @param {(StripeGateway|PaypalGateway|VantivGateway|TapGateway|CybersourceGateway|BraintreeGateway)} paymentGateway
|
|
16399
16409
|
*/
|
|
16400
16410
|
constructor(paymentGateway) {
|
|
16401
16411
|
_defineProperty$3(this, "execute", (options, callback) => {
|
|
@@ -16414,7 +16424,7 @@ class Payment {
|
|
|
16414
16424
|
_classPrivateFieldInitSpec$1(this, _isPaymentGatewayInvalid, {
|
|
16415
16425
|
writable: true,
|
|
16416
16426
|
value: gateway => {
|
|
16417
|
-
return gateway && !(gateway instanceof StripeGateway || gateway instanceof PaypalGateway || gateway instanceof VantivGateway || gateway instanceof TapGateway || gateway instanceof CybersourceGateway);
|
|
16427
|
+
return gateway && !(gateway instanceof StripeGateway || gateway instanceof PaypalGateway || gateway instanceof VantivGateway || gateway instanceof TapGateway || gateway instanceof CybersourceGateway || gateway instanceof BraintreeGateway);
|
|
16418
16428
|
}
|
|
16419
16429
|
});
|
|
16420
16430
|
_classPrivateFieldInitSpec$1(this, _generateUserError, {
|
|
@@ -16469,7 +16479,8 @@ const PAYMENT_GATEWAYS_ENUM = {
|
|
|
16469
16479
|
paypal: "braintree",
|
|
16470
16480
|
vantiv: "vantiv",
|
|
16471
16481
|
tap: "tap",
|
|
16472
|
-
cybersource: "cybersource"
|
|
16482
|
+
cybersource: "cybersource",
|
|
16483
|
+
braintree: "braintree"
|
|
16473
16484
|
};
|
|
16474
16485
|
|
|
16475
16486
|
/**
|
|
@@ -17408,6 +17419,218 @@ class CybersourceGateway {
|
|
|
17408
17419
|
});
|
|
17409
17420
|
}
|
|
17410
17421
|
}
|
|
17422
|
+
var _paymentGateway6 = /*#__PURE__*/new WeakMap();
|
|
17423
|
+
var _createSubscription6 = /*#__PURE__*/new WeakMap();
|
|
17424
|
+
var _renewSubscription5 = /*#__PURE__*/new WeakMap();
|
|
17425
|
+
var _createGiftedSubscription6 = /*#__PURE__*/new WeakMap();
|
|
17426
|
+
var _renewGiftedSubscription5 = /*#__PURE__*/new WeakMap();
|
|
17427
|
+
var _purchaseEcommerceOrder5 = /*#__PURE__*/new WeakMap();
|
|
17428
|
+
var _payInvoice6 = /*#__PURE__*/new WeakMap();
|
|
17429
|
+
class BraintreeGateway {
|
|
17430
|
+
constructor() {
|
|
17431
|
+
_classPrivateFieldInitSpec$1(this, _paymentGateway6, {
|
|
17432
|
+
writable: true,
|
|
17433
|
+
value: PAYMENT_GATEWAYS_ENUM["braintree"]
|
|
17434
|
+
});
|
|
17435
|
+
_defineProperty$3(this, "execute", (options, callback) => {
|
|
17436
|
+
const types = PAYMENT_TYPES;
|
|
17437
|
+
switch (options.type) {
|
|
17438
|
+
case types.CREATE_SUBSCRIPTION:
|
|
17439
|
+
return _classPrivateFieldGet(this, _createSubscription6).call(this, options, callback);
|
|
17440
|
+
case types.RENEW_SUBSCRIPTION:
|
|
17441
|
+
return _classPrivateFieldGet(this, _renewSubscription5).call(this, options, callback);
|
|
17442
|
+
case types.CREATE_GIFTED_SUBSCRIPTION:
|
|
17443
|
+
return _classPrivateFieldGet(this, _createGiftedSubscription6).call(this, options, callback);
|
|
17444
|
+
case types.RENEW_GIFTED_SUBSCRIPTION:
|
|
17445
|
+
return _classPrivateFieldGet(this, _renewGiftedSubscription5).call(this, options, callback);
|
|
17446
|
+
case types.PURCHASE_ECOMMERCE_ORDER:
|
|
17447
|
+
return _classPrivateFieldGet(this, _purchaseEcommerceOrder5).call(this, options, callback);
|
|
17448
|
+
case types.PAY_INVOICE:
|
|
17449
|
+
return _classPrivateFieldGet(this, _payInvoice6).call(this, options, callback);
|
|
17450
|
+
default:
|
|
17451
|
+
console.error("Unsupported payment method: braintree Gateway");
|
|
17452
|
+
}
|
|
17453
|
+
});
|
|
17454
|
+
_classPrivateFieldInitSpec$1(this, _createSubscription6, {
|
|
17455
|
+
writable: true,
|
|
17456
|
+
value: (options, callback) => {
|
|
17457
|
+
const {
|
|
17458
|
+
token,
|
|
17459
|
+
plan,
|
|
17460
|
+
couponCode,
|
|
17461
|
+
product,
|
|
17462
|
+
quantity = 1,
|
|
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.create({
|
|
17473
|
+
quantity,
|
|
17474
|
+
auth_token: window.Pelcro.user.read().auth_token,
|
|
17475
|
+
plan_id: plan.id,
|
|
17476
|
+
campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
|
|
17477
|
+
coupon_code: couponCode,
|
|
17478
|
+
address_id: product.address_required ? addressId : null,
|
|
17479
|
+
...params
|
|
17480
|
+
}, (err, res) => {
|
|
17481
|
+
callback(err, res);
|
|
17482
|
+
});
|
|
17483
|
+
}
|
|
17484
|
+
});
|
|
17485
|
+
_classPrivateFieldInitSpec$1(this, _renewSubscription5, {
|
|
17486
|
+
writable: true,
|
|
17487
|
+
value: (options, callback) => {
|
|
17488
|
+
const {
|
|
17489
|
+
subscriptionIdToRenew,
|
|
17490
|
+
token,
|
|
17491
|
+
plan,
|
|
17492
|
+
couponCode,
|
|
17493
|
+
product,
|
|
17494
|
+
addressId,
|
|
17495
|
+
isExistingSource
|
|
17496
|
+
} = options;
|
|
17497
|
+
const params = isExistingSource ? {
|
|
17498
|
+
source_id: token
|
|
17499
|
+
} : {
|
|
17500
|
+
payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
|
|
17501
|
+
gateway_token: token
|
|
17502
|
+
};
|
|
17503
|
+
window.Pelcro.subscription.renew({
|
|
17504
|
+
auth_token: window.Pelcro.user.read().auth_token,
|
|
17505
|
+
plan_id: plan.id,
|
|
17506
|
+
coupon_code: couponCode,
|
|
17507
|
+
campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
|
|
17508
|
+
subscription_id: subscriptionIdToRenew,
|
|
17509
|
+
address_id: product.address_required ? addressId : null,
|
|
17510
|
+
...params
|
|
17511
|
+
}, (err, res) => {
|
|
17512
|
+
callback(err, res);
|
|
17513
|
+
});
|
|
17514
|
+
}
|
|
17515
|
+
});
|
|
17516
|
+
_classPrivateFieldInitSpec$1(this, _createGiftedSubscription6, {
|
|
17517
|
+
writable: true,
|
|
17518
|
+
value: (options, callback) => {
|
|
17519
|
+
const {
|
|
17520
|
+
token,
|
|
17521
|
+
plan,
|
|
17522
|
+
couponCode,
|
|
17523
|
+
product,
|
|
17524
|
+
giftRecipient,
|
|
17525
|
+
quantity = 1,
|
|
17526
|
+
addressId,
|
|
17527
|
+
isExistingSource
|
|
17528
|
+
} = options;
|
|
17529
|
+
const params = isExistingSource ? {
|
|
17530
|
+
source_id: token
|
|
17531
|
+
} : {
|
|
17532
|
+
payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
|
|
17533
|
+
gateway_token: token
|
|
17534
|
+
};
|
|
17535
|
+
window.Pelcro.subscription.create({
|
|
17536
|
+
quantity,
|
|
17537
|
+
auth_token: window.Pelcro.user.read().auth_token,
|
|
17538
|
+
plan_id: plan.id,
|
|
17539
|
+
coupon_code: couponCode,
|
|
17540
|
+
campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
|
|
17541
|
+
gift_recipient_email: giftRecipient.email,
|
|
17542
|
+
gift_recipient_first_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.firstName,
|
|
17543
|
+
gift_recipient_last_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.lastName,
|
|
17544
|
+
gift_start_date: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.startDate,
|
|
17545
|
+
gift_message: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.giftMessage,
|
|
17546
|
+
address_id: product.address_required ? addressId : null,
|
|
17547
|
+
...params
|
|
17548
|
+
}, (err, res) => {
|
|
17549
|
+
callback(err, res);
|
|
17550
|
+
});
|
|
17551
|
+
}
|
|
17552
|
+
});
|
|
17553
|
+
_classPrivateFieldInitSpec$1(this, _renewGiftedSubscription5, {
|
|
17554
|
+
writable: true,
|
|
17555
|
+
value: (options, callback) => {
|
|
17556
|
+
const {
|
|
17557
|
+
subscriptionIdToRenew,
|
|
17558
|
+
token,
|
|
17559
|
+
product,
|
|
17560
|
+
plan,
|
|
17561
|
+
couponCode,
|
|
17562
|
+
addressId,
|
|
17563
|
+
isExistingSource
|
|
17564
|
+
} = options;
|
|
17565
|
+
const params = isExistingSource ? {
|
|
17566
|
+
source_id: token
|
|
17567
|
+
} : {
|
|
17568
|
+
payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
|
|
17569
|
+
gateway_token: token
|
|
17570
|
+
};
|
|
17571
|
+
window.Pelcro.subscription.renewGift({
|
|
17572
|
+
auth_token: window.Pelcro.user.read().auth_token,
|
|
17573
|
+
plan_id: plan.id,
|
|
17574
|
+
coupon_code: couponCode,
|
|
17575
|
+
subscription_id: subscriptionIdToRenew,
|
|
17576
|
+
address_id: product.address_required ? addressId : null,
|
|
17577
|
+
...params
|
|
17578
|
+
}, (err, res) => {
|
|
17579
|
+
callback(err, res);
|
|
17580
|
+
});
|
|
17581
|
+
}
|
|
17582
|
+
});
|
|
17583
|
+
_classPrivateFieldInitSpec$1(this, _purchaseEcommerceOrder5, {
|
|
17584
|
+
writable: true,
|
|
17585
|
+
value: (options, callback) => {
|
|
17586
|
+
const {
|
|
17587
|
+
token,
|
|
17588
|
+
items,
|
|
17589
|
+
couponCode,
|
|
17590
|
+
addressId,
|
|
17591
|
+
isExistingSource
|
|
17592
|
+
} = options;
|
|
17593
|
+
const params = isExistingSource ? {
|
|
17594
|
+
source_id: token
|
|
17595
|
+
} : {
|
|
17596
|
+
payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
|
|
17597
|
+
gateway_token: token
|
|
17598
|
+
};
|
|
17599
|
+
window.Pelcro.ecommerce.order.create({
|
|
17600
|
+
items,
|
|
17601
|
+
coupon_code: couponCode,
|
|
17602
|
+
campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
|
|
17603
|
+
...params,
|
|
17604
|
+
...(addressId && {
|
|
17605
|
+
address_id: addressId
|
|
17606
|
+
})
|
|
17607
|
+
}, (err, res) => {
|
|
17608
|
+
callback(err, res);
|
|
17609
|
+
});
|
|
17610
|
+
}
|
|
17611
|
+
});
|
|
17612
|
+
_classPrivateFieldInitSpec$1(this, _payInvoice6, {
|
|
17613
|
+
writable: true,
|
|
17614
|
+
value: (options, callback) => {
|
|
17615
|
+
const {
|
|
17616
|
+
token,
|
|
17617
|
+
invoiceId
|
|
17618
|
+
} = options;
|
|
17619
|
+
const params = options.isExistingSource ? {
|
|
17620
|
+
source_id: token,
|
|
17621
|
+
invoice_id: invoiceId
|
|
17622
|
+
} : {
|
|
17623
|
+
payment_gateway: _classPrivateFieldGet(this, _paymentGateway6),
|
|
17624
|
+
gateway_token: token,
|
|
17625
|
+
invoice_id: invoiceId
|
|
17626
|
+
};
|
|
17627
|
+
window.Pelcro.invoice.pay(params, (err, res) => {
|
|
17628
|
+
callback(err, res);
|
|
17629
|
+
});
|
|
17630
|
+
}
|
|
17631
|
+
});
|
|
17632
|
+
}
|
|
17633
|
+
}
|
|
17411
17634
|
|
|
17412
17635
|
/**
|
|
17413
17636
|
* @typedef {Object} PaymentStateType
|
|
@@ -17431,6 +17654,7 @@ class CybersourceGateway {
|
|
|
17431
17654
|
const initialState$l = {
|
|
17432
17655
|
disableSubmit: false,
|
|
17433
17656
|
isLoading: false,
|
|
17657
|
+
isSkeletonLoaded: false,
|
|
17434
17658
|
disableCouponButton: false,
|
|
17435
17659
|
couponObject: null,
|
|
17436
17660
|
couponCode: "",
|
|
@@ -18077,23 +18301,591 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
18077
18301
|
};
|
|
18078
18302
|
/* ====== End Tap integration ======== */
|
|
18079
18303
|
|
|
18080
|
-
|
|
18304
|
+
/* ====== Start Braintree integration ======== */
|
|
18305
|
+
const braintreeInstanceRef = React__default['default'].useRef(null);
|
|
18306
|
+
const braintree3DSecureInstanceRef = React__default['default'].useRef(null);
|
|
18307
|
+
function getClientToken() {
|
|
18308
|
+
return new Promise((resolve, reject) => {
|
|
18309
|
+
window.Pelcro.payment.generateClientToken({
|
|
18310
|
+
auth_token: window.Pelcro.user.read().auth_token,
|
|
18311
|
+
site_id: window.Pelcro.siteid
|
|
18312
|
+
}, (error, response) => {
|
|
18313
|
+
if (error) {
|
|
18314
|
+
reject(error);
|
|
18315
|
+
}
|
|
18316
|
+
if (response) {
|
|
18317
|
+
resolve(response.client_token);
|
|
18318
|
+
}
|
|
18319
|
+
});
|
|
18320
|
+
});
|
|
18321
|
+
}
|
|
18322
|
+
async function initializeBraintree() {
|
|
18323
|
+
if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
|
|
18324
|
+
if (cardProcessor === "braintree" && !selectedPaymentMethodId) {
|
|
18325
|
+
const braintreeToken = await getClientToken();
|
|
18326
|
+
const isBraintreeEnabled = Boolean(braintreeToken);
|
|
18327
|
+
if (!isBraintreeEnabled) {
|
|
18328
|
+
console.error("Braintree integration is currently not enabled on this site's config");
|
|
18329
|
+
return;
|
|
18330
|
+
}
|
|
18331
|
+
if (type !== "updatePaymentSource") {
|
|
18332
|
+
braintreeInstanceRef.current = new window.braintree.client.create({
|
|
18333
|
+
authorization: braintreeToken
|
|
18334
|
+
}).then(clientInstance => {
|
|
18335
|
+
const options = {
|
|
18336
|
+
authorization: braintreeToken,
|
|
18337
|
+
styles: {
|
|
18338
|
+
input: {
|
|
18339
|
+
"font-size": "14px"
|
|
18340
|
+
},
|
|
18341
|
+
"input.invalid": {
|
|
18342
|
+
color: "red"
|
|
18343
|
+
},
|
|
18344
|
+
"input.valid": {
|
|
18345
|
+
color: "green"
|
|
18346
|
+
}
|
|
18347
|
+
},
|
|
18348
|
+
fields: {
|
|
18349
|
+
number: {
|
|
18350
|
+
container: "#card-number",
|
|
18351
|
+
placeholder: "4111 1111 1111 1111"
|
|
18352
|
+
},
|
|
18353
|
+
cvv: {
|
|
18354
|
+
container: "#cvv",
|
|
18355
|
+
placeholder: "123"
|
|
18356
|
+
},
|
|
18357
|
+
expirationDate: {
|
|
18358
|
+
container: "#expiration-date",
|
|
18359
|
+
placeholder: "10/2022"
|
|
18360
|
+
}
|
|
18361
|
+
}
|
|
18362
|
+
};
|
|
18363
|
+
dispatch({
|
|
18364
|
+
type: SKELETON_LOADER,
|
|
18365
|
+
payload: true
|
|
18366
|
+
});
|
|
18367
|
+
braintree3DSecureInstanceRef.current = new window.braintree.threeDSecure.create({
|
|
18368
|
+
version: 2,
|
|
18369
|
+
authorization: braintreeToken
|
|
18370
|
+
}).then(threeDSecureInstance => {
|
|
18371
|
+
return threeDSecureInstance;
|
|
18372
|
+
});
|
|
18373
|
+
return window.braintree.hostedFields.create(options);
|
|
18374
|
+
});
|
|
18375
|
+
braintreeInstanceRef.current.then(hostedFieldInstance => {
|
|
18376
|
+
hostedFieldInstance.on("notEmpty", function (event) {
|
|
18377
|
+
const field = event.fields[event.emittedBy];
|
|
18378
|
+
if (field.isPotentiallyValid) {
|
|
18379
|
+
field.container.classList.remove("pelcro-input-invalid");
|
|
18380
|
+
}
|
|
18381
|
+
});
|
|
18382
|
+
hostedFieldInstance.on("validityChange", function (event) {
|
|
18383
|
+
const field = event.fields[event.emittedBy];
|
|
18384
|
+
|
|
18385
|
+
// Remove any previously applied error or warning classes
|
|
18386
|
+
field.container.classList.remove("is-valid");
|
|
18387
|
+
field.container.classList.remove("pelcro-input-invalid");
|
|
18388
|
+
if (field.isValid) {
|
|
18389
|
+
field.container.classList.add("is-valid");
|
|
18390
|
+
} else if (field.isPotentiallyValid) ; else {
|
|
18391
|
+
field.container.classList.add("pelcro-input-invalid");
|
|
18392
|
+
}
|
|
18393
|
+
});
|
|
18394
|
+
});
|
|
18395
|
+
} else if (type == "updatePaymentSource" && paymentMethodToEdit) {
|
|
18396
|
+
const {
|
|
18397
|
+
properties
|
|
18398
|
+
} = paymentMethodToEdit !== null && paymentMethodToEdit !== void 0 ? paymentMethodToEdit : {};
|
|
18399
|
+
const {
|
|
18400
|
+
exp_month: expMonth,
|
|
18401
|
+
exp_year: expYear
|
|
18402
|
+
} = properties !== null && properties !== void 0 ? properties : {};
|
|
18403
|
+
braintreeInstanceRef.current = new window.braintree.client.create({
|
|
18404
|
+
authorization: braintreeToken
|
|
18405
|
+
}).then(clientInstance => {
|
|
18406
|
+
const options = {
|
|
18407
|
+
client: clientInstance,
|
|
18408
|
+
styles: {
|
|
18409
|
+
input: {
|
|
18410
|
+
"font-size": "14px"
|
|
18411
|
+
},
|
|
18412
|
+
"input.invalid": {
|
|
18413
|
+
color: "red"
|
|
18414
|
+
},
|
|
18415
|
+
"input.valid": {
|
|
18416
|
+
color: "green"
|
|
18417
|
+
}
|
|
18418
|
+
},
|
|
18419
|
+
fields: {
|
|
18420
|
+
expirationMonth: {
|
|
18421
|
+
container: "#expiration-month",
|
|
18422
|
+
prefill: expMonth
|
|
18423
|
+
},
|
|
18424
|
+
expirationYear: {
|
|
18425
|
+
container: "#expiration-year",
|
|
18426
|
+
prefill: expYear
|
|
18427
|
+
}
|
|
18428
|
+
}
|
|
18429
|
+
};
|
|
18430
|
+
dispatch({
|
|
18431
|
+
type: SKELETON_LOADER,
|
|
18432
|
+
payload: true
|
|
18433
|
+
});
|
|
18434
|
+
return window.braintree.hostedFields.create(options);
|
|
18435
|
+
});
|
|
18436
|
+
braintreeInstanceRef.current.then(hostedFieldInstance => {
|
|
18437
|
+
hostedFieldInstance.on("notEmpty", function (event) {
|
|
18438
|
+
const field = event.fields[event.emittedBy];
|
|
18439
|
+
if (field.isPotentiallyValid) {
|
|
18440
|
+
field.container.classList.remove("pelcro-input-invalid");
|
|
18441
|
+
}
|
|
18442
|
+
});
|
|
18443
|
+
hostedFieldInstance.on("validityChange", function (event) {
|
|
18444
|
+
const field = event.fields[event.emittedBy];
|
|
18445
|
+
|
|
18446
|
+
// Remove any previously applied error or warning classes
|
|
18447
|
+
field.container.classList.remove("is-valid");
|
|
18448
|
+
field.container.classList.remove("pelcro-input-invalid");
|
|
18449
|
+
if (field.isValid) {
|
|
18450
|
+
field.container.classList.add("is-valid");
|
|
18451
|
+
} else if (field.isPotentiallyValid) ; else {
|
|
18452
|
+
field.container.classList.add("pelcro-input-invalid");
|
|
18453
|
+
}
|
|
18454
|
+
});
|
|
18455
|
+
});
|
|
18456
|
+
}
|
|
18457
|
+
}
|
|
18458
|
+
}
|
|
18459
|
+
React.useEffect(() => {
|
|
18460
|
+
initializeBraintree();
|
|
18461
|
+
}, [selectedPaymentMethodId, paymentMethodToEdit]);
|
|
18462
|
+
const braintreeErrorHandler = tokenizeErr => {
|
|
18463
|
+
var _tokenizeErr$details, _tokenizeErr$details2;
|
|
18464
|
+
const cardNumber = document.querySelector("#card-number");
|
|
18465
|
+
const expirationDate = document.querySelector("#expiration-date");
|
|
18466
|
+
const cvv = document.querySelector("#cvv");
|
|
18467
|
+
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;
|
|
18468
|
+
switch (tokenizeErr.code) {
|
|
18469
|
+
case "HOSTED_FIELDS_FIELDS_EMPTY":
|
|
18470
|
+
// occurs when none of the fields are filled in
|
|
18471
|
+
cardNumber.classList.add("pelcro-input-invalid");
|
|
18472
|
+
expirationDate.classList.add("pelcro-input-invalid");
|
|
18473
|
+
cvv.classList.add("pelcro-input-invalid");
|
|
18474
|
+
return "All fields are empty! Please fill out the form.";
|
|
18475
|
+
// break;
|
|
18476
|
+
case "HOSTED_FIELDS_FIELDS_INVALID":
|
|
18477
|
+
// occurs when certain fields do not pass client side validation
|
|
18478
|
+
console.error("Some fields are invalid:", tokenizeErr.details.invalidFieldKeys.toString());
|
|
18479
|
+
|
|
18480
|
+
// you can also programmatically access the field containers for the invalid fields
|
|
18481
|
+
// tokenizeErr.details.invalidFields.forEach(function (
|
|
18482
|
+
// fieldContainer
|
|
18483
|
+
// ) {
|
|
18484
|
+
// fieldContainer.className = "invalid";
|
|
18485
|
+
// });
|
|
18486
|
+
fields.forEach(field => {
|
|
18487
|
+
field.classList.add("pelcro-input-invalid");
|
|
18488
|
+
});
|
|
18489
|
+
return `Some fields are invalid: ${tokenizeErr.details.invalidFieldKeys.toString()}`;
|
|
18490
|
+
case "HOSTED_FIELDS_TOKENIZATION_FAIL_ON_DUPLICATE":
|
|
18491
|
+
// occurs when:
|
|
18492
|
+
// * the client token used for client authorization was generated
|
|
18493
|
+
// with a customer ID and the fail on duplicate payment method
|
|
18494
|
+
// option is set to true
|
|
18495
|
+
// * the card being tokenized has previously been vaulted (with any customer)
|
|
18496
|
+
// See: https://developer.paypal.com/braintree/docs/reference/request/client-token/generate#options.fail_on_duplicate_payment_method
|
|
18497
|
+
return "This payment method already exists in your vault.";
|
|
18498
|
+
case "HOSTED_FIELDS_TOKENIZATION_CVV_VERIFICATION_FAILED":
|
|
18499
|
+
// occurs when:
|
|
18500
|
+
// * the client token used for client authorization was generated
|
|
18501
|
+
// with a customer ID and the verify card option is set to true
|
|
18502
|
+
// and you have credit card verification turned on in the Braintree
|
|
18503
|
+
// control panel
|
|
18504
|
+
// * the cvv does not pass verification (https://developer.paypal.com/braintree/docs/reference/general/testing#avs-and-cvv/cid-responses)
|
|
18505
|
+
// See: https://developer.paypal.com/braintree/docs/reference/request/client-token/generate#options.verify_card
|
|
18506
|
+
return "CVV did not pass verification";
|
|
18507
|
+
case "HOSTED_FIELDS_FAILED_TOKENIZATION":
|
|
18508
|
+
// occurs for any other tokenization error on the server
|
|
18509
|
+
return "Tokenization failed server side. Is the card valid?";
|
|
18510
|
+
case "HOSTED_FIELDS_TOKENIZATION_NETWORK_ERROR":
|
|
18511
|
+
// occurs when the Braintree gateway cannot be contacted
|
|
18512
|
+
return "Network error occurred when tokenizing.";
|
|
18513
|
+
default:
|
|
18514
|
+
console.error("Something bad happened!", tokenizeErr);
|
|
18515
|
+
return "Something bad happened!";
|
|
18516
|
+
}
|
|
18517
|
+
};
|
|
18518
|
+
const submitUsingBraintree = (state, dispatch) => {
|
|
18519
|
+
var _ref6, _ref7, _state$updatedPrice2;
|
|
18081
18520
|
const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
|
|
18082
18521
|
if (isUsingExistingPaymentMethod) {
|
|
18083
|
-
// no need to create a new source using
|
|
18084
|
-
return
|
|
18522
|
+
// no need to create a new source using braintree
|
|
18523
|
+
return handleBraintreePayment(null, state.couponCode);
|
|
18085
18524
|
}
|
|
18086
|
-
if (!
|
|
18087
|
-
return console.error("
|
|
18525
|
+
if (!braintreeInstanceRef.current) {
|
|
18526
|
+
return console.error("Braintree sdk script wasn't loaded, you need to load braintree sdk before rendering the braintree payment flow");
|
|
18088
18527
|
}
|
|
18089
|
-
const
|
|
18090
|
-
|
|
18091
|
-
|
|
18092
|
-
|
|
18093
|
-
|
|
18094
|
-
|
|
18095
|
-
|
|
18096
|
-
|
|
18528
|
+
const getOrderItemsTotal = () => {
|
|
18529
|
+
if (!order) {
|
|
18530
|
+
return null;
|
|
18531
|
+
}
|
|
18532
|
+
const isQuickPurchase = !Array.isArray(order);
|
|
18533
|
+
if (isQuickPurchase) {
|
|
18534
|
+
return order.price * order.quantity;
|
|
18535
|
+
}
|
|
18536
|
+
if (order.length === 0) {
|
|
18537
|
+
return null;
|
|
18538
|
+
}
|
|
18539
|
+
return order.reduce((total, item) => {
|
|
18540
|
+
return total + item.price * item.quantity;
|
|
18541
|
+
}, 0);
|
|
18542
|
+
};
|
|
18543
|
+
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();
|
|
18544
|
+
braintreeInstanceRef.current.then(hostedFieldInstance => {
|
|
18545
|
+
hostedFieldInstance.tokenize((tokenizeErr, payload) => {
|
|
18546
|
+
if (tokenizeErr) {
|
|
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: braintreeErrorHandler(tokenizeErr)
|
|
18560
|
+
}
|
|
18561
|
+
});
|
|
18562
|
+
}
|
|
18563
|
+
if (type == "updatePaymentSource" || type == "deletePaymentSource") {
|
|
18564
|
+
handleBraintreePayment(payload, state.couponCode);
|
|
18565
|
+
} else {
|
|
18566
|
+
braintree3DSecureInstanceRef.current.then(threeDSecureInstance => {
|
|
18567
|
+
threeDSecureInstance.verifyCard({
|
|
18568
|
+
onLookupComplete: function (data, next) {
|
|
18569
|
+
next();
|
|
18570
|
+
},
|
|
18571
|
+
amount: totalAmount !== null && totalAmount !== void 0 ? totalAmount : "0.00",
|
|
18572
|
+
nonce: payload.nonce,
|
|
18573
|
+
bin: payload.details.bin
|
|
18574
|
+
}).then(payload => {
|
|
18575
|
+
if (payload.liabilityShifted) {
|
|
18576
|
+
handleBraintreePayment(payload, state.couponCode);
|
|
18577
|
+
} else if (payload.liabilityShiftPossible) {
|
|
18578
|
+
dispatch({
|
|
18579
|
+
type: DISABLE_SUBMIT,
|
|
18580
|
+
payload: false
|
|
18581
|
+
});
|
|
18582
|
+
dispatch({
|
|
18583
|
+
type: LOADING,
|
|
18584
|
+
payload: false
|
|
18585
|
+
});
|
|
18586
|
+
return dispatch({
|
|
18587
|
+
type: SHOW_ALERT,
|
|
18588
|
+
payload: {
|
|
18589
|
+
type: "error",
|
|
18590
|
+
content: "We encountered an issue verifying your transaction with 3D Secure, please try again."
|
|
18591
|
+
}
|
|
18592
|
+
});
|
|
18593
|
+
} else {
|
|
18594
|
+
// Liability has not shifted and will not shift
|
|
18595
|
+
dispatch({
|
|
18596
|
+
type: DISABLE_SUBMIT,
|
|
18597
|
+
payload: false
|
|
18598
|
+
});
|
|
18599
|
+
dispatch({
|
|
18600
|
+
type: LOADING,
|
|
18601
|
+
payload: false
|
|
18602
|
+
});
|
|
18603
|
+
return dispatch({
|
|
18604
|
+
type: SHOW_ALERT,
|
|
18605
|
+
payload: {
|
|
18606
|
+
type: "error",
|
|
18607
|
+
content: "We encountered an issue verifying your transaction with 3D Secure, please try another payment method."
|
|
18608
|
+
}
|
|
18609
|
+
});
|
|
18610
|
+
}
|
|
18611
|
+
}).catch(error => {
|
|
18612
|
+
console.error(error);
|
|
18613
|
+
dispatch({
|
|
18614
|
+
type: DISABLE_SUBMIT,
|
|
18615
|
+
payload: false
|
|
18616
|
+
});
|
|
18617
|
+
dispatch({
|
|
18618
|
+
type: LOADING,
|
|
18619
|
+
payload: false
|
|
18620
|
+
});
|
|
18621
|
+
return dispatch({
|
|
18622
|
+
type: SHOW_ALERT,
|
|
18623
|
+
payload: {
|
|
18624
|
+
type: "error",
|
|
18625
|
+
content: "There was a problem with your request."
|
|
18626
|
+
}
|
|
18627
|
+
});
|
|
18628
|
+
});
|
|
18629
|
+
});
|
|
18630
|
+
}
|
|
18631
|
+
});
|
|
18632
|
+
}).catch(error => {
|
|
18633
|
+
if (error) {
|
|
18634
|
+
console.error(error);
|
|
18635
|
+
return;
|
|
18636
|
+
}
|
|
18637
|
+
});
|
|
18638
|
+
};
|
|
18639
|
+
const handleBraintreePayment = (braintreePaymentRequest, couponCode) => {
|
|
18640
|
+
const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
|
|
18641
|
+
const braintreeNonce = braintreePaymentRequest === null || braintreePaymentRequest === void 0 ? void 0 : braintreePaymentRequest.nonce;
|
|
18642
|
+
if (type === "createPayment") {
|
|
18643
|
+
handleBraintreeSubscription();
|
|
18644
|
+
} else if (type === "orderCreate") {
|
|
18645
|
+
purchase(new BraintreeGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce, state, dispatch);
|
|
18646
|
+
} else if (type === "invoicePayment") {
|
|
18647
|
+
payInvoice(new BraintreeGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce);
|
|
18648
|
+
} else if (type === "createPaymentSource") {
|
|
18649
|
+
createNewBraintreeCard();
|
|
18650
|
+
} else if (type === "updatePaymentSource") {
|
|
18651
|
+
updateBraintreeCard();
|
|
18652
|
+
} else if (type === "deletePaymentSource") {
|
|
18653
|
+
replaceBraintreeCard();
|
|
18654
|
+
}
|
|
18655
|
+
function createNewBraintreeCard() {
|
|
18656
|
+
window.Pelcro.paymentMethods.create({
|
|
18657
|
+
auth_token: window.Pelcro.user.read().auth_token,
|
|
18658
|
+
token: braintreeNonce,
|
|
18659
|
+
gateway: "braintree"
|
|
18660
|
+
}, (err, res) => {
|
|
18661
|
+
dispatch({
|
|
18662
|
+
type: DISABLE_SUBMIT,
|
|
18663
|
+
payload: false
|
|
18664
|
+
});
|
|
18665
|
+
dispatch({
|
|
18666
|
+
type: LOADING,
|
|
18667
|
+
payload: false
|
|
18668
|
+
});
|
|
18669
|
+
if (err) {
|
|
18670
|
+
onFailure(err);
|
|
18671
|
+
return dispatch({
|
|
18672
|
+
type: SHOW_ALERT,
|
|
18673
|
+
payload: {
|
|
18674
|
+
type: "error",
|
|
18675
|
+
content: getErrorMessages(err)
|
|
18676
|
+
}
|
|
18677
|
+
});
|
|
18678
|
+
}
|
|
18679
|
+
dispatch({
|
|
18680
|
+
type: SHOW_ALERT,
|
|
18681
|
+
payload: {
|
|
18682
|
+
type: "success",
|
|
18683
|
+
content: t("messages.sourceCreated")
|
|
18684
|
+
}
|
|
18685
|
+
});
|
|
18686
|
+
onSuccess(res);
|
|
18687
|
+
});
|
|
18688
|
+
}
|
|
18689
|
+
function replaceBraintreeCard() {
|
|
18690
|
+
const {
|
|
18691
|
+
id: paymentMethodId
|
|
18692
|
+
} = paymentMethodToDelete;
|
|
18693
|
+
window.Pelcro.paymentMethods.create({
|
|
18694
|
+
auth_token: window.Pelcro.user.read().auth_token,
|
|
18695
|
+
token: braintreeNonce,
|
|
18696
|
+
gateway: "braintree"
|
|
18697
|
+
}, (err, res) => {
|
|
18698
|
+
if (err) {
|
|
18699
|
+
dispatch({
|
|
18700
|
+
type: DISABLE_SUBMIT,
|
|
18701
|
+
payload: false
|
|
18702
|
+
});
|
|
18703
|
+
dispatch({
|
|
18704
|
+
type: LOADING,
|
|
18705
|
+
payload: false
|
|
18706
|
+
});
|
|
18707
|
+
onFailure(err);
|
|
18708
|
+
return dispatch({
|
|
18709
|
+
type: SHOW_ALERT,
|
|
18710
|
+
payload: {
|
|
18711
|
+
type: "error",
|
|
18712
|
+
content: getErrorMessages(err)
|
|
18713
|
+
}
|
|
18714
|
+
});
|
|
18715
|
+
}
|
|
18716
|
+
if (res) {
|
|
18717
|
+
setTimeout(() => {
|
|
18718
|
+
window.Pelcro.paymentMethods.deletePaymentMethod({
|
|
18719
|
+
auth_token: window.Pelcro.user.read().auth_token,
|
|
18720
|
+
payment_method_id: paymentMethodId
|
|
18721
|
+
}, (err, res) => {
|
|
18722
|
+
dispatch({
|
|
18723
|
+
type: DISABLE_SUBMIT,
|
|
18724
|
+
payload: false
|
|
18725
|
+
});
|
|
18726
|
+
dispatch({
|
|
18727
|
+
type: LOADING,
|
|
18728
|
+
payload: false
|
|
18729
|
+
});
|
|
18730
|
+
if (err) {
|
|
18731
|
+
onFailure === null || onFailure === void 0 ? void 0 : onFailure(err);
|
|
18732
|
+
return dispatch({
|
|
18733
|
+
type: SHOW_ALERT,
|
|
18734
|
+
payload: {
|
|
18735
|
+
type: "error",
|
|
18736
|
+
content: getErrorMessages(err)
|
|
18737
|
+
}
|
|
18738
|
+
});
|
|
18739
|
+
}
|
|
18740
|
+
onSuccess(res);
|
|
18741
|
+
});
|
|
18742
|
+
}, 2000);
|
|
18743
|
+
}
|
|
18744
|
+
});
|
|
18745
|
+
}
|
|
18746
|
+
function updateBraintreeCard() {
|
|
18747
|
+
const {
|
|
18748
|
+
id: paymentMethodId
|
|
18749
|
+
} = paymentMethodToEdit;
|
|
18750
|
+
const {
|
|
18751
|
+
expirationMonth,
|
|
18752
|
+
expirationYear
|
|
18753
|
+
} = braintreePaymentRequest === null || braintreePaymentRequest === void 0 ? void 0 : braintreePaymentRequest.details;
|
|
18754
|
+
const {
|
|
18755
|
+
isDefault
|
|
18756
|
+
} = state;
|
|
18757
|
+
window.Pelcro.paymentMethods.update({
|
|
18758
|
+
auth_token: window.Pelcro.user.read().auth_token,
|
|
18759
|
+
payment_method_id: paymentMethodId,
|
|
18760
|
+
token: braintreeNonce,
|
|
18761
|
+
gateway: "braintree",
|
|
18762
|
+
exp_month: expirationMonth,
|
|
18763
|
+
exp_year: expirationYear,
|
|
18764
|
+
is_default: isDefault
|
|
18765
|
+
}, (err, res) => {
|
|
18766
|
+
dispatch({
|
|
18767
|
+
type: DISABLE_SUBMIT,
|
|
18768
|
+
payload: false
|
|
18769
|
+
});
|
|
18770
|
+
dispatch({
|
|
18771
|
+
type: LOADING,
|
|
18772
|
+
payload: false
|
|
18773
|
+
});
|
|
18774
|
+
if (err) {
|
|
18775
|
+
onFailure(err);
|
|
18776
|
+
return dispatch({
|
|
18777
|
+
type: SHOW_ALERT,
|
|
18778
|
+
payload: {
|
|
18779
|
+
type: "error",
|
|
18780
|
+
content: getErrorMessages(err)
|
|
18781
|
+
}
|
|
18782
|
+
});
|
|
18783
|
+
}
|
|
18784
|
+
dispatch({
|
|
18785
|
+
type: SHOW_ALERT,
|
|
18786
|
+
payload: {
|
|
18787
|
+
type: "success",
|
|
18788
|
+
content: t("messages.sourceUpdated")
|
|
18789
|
+
}
|
|
18790
|
+
});
|
|
18791
|
+
onSuccess(res);
|
|
18792
|
+
});
|
|
18793
|
+
}
|
|
18794
|
+
function handleBraintreeSubscription() {
|
|
18795
|
+
const payment = new Payment(new BraintreeGateway());
|
|
18796
|
+
const createSubscription = !isGift && !subscriptionIdToRenew;
|
|
18797
|
+
const renewSubscription = !isGift && subscriptionIdToRenew;
|
|
18798
|
+
const giftSubscriprition = isGift && !subscriptionIdToRenew;
|
|
18799
|
+
const renewGift = isRenewingGift;
|
|
18800
|
+
if (renewGift) {
|
|
18801
|
+
return payment.execute({
|
|
18802
|
+
type: PAYMENT_TYPES.RENEW_GIFTED_SUBSCRIPTION,
|
|
18803
|
+
token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
|
|
18804
|
+
plan,
|
|
18805
|
+
couponCode,
|
|
18806
|
+
product,
|
|
18807
|
+
isExistingSource: isUsingExistingPaymentMethod,
|
|
18808
|
+
subscriptionIdToRenew,
|
|
18809
|
+
addressId: selectedAddressId
|
|
18810
|
+
}, (err, res) => {
|
|
18811
|
+
if (err) {
|
|
18812
|
+
return handlePaymentError(err);
|
|
18813
|
+
}
|
|
18814
|
+
onSuccess(res);
|
|
18815
|
+
});
|
|
18816
|
+
} else if (giftSubscriprition) {
|
|
18817
|
+
return payment.execute({
|
|
18818
|
+
type: PAYMENT_TYPES.CREATE_GIFTED_SUBSCRIPTION,
|
|
18819
|
+
token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
|
|
18820
|
+
quantity: plan.quantity,
|
|
18821
|
+
plan,
|
|
18822
|
+
couponCode,
|
|
18823
|
+
product,
|
|
18824
|
+
isExistingSource: isUsingExistingPaymentMethod,
|
|
18825
|
+
giftRecipient,
|
|
18826
|
+
addressId: selectedAddressId
|
|
18827
|
+
}, (err, res) => {
|
|
18828
|
+
if (err) {
|
|
18829
|
+
return handlePaymentError(err);
|
|
18830
|
+
}
|
|
18831
|
+
onSuccess(res);
|
|
18832
|
+
});
|
|
18833
|
+
} else if (renewSubscription) {
|
|
18834
|
+
return payment.execute({
|
|
18835
|
+
type: PAYMENT_TYPES.RENEW_SUBSCRIPTION,
|
|
18836
|
+
token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
|
|
18837
|
+
quantity: plan.quantity,
|
|
18838
|
+
plan,
|
|
18839
|
+
couponCode,
|
|
18840
|
+
product,
|
|
18841
|
+
isExistingSource: isUsingExistingPaymentMethod,
|
|
18842
|
+
subscriptionIdToRenew,
|
|
18843
|
+
addressId: selectedAddressId
|
|
18844
|
+
}, (err, res) => {
|
|
18845
|
+
if (err) {
|
|
18846
|
+
return handlePaymentError(err);
|
|
18847
|
+
}
|
|
18848
|
+
onSuccess(res);
|
|
18849
|
+
});
|
|
18850
|
+
} else if (createSubscription) {
|
|
18851
|
+
return payment.execute({
|
|
18852
|
+
type: PAYMENT_TYPES.CREATE_SUBSCRIPTION,
|
|
18853
|
+
token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : braintreeNonce,
|
|
18854
|
+
quantity: plan.quantity,
|
|
18855
|
+
plan,
|
|
18856
|
+
couponCode,
|
|
18857
|
+
product,
|
|
18858
|
+
isExistingSource: isUsingExistingPaymentMethod,
|
|
18859
|
+
addressId: selectedAddressId
|
|
18860
|
+
}, (err, res) => {
|
|
18861
|
+
if (err) {
|
|
18862
|
+
return handlePaymentError(err);
|
|
18863
|
+
}
|
|
18864
|
+
onSuccess(res);
|
|
18865
|
+
});
|
|
18866
|
+
}
|
|
18867
|
+
}
|
|
18868
|
+
};
|
|
18869
|
+
|
|
18870
|
+
/* ====== End Braintree integration ======== */
|
|
18871
|
+
|
|
18872
|
+
const submitUsingVantiv = state => {
|
|
18873
|
+
const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
|
|
18874
|
+
if (isUsingExistingPaymentMethod) {
|
|
18875
|
+
// no need to create a new source using vantiv
|
|
18876
|
+
return handleVantivPayment(null, state.couponCode);
|
|
18877
|
+
}
|
|
18878
|
+
if (!vantivInstanceRef.current) {
|
|
18879
|
+
return console.error("Vantiv sdk script wasn't loaded, you need to load vantiv sdk before rendering the vantiv payment flow");
|
|
18880
|
+
}
|
|
18881
|
+
const orderId = `pelcro-${new Date().getTime()}`;
|
|
18882
|
+
/*
|
|
18883
|
+
calls handleVantivPayment to either handle a payment or update a source by simply creating a new source
|
|
18884
|
+
*/
|
|
18885
|
+
vantivInstanceRef.current.getPaypageRegistrationId({
|
|
18886
|
+
id: orderId,
|
|
18887
|
+
orderId: orderId
|
|
18888
|
+
});
|
|
18097
18889
|
};
|
|
18098
18890
|
function handleVantivPayment(paymentRequest, couponCode) {
|
|
18099
18891
|
if (paymentRequest) {
|
|
@@ -18431,13 +19223,13 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
18431
19223
|
});
|
|
18432
19224
|
|
|
18433
19225
|
// When Google pay / Apple pay source created
|
|
18434
|
-
paymentRequest.on("source",
|
|
19226
|
+
paymentRequest.on("source", _ref8 => {
|
|
18435
19227
|
var _source$card;
|
|
18436
19228
|
let {
|
|
18437
19229
|
complete,
|
|
18438
19230
|
source,
|
|
18439
19231
|
...data
|
|
18440
|
-
} =
|
|
19232
|
+
} = _ref8;
|
|
18441
19233
|
dispatch({
|
|
18442
19234
|
type: DISABLE_COUPON_BUTTON,
|
|
18443
19235
|
payload: true
|
|
@@ -18452,11 +19244,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
18452
19244
|
});
|
|
18453
19245
|
complete("success");
|
|
18454
19246
|
if ((source === null || source === void 0 ? void 0 : (_source$card = source.card) === null || _source$card === void 0 ? void 0 : _source$card.three_d_secure) === "required") {
|
|
18455
|
-
return generate3DSecureSource(source).then(
|
|
19247
|
+
return generate3DSecureSource(source).then(_ref9 => {
|
|
18456
19248
|
let {
|
|
18457
19249
|
source,
|
|
18458
19250
|
error
|
|
18459
|
-
} =
|
|
19251
|
+
} = _ref9;
|
|
18460
19252
|
if (error) {
|
|
18461
19253
|
return handlePaymentError(error);
|
|
18462
19254
|
}
|
|
@@ -19173,11 +19965,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
19173
19965
|
const createPaymentSource = (state, dispatch) => {
|
|
19174
19966
|
return stripe.createSource({
|
|
19175
19967
|
type: "card"
|
|
19176
|
-
}).then(
|
|
19968
|
+
}).then(_ref10 => {
|
|
19177
19969
|
let {
|
|
19178
19970
|
source,
|
|
19179
19971
|
error
|
|
19180
|
-
} =
|
|
19972
|
+
} = _ref10;
|
|
19181
19973
|
if (error) {
|
|
19182
19974
|
return handlePaymentError(error);
|
|
19183
19975
|
}
|
|
@@ -19291,11 +20083,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
19291
20083
|
} = paymentMethodToDelete;
|
|
19292
20084
|
return stripe.createSource({
|
|
19293
20085
|
type: "card"
|
|
19294
|
-
}).then(
|
|
20086
|
+
}).then(_ref11 => {
|
|
19295
20087
|
let {
|
|
19296
20088
|
source,
|
|
19297
20089
|
error
|
|
19298
|
-
} =
|
|
20090
|
+
} = _ref11;
|
|
19299
20091
|
if (error) {
|
|
19300
20092
|
return handlePaymentError(error);
|
|
19301
20093
|
}
|
|
@@ -19393,12 +20185,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
19393
20185
|
}
|
|
19394
20186
|
stripe.createSource({
|
|
19395
20187
|
type: "card"
|
|
19396
|
-
}).then(
|
|
19397
|
-
var
|
|
20188
|
+
}).then(_ref12 => {
|
|
20189
|
+
var _ref13, _ref14, _state$updatedPrice3;
|
|
19398
20190
|
let {
|
|
19399
20191
|
source,
|
|
19400
20192
|
error
|
|
19401
|
-
} =
|
|
20193
|
+
} = _ref12;
|
|
19402
20194
|
if (error) {
|
|
19403
20195
|
return handlePaymentError(error);
|
|
19404
20196
|
}
|
|
@@ -19417,7 +20209,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
19417
20209
|
return total + item.price * item.quantity;
|
|
19418
20210
|
}, 0);
|
|
19419
20211
|
};
|
|
19420
|
-
(
|
|
20212
|
+
(_ref13 = (_ref14 = (_state$updatedPrice3 = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice3 !== void 0 ? _state$updatedPrice3 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref14 !== void 0 ? _ref14 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref13 !== void 0 ? _ref13 : getOrderItemsTotal();
|
|
19421
20213
|
return handlePayment(source);
|
|
19422
20214
|
}).catch(error => {
|
|
19423
20215
|
return handlePaymentError(error);
|
|
@@ -19599,6 +20391,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
19599
20391
|
...state,
|
|
19600
20392
|
isLoading: action.payload
|
|
19601
20393
|
});
|
|
20394
|
+
case SKELETON_LOADER:
|
|
20395
|
+
return lib_7({
|
|
20396
|
+
...state,
|
|
20397
|
+
isSkeletonLoaded: action.payload
|
|
20398
|
+
});
|
|
19602
20399
|
case SHOW_COUPON_FIELD:
|
|
19603
20400
|
return lib_7({
|
|
19604
20401
|
...state,
|
|
@@ -19636,6 +20433,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
19636
20433
|
if (getSiteCardProcessor() === "cybersource") {
|
|
19637
20434
|
return submitUsingCybersource(state, dispatch);
|
|
19638
20435
|
}
|
|
20436
|
+
if (getSiteCardProcessor() === "braintree") {
|
|
20437
|
+
return submitUsingBraintree(state, dispatch);
|
|
20438
|
+
}
|
|
19639
20439
|
if (selectedPaymentMethodId) {
|
|
19640
20440
|
// pay with selected method (source) if exists already
|
|
19641
20441
|
return handlePayment({
|
|
@@ -20024,6 +20824,11 @@ const CheckoutForm = _ref => {
|
|
|
20024
20824
|
paymentMethodToEdit
|
|
20025
20825
|
} = usePelcro();
|
|
20026
20826
|
const cardProcessor = getSiteCardProcessor();
|
|
20827
|
+
const {
|
|
20828
|
+
state: {
|
|
20829
|
+
isSkeletonLoaded
|
|
20830
|
+
}
|
|
20831
|
+
} = React.useContext(store$l);
|
|
20027
20832
|
if (selectedPaymentMethodId) {
|
|
20028
20833
|
return null;
|
|
20029
20834
|
}
|
|
@@ -20055,12 +20860,61 @@ const CheckoutForm = _ref => {
|
|
|
20055
20860
|
placeholder: "Exp Year *"
|
|
20056
20861
|
}))));
|
|
20057
20862
|
}
|
|
20058
|
-
if (cardProcessor === "
|
|
20863
|
+
if (cardProcessor === "braintree") {
|
|
20059
20864
|
if (type === "updatePaymentSource") {
|
|
20060
20865
|
var _paymentMethodToEdit$;
|
|
20866
|
+
return /*#__PURE__*/React__default['default'].createElement("div", null, isSkeletonLoaded && paymentMethodToEdit ? /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
|
|
20867
|
+
htmlFor: "card-number"
|
|
20868
|
+
}, "Card Number *"), /*#__PURE__*/React__default['default'].createElement(Input, {
|
|
20869
|
+
id: "card-number",
|
|
20870
|
+
className: "plc-tracking-widest plc-flex-grow plc-h-12 plc-text-center",
|
|
20871
|
+
value: `•••• •••• •••• ${paymentMethodToEdit === null || paymentMethodToEdit === void 0 ? void 0 : (_paymentMethodToEdit$ = paymentMethodToEdit.properties) === null || _paymentMethodToEdit$ === void 0 ? void 0 : _paymentMethodToEdit$.last4}`,
|
|
20872
|
+
disabled: true
|
|
20873
|
+
}), /*#__PURE__*/React__default['default'].createElement("div", {
|
|
20874
|
+
className: "plc-flex plc-items-start plc-space-x-8 plc-my-6"
|
|
20875
|
+
}, /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
|
|
20876
|
+
htmlFor: "expiration-month"
|
|
20877
|
+
}, "Expiration Month *"), /*#__PURE__*/React__default['default'].createElement("div", {
|
|
20878
|
+
id: "expiration-month",
|
|
20879
|
+
className: "pelcro-input-field plc-h-12 plc-bg-white"
|
|
20880
|
+
})), /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
|
|
20881
|
+
htmlFor: "expiration-year"
|
|
20882
|
+
}, "Expiration Year *"), /*#__PURE__*/React__default['default'].createElement("div", {
|
|
20883
|
+
id: "expiration-year",
|
|
20884
|
+
className: "pelcro-input-field plc-h-12 plc-bg-white"
|
|
20885
|
+
})))) : /*#__PURE__*/React__default['default'].createElement("div", {
|
|
20886
|
+
className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
|
|
20887
|
+
}));
|
|
20888
|
+
}
|
|
20889
|
+
return /*#__PURE__*/React__default['default'].createElement("div", null, isSkeletonLoaded ? /*#__PURE__*/React__default['default'].createElement("div", {
|
|
20890
|
+
className: "plc-max-w-[50em]"
|
|
20891
|
+
}, /*#__PURE__*/React__default['default'].createElement("label", {
|
|
20892
|
+
htmlFor: "card-number"
|
|
20893
|
+
}, "Card Number *"), /*#__PURE__*/React__default['default'].createElement("div", {
|
|
20894
|
+
id: "card-number",
|
|
20895
|
+
className: "pelcro-input-field plc-h-12 plc-bg-white"
|
|
20896
|
+
}), /*#__PURE__*/React__default['default'].createElement("div", {
|
|
20897
|
+
className: "plc-flex plc-items-start plc-space-x-8 plc-my-6"
|
|
20898
|
+
}, /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
|
|
20899
|
+
htmlFor: "expiration-date"
|
|
20900
|
+
}, "Expiration Date *"), /*#__PURE__*/React__default['default'].createElement("div", {
|
|
20901
|
+
id: "expiration-date",
|
|
20902
|
+
className: "pelcro-input-field plc-h-12 plc-bg-white"
|
|
20903
|
+
})), /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
|
|
20904
|
+
htmlFor: "cvv"
|
|
20905
|
+
}, "CVC *"), /*#__PURE__*/React__default['default'].createElement("div", {
|
|
20906
|
+
id: "cvv",
|
|
20907
|
+
className: "pelcro-input-field plc-h-12 plc-bg-white"
|
|
20908
|
+
})))) : /*#__PURE__*/React__default['default'].createElement("div", {
|
|
20909
|
+
className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
|
|
20910
|
+
}));
|
|
20911
|
+
}
|
|
20912
|
+
if (cardProcessor === "stripe") {
|
|
20913
|
+
if (type === "updatePaymentSource") {
|
|
20914
|
+
var _paymentMethodToEdit$2;
|
|
20061
20915
|
return /*#__PURE__*/React__default['default'].createElement("div", null, paymentMethodToEdit ? /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement(Input, {
|
|
20062
20916
|
className: "plc-tracking-widest plc-flex-grow plc-text-center",
|
|
20063
|
-
value: `•••• •••• •••• ${paymentMethodToEdit === null || paymentMethodToEdit === void 0 ? void 0 : (_paymentMethodToEdit$ = paymentMethodToEdit.properties) === null || _paymentMethodToEdit$ === void 0 ? void 0 : _paymentMethodToEdit
|
|
20917
|
+
value: `•••• •••• •••• ${paymentMethodToEdit === null || paymentMethodToEdit === void 0 ? void 0 : (_paymentMethodToEdit$2 = paymentMethodToEdit.properties) === null || _paymentMethodToEdit$2 === void 0 ? void 0 : _paymentMethodToEdit$2.last4}`,
|
|
20064
20918
|
disabled: true
|
|
20065
20919
|
})) : /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement(Input, {
|
|
20066
20920
|
className: "plc-bg-gray-300 plc-animate-pulse"
|