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