@pelcro/react-pelcro-js 3.26.0-sandbox.32 → 3.26.0-sandbox.34
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 +253 -222
- package/dist/index.esm.js +253 -222
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -20302,14 +20302,12 @@ const OrderCreateFreeButton = _ref => {
|
|
|
20302
20302
|
}, otherProps), t("labels.submit"));
|
|
20303
20303
|
};
|
|
20304
20304
|
|
|
20305
|
-
/* eslint-disable no-undef */
|
|
20306
|
-
|
|
20307
20305
|
/**
|
|
20308
20306
|
* ApplePayButton component
|
|
20309
20307
|
* @return {JSX}
|
|
20310
20308
|
*/
|
|
20311
20309
|
const ApplePayButton = _ref => {
|
|
20312
|
-
var _window$Pelcro$site$r
|
|
20310
|
+
var _window$Pelcro$site$r;
|
|
20313
20311
|
let {
|
|
20314
20312
|
onClick,
|
|
20315
20313
|
props,
|
|
@@ -20330,28 +20328,43 @@ const ApplePayButton = _ref => {
|
|
|
20330
20328
|
apple_pay_merchant_id: ApplePayMerchantId,
|
|
20331
20329
|
apple_pay_enabled: ApplePayEnabled
|
|
20332
20330
|
} = (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.vantiv_gateway_settings;
|
|
20333
|
-
const
|
|
20331
|
+
const getOrderInfo = () => {
|
|
20334
20332
|
if (!order) {
|
|
20335
|
-
return
|
|
20333
|
+
return {
|
|
20334
|
+
price: null,
|
|
20335
|
+
currency: null,
|
|
20336
|
+
label: null
|
|
20337
|
+
};
|
|
20336
20338
|
}
|
|
20337
20339
|
const isQuickPurchase = !Array.isArray(order);
|
|
20338
20340
|
if (isQuickPurchase) {
|
|
20339
|
-
return
|
|
20341
|
+
return {
|
|
20342
|
+
price: order.price * order.quantity,
|
|
20343
|
+
currency: order.currency,
|
|
20344
|
+
label: order.name
|
|
20345
|
+
};
|
|
20340
20346
|
}
|
|
20341
20347
|
if (order.length === 0) {
|
|
20342
|
-
return
|
|
20348
|
+
return {
|
|
20349
|
+
price: null,
|
|
20350
|
+
currency: null,
|
|
20351
|
+
label: null
|
|
20352
|
+
};
|
|
20343
20353
|
}
|
|
20344
|
-
|
|
20345
|
-
|
|
20346
|
-
|
|
20354
|
+
const price = order.reduce((total, item) => total + item.price * item.quantity, 0);
|
|
20355
|
+
return {
|
|
20356
|
+
price,
|
|
20357
|
+
currency: order[0].currency,
|
|
20358
|
+
label: "Order"
|
|
20359
|
+
};
|
|
20347
20360
|
};
|
|
20348
|
-
const orderPrice =
|
|
20349
|
-
const orderCurrency =
|
|
20350
|
-
const orderLabel =
|
|
20351
|
-
const updatedPrice = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_state$updatedPrice = state.updatedPrice) !== null && _state$updatedPrice !== void 0 ? _state$updatedPrice : props === null || props === void 0 ? void 0 : (_props$plan = props.plan) === null || _props$plan === void 0 ? void 0 : _props$plan.amount) !== null && _ref5 !== void 0 ? _ref5 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref4 !== void 0 ? _ref4 : orderPrice) !== null && _ref3 !== void 0 ? _ref3 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref2 !== void 0 ? _ref2 : null;
|
|
20361
|
+
const orderPrice = getOrderInfo().price;
|
|
20362
|
+
const orderCurrency = getOrderInfo().currency;
|
|
20363
|
+
const orderLabel = getOrderInfo().label;
|
|
20352
20364
|
React.useEffect(() => {
|
|
20353
20365
|
if (window.ApplePaySession) {
|
|
20354
20366
|
// Indicates whether the device supports Apple Pay and whether the user has an active card in Wallet.
|
|
20367
|
+
// eslint-disable-next-line no-undef
|
|
20355
20368
|
const promise = ApplePaySession.canMakePaymentsWithActiveCard(ApplePayMerchantId);
|
|
20356
20369
|
promise.then(function (canMakePayments) {
|
|
20357
20370
|
if (canMakePayments && ApplePayEnabled) {
|
|
@@ -20367,233 +20380,251 @@ const ApplePayButton = _ref => {
|
|
|
20367
20380
|
console.error("ApplePay is not available on this browser");
|
|
20368
20381
|
}
|
|
20369
20382
|
}, []);
|
|
20370
|
-
|
|
20371
|
-
|
|
20372
|
-
|
|
20373
|
-
|
|
20374
|
-
|
|
20375
|
-
|
|
20376
|
-
type: DISABLE_SUBMIT,
|
|
20377
|
-
payload: true
|
|
20378
|
-
});
|
|
20379
|
-
|
|
20380
|
-
// Define ApplePayPaymentRequest
|
|
20381
|
-
// @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session
|
|
20382
|
-
const ApplePayPaymentRequest = {
|
|
20383
|
-
countryCode: ((_window = window) === null || _window === void 0 ? void 0 : (_window$Pelcro = _window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$user = _window$Pelcro.user) === null || _window$Pelcro$user === void 0 ? void 0 : (_window$Pelcro$user$l = _window$Pelcro$user.location) === null || _window$Pelcro$user$l === void 0 ? void 0 : _window$Pelcro$user$l.countryCode) || "US",
|
|
20384
|
-
currencyCode: (plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase()) || orderCurrency.toUpperCase() || (invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase()),
|
|
20385
|
-
merchantCapabilities: ["supports3DS"],
|
|
20386
|
-
supportedNetworks: ["visa", "masterCard", "amex", "discover"],
|
|
20387
|
-
total: {
|
|
20388
|
-
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
20389
|
-
type: "final",
|
|
20390
|
-
amount: updatedPrice / 100
|
|
20383
|
+
React.useEffect(() => {
|
|
20384
|
+
function onApplePayButtonClicked() {
|
|
20385
|
+
var _ref2, _ref3, _ref4, _ref5, _state$updatedPrice, _props$plan, _window, _window$Pelcro, _window$Pelcro$user, _window$Pelcro$user$l;
|
|
20386
|
+
// eslint-disable-next-line no-undef
|
|
20387
|
+
if (!ApplePaySession) {
|
|
20388
|
+
return;
|
|
20391
20389
|
}
|
|
20392
|
-
|
|
20393
|
-
|
|
20394
|
-
|
|
20395
|
-
|
|
20396
|
-
|
|
20397
|
-
|
|
20398
|
-
|
|
20399
|
-
|
|
20400
|
-
// @see https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778014-supportsversion
|
|
20401
|
-
|
|
20402
|
-
session.onvalidatemerchant = async event => {
|
|
20403
|
-
const {
|
|
20404
|
-
validationURL
|
|
20405
|
-
} = event;
|
|
20406
|
-
console.log("then merchantSession step", event);
|
|
20407
|
-
// Call your own server to request a new merchant session.
|
|
20408
|
-
window.Pelcro.payment.startSession({
|
|
20409
|
-
auth_token: window.Pelcro.user.read().auth_token,
|
|
20410
|
-
site_id: window.Pelcro.siteid,
|
|
20411
|
-
validation_url: validationURL
|
|
20412
|
-
}, (err, res) => {
|
|
20413
|
-
if (err) {
|
|
20414
|
-
// Handle any errors during merchant validation
|
|
20415
|
-
console.error("Merchant validation SDK error: ", err);
|
|
20416
|
-
session.abort();
|
|
20417
|
-
return dispatch({
|
|
20418
|
-
type: SHOW_ALERT,
|
|
20419
|
-
payload: {
|
|
20420
|
-
type: "error",
|
|
20421
|
-
content: getErrorMessages(err)
|
|
20422
|
-
}
|
|
20423
|
-
});
|
|
20390
|
+
const updatedPrice = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_state$updatedPrice = state.updatedPrice) !== null && _state$updatedPrice !== void 0 ? _state$updatedPrice : props === null || props === void 0 ? void 0 : (_props$plan = props.plan) === null || _props$plan === void 0 ? void 0 : _props$plan.amount) !== null && _ref5 !== void 0 ? _ref5 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref4 !== void 0 ? _ref4 : orderPrice) !== null && _ref3 !== void 0 ? _ref3 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref2 !== void 0 ? _ref2 : null;
|
|
20391
|
+
const getCurrencyCode = () => {
|
|
20392
|
+
if (plan) {
|
|
20393
|
+
return plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase();
|
|
20394
|
+
} else if (order) {
|
|
20395
|
+
return orderCurrency.toUpperCase();
|
|
20396
|
+
} else if (invoice) {
|
|
20397
|
+
return invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase();
|
|
20424
20398
|
}
|
|
20425
|
-
// Complete merchant validation with the merchant session object
|
|
20426
|
-
console.log("Merchant validation SDK response: ", res);
|
|
20427
|
-
const merchantSession = res;
|
|
20428
|
-
session.completeMerchantValidation(merchantSession);
|
|
20429
|
-
});
|
|
20430
|
-
};
|
|
20431
|
-
session.onpaymentmethodselected = event => {
|
|
20432
|
-
console.log("payment method selected step", event);
|
|
20433
|
-
// Define ApplePayPaymentMethodUpdate based on the selected payment method.
|
|
20434
|
-
// No updates or errors are needed, pass an empty object.
|
|
20435
|
-
const newTotal = {
|
|
20436
|
-
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
20437
|
-
type: "final",
|
|
20438
|
-
amount: updatedPrice / 100
|
|
20439
20399
|
};
|
|
20440
|
-
|
|
20441
|
-
|
|
20442
|
-
|
|
20443
|
-
|
|
20444
|
-
}];
|
|
20445
|
-
session.completePaymentMethodSelection(newTotal, newLineItems);
|
|
20446
|
-
};
|
|
20400
|
+
dispatch({
|
|
20401
|
+
type: DISABLE_SUBMIT,
|
|
20402
|
+
payload: true
|
|
20403
|
+
});
|
|
20447
20404
|
|
|
20448
|
-
|
|
20449
|
-
|
|
20450
|
-
|
|
20451
|
-
|
|
20452
|
-
|
|
20453
|
-
|
|
20454
|
-
|
|
20455
|
-
|
|
20456
|
-
|
|
20457
|
-
|
|
20458
|
-
|
|
20459
|
-
// const newLineItems = [
|
|
20460
|
-
// {
|
|
20461
|
-
// label: plan?.nickname || orderLabel || `invoice #${invoice?.id}`,
|
|
20462
|
-
// type: "final",
|
|
20463
|
-
// amount: updatedPrice / 100
|
|
20464
|
-
// }
|
|
20465
|
-
// ];
|
|
20466
|
-
|
|
20467
|
-
// session.completeShippingMethodSelection(newTotal, newLineItems);
|
|
20468
|
-
// };
|
|
20469
|
-
|
|
20470
|
-
// TODO: Check if onshippingcontactselected it should be implemented
|
|
20471
|
-
// session.onshippingcontactselected = (event) => {
|
|
20472
|
-
// console.log("on shipping contact selected step", event);
|
|
20473
|
-
// // Define ApplePayShippingContactUpdate based on the selected shipping contact.
|
|
20474
|
-
// const update = {};
|
|
20475
|
-
// session.completeShippingContactSelection(update);
|
|
20476
|
-
// };
|
|
20477
|
-
|
|
20478
|
-
session.onpaymentauthorized = event => {
|
|
20479
|
-
console.log("on payment authorized step", event);
|
|
20480
|
-
// Define ApplePayPaymentAuthorizationResult
|
|
20481
|
-
const result = {
|
|
20482
|
-
status: ApplePaySession.STATUS_SUCCESS
|
|
20483
|
-
};
|
|
20484
|
-
const {
|
|
20485
|
-
paymentData
|
|
20486
|
-
} = event.payment.token;
|
|
20487
|
-
const {
|
|
20488
|
-
data,
|
|
20489
|
-
signature,
|
|
20490
|
-
version
|
|
20491
|
-
} = paymentData;
|
|
20492
|
-
const {
|
|
20493
|
-
ephemeralPublicKey,
|
|
20494
|
-
publicKeyHash,
|
|
20495
|
-
transactionId
|
|
20496
|
-
} = paymentData.header;
|
|
20497
|
-
const applePayToken = {
|
|
20498
|
-
data: data,
|
|
20499
|
-
signature: signature,
|
|
20500
|
-
version: version,
|
|
20501
|
-
header: {
|
|
20502
|
-
ephemeralPublicKey: ephemeralPublicKey,
|
|
20503
|
-
publicKeyHash: publicKeyHash,
|
|
20504
|
-
transactionId: transactionId
|
|
20405
|
+
// Define ApplePayPaymentRequest
|
|
20406
|
+
// @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session
|
|
20407
|
+
const ApplePayPaymentRequest = {
|
|
20408
|
+
countryCode: ((_window = window) === null || _window === void 0 ? void 0 : (_window$Pelcro = _window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$user = _window$Pelcro.user) === null || _window$Pelcro$user === void 0 ? void 0 : (_window$Pelcro$user$l = _window$Pelcro$user.location) === null || _window$Pelcro$user$l === void 0 ? void 0 : _window$Pelcro$user$l.countryCode) || "US",
|
|
20409
|
+
currencyCode: getCurrencyCode(),
|
|
20410
|
+
merchantCapabilities: ["supports3DS"],
|
|
20411
|
+
supportedNetworks: ["visa", "masterCard", "amex", "discover"],
|
|
20412
|
+
total: {
|
|
20413
|
+
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
20414
|
+
type: "final",
|
|
20415
|
+
amount: updatedPrice / 100
|
|
20505
20416
|
}
|
|
20506
20417
|
};
|
|
20507
|
-
console.log(
|
|
20508
|
-
|
|
20509
|
-
|
|
20510
|
-
|
|
20511
|
-
|
|
20512
|
-
|
|
20513
|
-
|
|
20514
|
-
|
|
20515
|
-
|
|
20418
|
+
console.log(ApplePayPaymentRequest);
|
|
20419
|
+
// Create ApplePaySession
|
|
20420
|
+
// @todo - Clarify supported version parameter
|
|
20421
|
+
// @odo - Apple Pay demo uses version 6 (https://applepaydemo.apple.com/)
|
|
20422
|
+
const session = new ApplePaySession(3, ApplePayPaymentRequest); // eslint-disable-line no-undef
|
|
20423
|
+
|
|
20424
|
+
// @todo - Detect whether web browser supports a particular Apple Pay version.
|
|
20425
|
+
// @see https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778014-supportsversion
|
|
20426
|
+
|
|
20427
|
+
session.onvalidatemerchant = async event => {
|
|
20428
|
+
const {
|
|
20429
|
+
validationURL
|
|
20430
|
+
} = event;
|
|
20431
|
+
console.log("then merchantSession step", event);
|
|
20432
|
+
// Call your own server to request a new merchant session.
|
|
20433
|
+
window.Pelcro.payment.startSession({
|
|
20434
|
+
auth_token: window.Pelcro.user.read().auth_token,
|
|
20435
|
+
site_id: window.Pelcro.siteid,
|
|
20436
|
+
validation_url: validationURL
|
|
20437
|
+
}, (err, res) => {
|
|
20438
|
+
if (err) {
|
|
20439
|
+
// Handle any errors during merchant validation
|
|
20440
|
+
console.error("Merchant validation SDK error: ", err);
|
|
20441
|
+
session.abort();
|
|
20442
|
+
return dispatch({
|
|
20443
|
+
type: SHOW_ALERT,
|
|
20444
|
+
payload: {
|
|
20445
|
+
type: "error",
|
|
20446
|
+
content: getErrorMessages(err)
|
|
20447
|
+
}
|
|
20448
|
+
});
|
|
20449
|
+
}
|
|
20450
|
+
// Complete merchant validation with the merchant session object
|
|
20451
|
+
console.log("Merchant validation SDK response: ", res);
|
|
20452
|
+
const merchantSession = res;
|
|
20453
|
+
session.completeMerchantValidation(merchantSession);
|
|
20454
|
+
});
|
|
20455
|
+
};
|
|
20456
|
+
session.onpaymentmethodselected = event => {
|
|
20457
|
+
console.log("payment method selected step", event);
|
|
20458
|
+
// Define ApplePayPaymentMethodUpdate based on the selected payment method.
|
|
20459
|
+
// No updates or errors are needed, pass an empty object.
|
|
20460
|
+
const newTotal = {
|
|
20461
|
+
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
20462
|
+
type: "final",
|
|
20463
|
+
amount: updatedPrice / 100
|
|
20464
|
+
};
|
|
20465
|
+
const newLineItems = [{
|
|
20466
|
+
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
20467
|
+
type: "final",
|
|
20468
|
+
amount: updatedPrice / 100
|
|
20469
|
+
}];
|
|
20470
|
+
session.completePaymentMethodSelection(newTotal, newLineItems);
|
|
20516
20471
|
};
|
|
20517
20472
|
|
|
20518
|
-
//
|
|
20519
|
-
|
|
20473
|
+
// TODO: Check if onshippingmethodselected it should be implemented
|
|
20474
|
+
// session.onshippingmethodselected = (event) => {
|
|
20475
|
+
// console.log("on shipping method selected step", event);
|
|
20476
|
+
// // Define ApplePayShippingMethodUpdate based on the selected shipping method.
|
|
20477
|
+
// // No updates or errors are needed, pass an empty object.
|
|
20478
|
+
// const newTotal = {
|
|
20479
|
+
// label: plan?.nickname || orderLabel || `invoice #${invoice?.id}`,
|
|
20480
|
+
// type: "final",
|
|
20481
|
+
// amount: updatedPrice / 100
|
|
20482
|
+
// };
|
|
20483
|
+
|
|
20484
|
+
// const newLineItems = [
|
|
20485
|
+
// {
|
|
20486
|
+
// label: plan?.nickname || orderLabel || `invoice #${invoice?.id}`,
|
|
20487
|
+
// type: "final",
|
|
20488
|
+
// amount: updatedPrice / 100
|
|
20489
|
+
// }
|
|
20490
|
+
// ];
|
|
20491
|
+
|
|
20492
|
+
// session.completeShippingMethodSelection(newTotal, newLineItems);
|
|
20493
|
+
// };
|
|
20494
|
+
|
|
20495
|
+
// TODO: Check if onshippingcontactselected it should be implemented
|
|
20496
|
+
// session.onshippingcontactselected = (event) => {
|
|
20497
|
+
// console.log("on shipping contact selected step", event);
|
|
20498
|
+
// // Define ApplePayShippingContactUpdate based on the selected shipping contact.
|
|
20499
|
+
// const update = {};
|
|
20500
|
+
// session.completeShippingContactSelection(update);
|
|
20501
|
+
// };
|
|
20502
|
+
|
|
20503
|
+
session.onpaymentauthorized = event => {
|
|
20504
|
+
console.log("on payment authorized step", event);
|
|
20505
|
+
// Define ApplePayPaymentAuthorizationResult
|
|
20506
|
+
const result = {
|
|
20507
|
+
status: ApplePaySession.STATUS_SUCCESS // eslint-disable-line no-undef
|
|
20508
|
+
};
|
|
20509
|
+
|
|
20510
|
+
const {
|
|
20511
|
+
paymentData
|
|
20512
|
+
} = event.payment.token;
|
|
20520
20513
|
const {
|
|
20521
|
-
|
|
20522
|
-
|
|
20523
|
-
|
|
20524
|
-
|
|
20525
|
-
const
|
|
20526
|
-
|
|
20527
|
-
|
|
20528
|
-
|
|
20529
|
-
|
|
20514
|
+
data,
|
|
20515
|
+
signature,
|
|
20516
|
+
version
|
|
20517
|
+
} = paymentData;
|
|
20518
|
+
const {
|
|
20519
|
+
ephemeralPublicKey,
|
|
20520
|
+
publicKeyHash,
|
|
20521
|
+
transactionId
|
|
20522
|
+
} = paymentData.header;
|
|
20523
|
+
const applePayToken = {
|
|
20524
|
+
data: data,
|
|
20525
|
+
signature: signature,
|
|
20526
|
+
version: version,
|
|
20527
|
+
header: {
|
|
20528
|
+
ephemeralPublicKey: ephemeralPublicKey,
|
|
20529
|
+
publicKeyHash: publicKeyHash,
|
|
20530
|
+
transactionId: transactionId
|
|
20531
|
+
}
|
|
20532
|
+
};
|
|
20533
|
+
console.log(applePayToken);
|
|
20534
|
+
const orderId = `pelcro-${new Date().getTime()}`;
|
|
20535
|
+
const eProtectRequest = {
|
|
20536
|
+
paypageId: payPageId,
|
|
20537
|
+
reportGroup: reportGroup,
|
|
20538
|
+
orderId: orderId,
|
|
20539
|
+
id: orderId,
|
|
20540
|
+
applepay: applePayToken,
|
|
20541
|
+
url: "https://request.eprotect.vantivprelive.com"
|
|
20530
20542
|
};
|
|
20531
20543
|
|
|
20532
|
-
//
|
|
20544
|
+
// successCallback function to handle the response from WorldPay.
|
|
20545
|
+
function successCallback(vantivResponse) {
|
|
20546
|
+
const {
|
|
20547
|
+
expDate
|
|
20548
|
+
} = vantivResponse;
|
|
20549
|
+
console.log("Response:", vantivResponse);
|
|
20550
|
+
const expMonth = expDate.substring(0, 2);
|
|
20551
|
+
const expYear = expDate.substring(2);
|
|
20552
|
+
const vantivPaymentRequest = {
|
|
20553
|
+
...vantivResponse,
|
|
20554
|
+
expMonth: expMonth,
|
|
20555
|
+
expYear: expYear
|
|
20556
|
+
};
|
|
20557
|
+
|
|
20558
|
+
// Process the registrationId or continue with further payment processing.
|
|
20559
|
+
dispatch({
|
|
20560
|
+
type: HANDLE_APPLEPAY_SUBSCRIPTION,
|
|
20561
|
+
payload: vantivPaymentRequest
|
|
20562
|
+
});
|
|
20563
|
+
dispatch({
|
|
20564
|
+
type: LOADING,
|
|
20565
|
+
payload: true
|
|
20566
|
+
});
|
|
20567
|
+
session.completePayment(result);
|
|
20568
|
+
}
|
|
20569
|
+
|
|
20570
|
+
// errorCallback function to handle any errors that may occur during the tokenization process.
|
|
20571
|
+
function errorCallback(error) {
|
|
20572
|
+
console.error("Error retrieving Registration ID:", error);
|
|
20573
|
+
// Handle error appropriately.
|
|
20574
|
+
}
|
|
20575
|
+
// errorCallback function to handle any errors that may occur during the tokenization process.
|
|
20576
|
+
function timeoutCallback() {
|
|
20577
|
+
console.error("eProtect Timeout");
|
|
20578
|
+
// Handle error appropriately.
|
|
20579
|
+
}
|
|
20580
|
+
|
|
20581
|
+
// eslint-disable-next-line no-undef
|
|
20582
|
+
new eProtect().sendToEprotect(eProtectRequest, {}, successCallback, errorCallback, timeoutCallback, 15000);
|
|
20583
|
+
};
|
|
20584
|
+
|
|
20585
|
+
// TODO: Check if oncouponcodechanged it should be implemented
|
|
20586
|
+
// session.oncouponcodechanged = (event) => {
|
|
20587
|
+
// console.log("on coupon code changed step", event);
|
|
20588
|
+
// // Define ApplePayCouponCodeUpdate
|
|
20589
|
+
// const newTotal = calculateNewTotal(event.couponCode);
|
|
20590
|
+
// const newLineItems = calculateNewLineItems(event.couponCode);
|
|
20591
|
+
// const newShippingMethods = calculateNewShippingMethods(
|
|
20592
|
+
// event.couponCode
|
|
20593
|
+
// );
|
|
20594
|
+
// const errors = calculateErrors(event.couponCode);
|
|
20595
|
+
|
|
20596
|
+
// session.completeCouponCodeChange({
|
|
20597
|
+
// newTotal: newTotal,
|
|
20598
|
+
// newLineItems: newLineItems,
|
|
20599
|
+
// newShippingMethods: newShippingMethods,
|
|
20600
|
+
// errors: errors
|
|
20601
|
+
// });
|
|
20602
|
+
// };
|
|
20603
|
+
|
|
20604
|
+
session.oncancel = event => {
|
|
20605
|
+
// Payment cancelled by WebKit
|
|
20606
|
+
console.log("on cancel step", event);
|
|
20533
20607
|
dispatch({
|
|
20534
|
-
type:
|
|
20535
|
-
payload:
|
|
20608
|
+
type: LOADING,
|
|
20609
|
+
payload: false
|
|
20536
20610
|
});
|
|
20537
20611
|
dispatch({
|
|
20538
|
-
type:
|
|
20539
|
-
payload:
|
|
20612
|
+
type: DISABLE_SUBMIT,
|
|
20613
|
+
payload: false
|
|
20540
20614
|
});
|
|
20541
|
-
|
|
20542
|
-
|
|
20543
|
-
|
|
20544
|
-
// errorCallback function to handle any errors that may occur during the tokenization process.
|
|
20545
|
-
function errorCallback(error) {
|
|
20546
|
-
console.error("Error retrieving Registration ID:", error);
|
|
20547
|
-
// Handle error appropriately.
|
|
20548
|
-
}
|
|
20549
|
-
// errorCallback function to handle any errors that may occur during the tokenization process.
|
|
20550
|
-
function timeoutCallback() {
|
|
20551
|
-
console.error("eProtect Timeout");
|
|
20552
|
-
// Handle error appropriately.
|
|
20553
|
-
}
|
|
20554
|
-
|
|
20555
|
-
new eProtect().sendToEprotect(eProtectRequest, {}, successCallback, errorCallback, timeoutCallback, 15000);
|
|
20556
|
-
};
|
|
20557
|
-
|
|
20558
|
-
// TODO: Check if oncouponcodechanged it should be implemented
|
|
20559
|
-
// session.oncouponcodechanged = (event) => {
|
|
20560
|
-
// console.log("on coupon code changed step", event);
|
|
20561
|
-
// // Define ApplePayCouponCodeUpdate
|
|
20562
|
-
// const newTotal = calculateNewTotal(event.couponCode);
|
|
20563
|
-
// const newLineItems = calculateNewLineItems(event.couponCode);
|
|
20564
|
-
// const newShippingMethods = calculateNewShippingMethods(
|
|
20565
|
-
// event.couponCode
|
|
20566
|
-
// );
|
|
20567
|
-
// const errors = calculateErrors(event.couponCode);
|
|
20568
|
-
|
|
20569
|
-
// session.completeCouponCodeChange({
|
|
20570
|
-
// newTotal: newTotal,
|
|
20571
|
-
// newLineItems: newLineItems,
|
|
20572
|
-
// newShippingMethods: newShippingMethods,
|
|
20573
|
-
// errors: errors
|
|
20574
|
-
// });
|
|
20575
|
-
// };
|
|
20576
|
-
|
|
20577
|
-
session.oncancel = event => {
|
|
20578
|
-
// Payment cancelled by WebKit
|
|
20579
|
-
console.log("on cancel step", event);
|
|
20580
|
-
dispatch({
|
|
20581
|
-
type: LOADING,
|
|
20582
|
-
payload: false
|
|
20583
|
-
});
|
|
20584
|
-
dispatch({
|
|
20585
|
-
type: DISABLE_SUBMIT,
|
|
20586
|
-
payload: false
|
|
20587
|
-
});
|
|
20588
|
-
};
|
|
20589
|
-
session.begin();
|
|
20590
|
-
}
|
|
20591
|
-
React.useEffect(() => {
|
|
20615
|
+
};
|
|
20616
|
+
session.begin();
|
|
20617
|
+
}
|
|
20592
20618
|
const pelcroApplyPayButton = document.getElementById("pelcro-apple-pay-button");
|
|
20593
20619
|
if (pelcroApplyPayButton) {
|
|
20594
20620
|
pelcroApplyPayButton.addEventListener("click", onApplePayButtonClicked);
|
|
20595
20621
|
}
|
|
20596
|
-
|
|
20622
|
+
return () => {
|
|
20623
|
+
if (pelcroApplyPayButton) {
|
|
20624
|
+
pelcroApplyPayButton.removeEventListener("click", onApplePayButtonClicked);
|
|
20625
|
+
}
|
|
20626
|
+
};
|
|
20627
|
+
}, [state.updatedPrice]);
|
|
20597
20628
|
return /*#__PURE__*/React__default['default'].createElement("apple-pay-button", {
|
|
20598
20629
|
id: "pelcro-apple-pay-button",
|
|
20599
20630
|
style: {
|
package/dist/index.esm.js
CHANGED
|
@@ -20272,14 +20272,12 @@ const OrderCreateFreeButton = _ref => {
|
|
|
20272
20272
|
}, otherProps), t("labels.submit"));
|
|
20273
20273
|
};
|
|
20274
20274
|
|
|
20275
|
-
/* eslint-disable no-undef */
|
|
20276
|
-
|
|
20277
20275
|
/**
|
|
20278
20276
|
* ApplePayButton component
|
|
20279
20277
|
* @return {JSX}
|
|
20280
20278
|
*/
|
|
20281
20279
|
const ApplePayButton = _ref => {
|
|
20282
|
-
var _window$Pelcro$site$r
|
|
20280
|
+
var _window$Pelcro$site$r;
|
|
20283
20281
|
let {
|
|
20284
20282
|
onClick,
|
|
20285
20283
|
props,
|
|
@@ -20300,28 +20298,43 @@ const ApplePayButton = _ref => {
|
|
|
20300
20298
|
apple_pay_merchant_id: ApplePayMerchantId,
|
|
20301
20299
|
apple_pay_enabled: ApplePayEnabled
|
|
20302
20300
|
} = (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.vantiv_gateway_settings;
|
|
20303
|
-
const
|
|
20301
|
+
const getOrderInfo = () => {
|
|
20304
20302
|
if (!order) {
|
|
20305
|
-
return
|
|
20303
|
+
return {
|
|
20304
|
+
price: null,
|
|
20305
|
+
currency: null,
|
|
20306
|
+
label: null
|
|
20307
|
+
};
|
|
20306
20308
|
}
|
|
20307
20309
|
const isQuickPurchase = !Array.isArray(order);
|
|
20308
20310
|
if (isQuickPurchase) {
|
|
20309
|
-
return
|
|
20311
|
+
return {
|
|
20312
|
+
price: order.price * order.quantity,
|
|
20313
|
+
currency: order.currency,
|
|
20314
|
+
label: order.name
|
|
20315
|
+
};
|
|
20310
20316
|
}
|
|
20311
20317
|
if (order.length === 0) {
|
|
20312
|
-
return
|
|
20318
|
+
return {
|
|
20319
|
+
price: null,
|
|
20320
|
+
currency: null,
|
|
20321
|
+
label: null
|
|
20322
|
+
};
|
|
20313
20323
|
}
|
|
20314
|
-
|
|
20315
|
-
|
|
20316
|
-
|
|
20324
|
+
const price = order.reduce((total, item) => total + item.price * item.quantity, 0);
|
|
20325
|
+
return {
|
|
20326
|
+
price,
|
|
20327
|
+
currency: order[0].currency,
|
|
20328
|
+
label: "Order"
|
|
20329
|
+
};
|
|
20317
20330
|
};
|
|
20318
|
-
const orderPrice =
|
|
20319
|
-
const orderCurrency =
|
|
20320
|
-
const orderLabel =
|
|
20321
|
-
const updatedPrice = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_state$updatedPrice = state.updatedPrice) !== null && _state$updatedPrice !== void 0 ? _state$updatedPrice : props === null || props === void 0 ? void 0 : (_props$plan = props.plan) === null || _props$plan === void 0 ? void 0 : _props$plan.amount) !== null && _ref5 !== void 0 ? _ref5 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref4 !== void 0 ? _ref4 : orderPrice) !== null && _ref3 !== void 0 ? _ref3 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref2 !== void 0 ? _ref2 : null;
|
|
20331
|
+
const orderPrice = getOrderInfo().price;
|
|
20332
|
+
const orderCurrency = getOrderInfo().currency;
|
|
20333
|
+
const orderLabel = getOrderInfo().label;
|
|
20322
20334
|
useEffect(() => {
|
|
20323
20335
|
if (window.ApplePaySession) {
|
|
20324
20336
|
// Indicates whether the device supports Apple Pay and whether the user has an active card in Wallet.
|
|
20337
|
+
// eslint-disable-next-line no-undef
|
|
20325
20338
|
const promise = ApplePaySession.canMakePaymentsWithActiveCard(ApplePayMerchantId);
|
|
20326
20339
|
promise.then(function (canMakePayments) {
|
|
20327
20340
|
if (canMakePayments && ApplePayEnabled) {
|
|
@@ -20337,233 +20350,251 @@ const ApplePayButton = _ref => {
|
|
|
20337
20350
|
console.error("ApplePay is not available on this browser");
|
|
20338
20351
|
}
|
|
20339
20352
|
}, []);
|
|
20340
|
-
|
|
20341
|
-
|
|
20342
|
-
|
|
20343
|
-
|
|
20344
|
-
|
|
20345
|
-
|
|
20346
|
-
type: DISABLE_SUBMIT,
|
|
20347
|
-
payload: true
|
|
20348
|
-
});
|
|
20349
|
-
|
|
20350
|
-
// Define ApplePayPaymentRequest
|
|
20351
|
-
// @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session
|
|
20352
|
-
const ApplePayPaymentRequest = {
|
|
20353
|
-
countryCode: ((_window = window) === null || _window === void 0 ? void 0 : (_window$Pelcro = _window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$user = _window$Pelcro.user) === null || _window$Pelcro$user === void 0 ? void 0 : (_window$Pelcro$user$l = _window$Pelcro$user.location) === null || _window$Pelcro$user$l === void 0 ? void 0 : _window$Pelcro$user$l.countryCode) || "US",
|
|
20354
|
-
currencyCode: (plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase()) || orderCurrency.toUpperCase() || (invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase()),
|
|
20355
|
-
merchantCapabilities: ["supports3DS"],
|
|
20356
|
-
supportedNetworks: ["visa", "masterCard", "amex", "discover"],
|
|
20357
|
-
total: {
|
|
20358
|
-
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
20359
|
-
type: "final",
|
|
20360
|
-
amount: updatedPrice / 100
|
|
20353
|
+
useEffect(() => {
|
|
20354
|
+
function onApplePayButtonClicked() {
|
|
20355
|
+
var _ref2, _ref3, _ref4, _ref5, _state$updatedPrice, _props$plan, _window, _window$Pelcro, _window$Pelcro$user, _window$Pelcro$user$l;
|
|
20356
|
+
// eslint-disable-next-line no-undef
|
|
20357
|
+
if (!ApplePaySession) {
|
|
20358
|
+
return;
|
|
20361
20359
|
}
|
|
20362
|
-
|
|
20363
|
-
|
|
20364
|
-
|
|
20365
|
-
|
|
20366
|
-
|
|
20367
|
-
|
|
20368
|
-
|
|
20369
|
-
|
|
20370
|
-
// @see https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778014-supportsversion
|
|
20371
|
-
|
|
20372
|
-
session.onvalidatemerchant = async event => {
|
|
20373
|
-
const {
|
|
20374
|
-
validationURL
|
|
20375
|
-
} = event;
|
|
20376
|
-
console.log("then merchantSession step", event);
|
|
20377
|
-
// Call your own server to request a new merchant session.
|
|
20378
|
-
window.Pelcro.payment.startSession({
|
|
20379
|
-
auth_token: window.Pelcro.user.read().auth_token,
|
|
20380
|
-
site_id: window.Pelcro.siteid,
|
|
20381
|
-
validation_url: validationURL
|
|
20382
|
-
}, (err, res) => {
|
|
20383
|
-
if (err) {
|
|
20384
|
-
// Handle any errors during merchant validation
|
|
20385
|
-
console.error("Merchant validation SDK error: ", err);
|
|
20386
|
-
session.abort();
|
|
20387
|
-
return dispatch({
|
|
20388
|
-
type: SHOW_ALERT,
|
|
20389
|
-
payload: {
|
|
20390
|
-
type: "error",
|
|
20391
|
-
content: getErrorMessages(err)
|
|
20392
|
-
}
|
|
20393
|
-
});
|
|
20360
|
+
const updatedPrice = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_state$updatedPrice = state.updatedPrice) !== null && _state$updatedPrice !== void 0 ? _state$updatedPrice : props === null || props === void 0 ? void 0 : (_props$plan = props.plan) === null || _props$plan === void 0 ? void 0 : _props$plan.amount) !== null && _ref5 !== void 0 ? _ref5 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref4 !== void 0 ? _ref4 : orderPrice) !== null && _ref3 !== void 0 ? _ref3 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref2 !== void 0 ? _ref2 : null;
|
|
20361
|
+
const getCurrencyCode = () => {
|
|
20362
|
+
if (plan) {
|
|
20363
|
+
return plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase();
|
|
20364
|
+
} else if (order) {
|
|
20365
|
+
return orderCurrency.toUpperCase();
|
|
20366
|
+
} else if (invoice) {
|
|
20367
|
+
return invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase();
|
|
20394
20368
|
}
|
|
20395
|
-
// Complete merchant validation with the merchant session object
|
|
20396
|
-
console.log("Merchant validation SDK response: ", res);
|
|
20397
|
-
const merchantSession = res;
|
|
20398
|
-
session.completeMerchantValidation(merchantSession);
|
|
20399
|
-
});
|
|
20400
|
-
};
|
|
20401
|
-
session.onpaymentmethodselected = event => {
|
|
20402
|
-
console.log("payment method selected step", event);
|
|
20403
|
-
// Define ApplePayPaymentMethodUpdate based on the selected payment method.
|
|
20404
|
-
// No updates or errors are needed, pass an empty object.
|
|
20405
|
-
const newTotal = {
|
|
20406
|
-
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
20407
|
-
type: "final",
|
|
20408
|
-
amount: updatedPrice / 100
|
|
20409
20369
|
};
|
|
20410
|
-
|
|
20411
|
-
|
|
20412
|
-
|
|
20413
|
-
|
|
20414
|
-
}];
|
|
20415
|
-
session.completePaymentMethodSelection(newTotal, newLineItems);
|
|
20416
|
-
};
|
|
20370
|
+
dispatch({
|
|
20371
|
+
type: DISABLE_SUBMIT,
|
|
20372
|
+
payload: true
|
|
20373
|
+
});
|
|
20417
20374
|
|
|
20418
|
-
|
|
20419
|
-
|
|
20420
|
-
|
|
20421
|
-
|
|
20422
|
-
|
|
20423
|
-
|
|
20424
|
-
|
|
20425
|
-
|
|
20426
|
-
|
|
20427
|
-
|
|
20428
|
-
|
|
20429
|
-
// const newLineItems = [
|
|
20430
|
-
// {
|
|
20431
|
-
// label: plan?.nickname || orderLabel || `invoice #${invoice?.id}`,
|
|
20432
|
-
// type: "final",
|
|
20433
|
-
// amount: updatedPrice / 100
|
|
20434
|
-
// }
|
|
20435
|
-
// ];
|
|
20436
|
-
|
|
20437
|
-
// session.completeShippingMethodSelection(newTotal, newLineItems);
|
|
20438
|
-
// };
|
|
20439
|
-
|
|
20440
|
-
// TODO: Check if onshippingcontactselected it should be implemented
|
|
20441
|
-
// session.onshippingcontactselected = (event) => {
|
|
20442
|
-
// console.log("on shipping contact selected step", event);
|
|
20443
|
-
// // Define ApplePayShippingContactUpdate based on the selected shipping contact.
|
|
20444
|
-
// const update = {};
|
|
20445
|
-
// session.completeShippingContactSelection(update);
|
|
20446
|
-
// };
|
|
20447
|
-
|
|
20448
|
-
session.onpaymentauthorized = event => {
|
|
20449
|
-
console.log("on payment authorized step", event);
|
|
20450
|
-
// Define ApplePayPaymentAuthorizationResult
|
|
20451
|
-
const result = {
|
|
20452
|
-
status: ApplePaySession.STATUS_SUCCESS
|
|
20453
|
-
};
|
|
20454
|
-
const {
|
|
20455
|
-
paymentData
|
|
20456
|
-
} = event.payment.token;
|
|
20457
|
-
const {
|
|
20458
|
-
data,
|
|
20459
|
-
signature,
|
|
20460
|
-
version
|
|
20461
|
-
} = paymentData;
|
|
20462
|
-
const {
|
|
20463
|
-
ephemeralPublicKey,
|
|
20464
|
-
publicKeyHash,
|
|
20465
|
-
transactionId
|
|
20466
|
-
} = paymentData.header;
|
|
20467
|
-
const applePayToken = {
|
|
20468
|
-
data: data,
|
|
20469
|
-
signature: signature,
|
|
20470
|
-
version: version,
|
|
20471
|
-
header: {
|
|
20472
|
-
ephemeralPublicKey: ephemeralPublicKey,
|
|
20473
|
-
publicKeyHash: publicKeyHash,
|
|
20474
|
-
transactionId: transactionId
|
|
20375
|
+
// Define ApplePayPaymentRequest
|
|
20376
|
+
// @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session
|
|
20377
|
+
const ApplePayPaymentRequest = {
|
|
20378
|
+
countryCode: ((_window = window) === null || _window === void 0 ? void 0 : (_window$Pelcro = _window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$user = _window$Pelcro.user) === null || _window$Pelcro$user === void 0 ? void 0 : (_window$Pelcro$user$l = _window$Pelcro$user.location) === null || _window$Pelcro$user$l === void 0 ? void 0 : _window$Pelcro$user$l.countryCode) || "US",
|
|
20379
|
+
currencyCode: getCurrencyCode(),
|
|
20380
|
+
merchantCapabilities: ["supports3DS"],
|
|
20381
|
+
supportedNetworks: ["visa", "masterCard", "amex", "discover"],
|
|
20382
|
+
total: {
|
|
20383
|
+
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
20384
|
+
type: "final",
|
|
20385
|
+
amount: updatedPrice / 100
|
|
20475
20386
|
}
|
|
20476
20387
|
};
|
|
20477
|
-
console.log(
|
|
20478
|
-
|
|
20479
|
-
|
|
20480
|
-
|
|
20481
|
-
|
|
20482
|
-
|
|
20483
|
-
|
|
20484
|
-
|
|
20485
|
-
|
|
20388
|
+
console.log(ApplePayPaymentRequest);
|
|
20389
|
+
// Create ApplePaySession
|
|
20390
|
+
// @todo - Clarify supported version parameter
|
|
20391
|
+
// @odo - Apple Pay demo uses version 6 (https://applepaydemo.apple.com/)
|
|
20392
|
+
const session = new ApplePaySession(3, ApplePayPaymentRequest); // eslint-disable-line no-undef
|
|
20393
|
+
|
|
20394
|
+
// @todo - Detect whether web browser supports a particular Apple Pay version.
|
|
20395
|
+
// @see https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778014-supportsversion
|
|
20396
|
+
|
|
20397
|
+
session.onvalidatemerchant = async event => {
|
|
20398
|
+
const {
|
|
20399
|
+
validationURL
|
|
20400
|
+
} = event;
|
|
20401
|
+
console.log("then merchantSession step", event);
|
|
20402
|
+
// Call your own server to request a new merchant session.
|
|
20403
|
+
window.Pelcro.payment.startSession({
|
|
20404
|
+
auth_token: window.Pelcro.user.read().auth_token,
|
|
20405
|
+
site_id: window.Pelcro.siteid,
|
|
20406
|
+
validation_url: validationURL
|
|
20407
|
+
}, (err, res) => {
|
|
20408
|
+
if (err) {
|
|
20409
|
+
// Handle any errors during merchant validation
|
|
20410
|
+
console.error("Merchant validation SDK error: ", err);
|
|
20411
|
+
session.abort();
|
|
20412
|
+
return dispatch({
|
|
20413
|
+
type: SHOW_ALERT,
|
|
20414
|
+
payload: {
|
|
20415
|
+
type: "error",
|
|
20416
|
+
content: getErrorMessages(err)
|
|
20417
|
+
}
|
|
20418
|
+
});
|
|
20419
|
+
}
|
|
20420
|
+
// Complete merchant validation with the merchant session object
|
|
20421
|
+
console.log("Merchant validation SDK response: ", res);
|
|
20422
|
+
const merchantSession = res;
|
|
20423
|
+
session.completeMerchantValidation(merchantSession);
|
|
20424
|
+
});
|
|
20425
|
+
};
|
|
20426
|
+
session.onpaymentmethodselected = event => {
|
|
20427
|
+
console.log("payment method selected step", event);
|
|
20428
|
+
// Define ApplePayPaymentMethodUpdate based on the selected payment method.
|
|
20429
|
+
// No updates or errors are needed, pass an empty object.
|
|
20430
|
+
const newTotal = {
|
|
20431
|
+
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
20432
|
+
type: "final",
|
|
20433
|
+
amount: updatedPrice / 100
|
|
20434
|
+
};
|
|
20435
|
+
const newLineItems = [{
|
|
20436
|
+
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
20437
|
+
type: "final",
|
|
20438
|
+
amount: updatedPrice / 100
|
|
20439
|
+
}];
|
|
20440
|
+
session.completePaymentMethodSelection(newTotal, newLineItems);
|
|
20486
20441
|
};
|
|
20487
20442
|
|
|
20488
|
-
//
|
|
20489
|
-
|
|
20443
|
+
// TODO: Check if onshippingmethodselected it should be implemented
|
|
20444
|
+
// session.onshippingmethodselected = (event) => {
|
|
20445
|
+
// console.log("on shipping method selected step", event);
|
|
20446
|
+
// // Define ApplePayShippingMethodUpdate based on the selected shipping method.
|
|
20447
|
+
// // No updates or errors are needed, pass an empty object.
|
|
20448
|
+
// const newTotal = {
|
|
20449
|
+
// label: plan?.nickname || orderLabel || `invoice #${invoice?.id}`,
|
|
20450
|
+
// type: "final",
|
|
20451
|
+
// amount: updatedPrice / 100
|
|
20452
|
+
// };
|
|
20453
|
+
|
|
20454
|
+
// const newLineItems = [
|
|
20455
|
+
// {
|
|
20456
|
+
// label: plan?.nickname || orderLabel || `invoice #${invoice?.id}`,
|
|
20457
|
+
// type: "final",
|
|
20458
|
+
// amount: updatedPrice / 100
|
|
20459
|
+
// }
|
|
20460
|
+
// ];
|
|
20461
|
+
|
|
20462
|
+
// session.completeShippingMethodSelection(newTotal, newLineItems);
|
|
20463
|
+
// };
|
|
20464
|
+
|
|
20465
|
+
// TODO: Check if onshippingcontactselected it should be implemented
|
|
20466
|
+
// session.onshippingcontactselected = (event) => {
|
|
20467
|
+
// console.log("on shipping contact selected step", event);
|
|
20468
|
+
// // Define ApplePayShippingContactUpdate based on the selected shipping contact.
|
|
20469
|
+
// const update = {};
|
|
20470
|
+
// session.completeShippingContactSelection(update);
|
|
20471
|
+
// };
|
|
20472
|
+
|
|
20473
|
+
session.onpaymentauthorized = event => {
|
|
20474
|
+
console.log("on payment authorized step", event);
|
|
20475
|
+
// Define ApplePayPaymentAuthorizationResult
|
|
20476
|
+
const result = {
|
|
20477
|
+
status: ApplePaySession.STATUS_SUCCESS // eslint-disable-line no-undef
|
|
20478
|
+
};
|
|
20479
|
+
|
|
20480
|
+
const {
|
|
20481
|
+
paymentData
|
|
20482
|
+
} = event.payment.token;
|
|
20490
20483
|
const {
|
|
20491
|
-
|
|
20492
|
-
|
|
20493
|
-
|
|
20494
|
-
|
|
20495
|
-
const
|
|
20496
|
-
|
|
20497
|
-
|
|
20498
|
-
|
|
20499
|
-
|
|
20484
|
+
data,
|
|
20485
|
+
signature,
|
|
20486
|
+
version
|
|
20487
|
+
} = paymentData;
|
|
20488
|
+
const {
|
|
20489
|
+
ephemeralPublicKey,
|
|
20490
|
+
publicKeyHash,
|
|
20491
|
+
transactionId
|
|
20492
|
+
} = paymentData.header;
|
|
20493
|
+
const applePayToken = {
|
|
20494
|
+
data: data,
|
|
20495
|
+
signature: signature,
|
|
20496
|
+
version: version,
|
|
20497
|
+
header: {
|
|
20498
|
+
ephemeralPublicKey: ephemeralPublicKey,
|
|
20499
|
+
publicKeyHash: publicKeyHash,
|
|
20500
|
+
transactionId: transactionId
|
|
20501
|
+
}
|
|
20502
|
+
};
|
|
20503
|
+
console.log(applePayToken);
|
|
20504
|
+
const orderId = `pelcro-${new Date().getTime()}`;
|
|
20505
|
+
const eProtectRequest = {
|
|
20506
|
+
paypageId: payPageId,
|
|
20507
|
+
reportGroup: reportGroup,
|
|
20508
|
+
orderId: orderId,
|
|
20509
|
+
id: orderId,
|
|
20510
|
+
applepay: applePayToken,
|
|
20511
|
+
url: "https://request.eprotect.vantivprelive.com"
|
|
20500
20512
|
};
|
|
20501
20513
|
|
|
20502
|
-
//
|
|
20514
|
+
// successCallback function to handle the response from WorldPay.
|
|
20515
|
+
function successCallback(vantivResponse) {
|
|
20516
|
+
const {
|
|
20517
|
+
expDate
|
|
20518
|
+
} = vantivResponse;
|
|
20519
|
+
console.log("Response:", vantivResponse);
|
|
20520
|
+
const expMonth = expDate.substring(0, 2);
|
|
20521
|
+
const expYear = expDate.substring(2);
|
|
20522
|
+
const vantivPaymentRequest = {
|
|
20523
|
+
...vantivResponse,
|
|
20524
|
+
expMonth: expMonth,
|
|
20525
|
+
expYear: expYear
|
|
20526
|
+
};
|
|
20527
|
+
|
|
20528
|
+
// Process the registrationId or continue with further payment processing.
|
|
20529
|
+
dispatch({
|
|
20530
|
+
type: HANDLE_APPLEPAY_SUBSCRIPTION,
|
|
20531
|
+
payload: vantivPaymentRequest
|
|
20532
|
+
});
|
|
20533
|
+
dispatch({
|
|
20534
|
+
type: LOADING,
|
|
20535
|
+
payload: true
|
|
20536
|
+
});
|
|
20537
|
+
session.completePayment(result);
|
|
20538
|
+
}
|
|
20539
|
+
|
|
20540
|
+
// errorCallback function to handle any errors that may occur during the tokenization process.
|
|
20541
|
+
function errorCallback(error) {
|
|
20542
|
+
console.error("Error retrieving Registration ID:", error);
|
|
20543
|
+
// Handle error appropriately.
|
|
20544
|
+
}
|
|
20545
|
+
// errorCallback function to handle any errors that may occur during the tokenization process.
|
|
20546
|
+
function timeoutCallback() {
|
|
20547
|
+
console.error("eProtect Timeout");
|
|
20548
|
+
// Handle error appropriately.
|
|
20549
|
+
}
|
|
20550
|
+
|
|
20551
|
+
// eslint-disable-next-line no-undef
|
|
20552
|
+
new eProtect().sendToEprotect(eProtectRequest, {}, successCallback, errorCallback, timeoutCallback, 15000);
|
|
20553
|
+
};
|
|
20554
|
+
|
|
20555
|
+
// TODO: Check if oncouponcodechanged it should be implemented
|
|
20556
|
+
// session.oncouponcodechanged = (event) => {
|
|
20557
|
+
// console.log("on coupon code changed step", event);
|
|
20558
|
+
// // Define ApplePayCouponCodeUpdate
|
|
20559
|
+
// const newTotal = calculateNewTotal(event.couponCode);
|
|
20560
|
+
// const newLineItems = calculateNewLineItems(event.couponCode);
|
|
20561
|
+
// const newShippingMethods = calculateNewShippingMethods(
|
|
20562
|
+
// event.couponCode
|
|
20563
|
+
// );
|
|
20564
|
+
// const errors = calculateErrors(event.couponCode);
|
|
20565
|
+
|
|
20566
|
+
// session.completeCouponCodeChange({
|
|
20567
|
+
// newTotal: newTotal,
|
|
20568
|
+
// newLineItems: newLineItems,
|
|
20569
|
+
// newShippingMethods: newShippingMethods,
|
|
20570
|
+
// errors: errors
|
|
20571
|
+
// });
|
|
20572
|
+
// };
|
|
20573
|
+
|
|
20574
|
+
session.oncancel = event => {
|
|
20575
|
+
// Payment cancelled by WebKit
|
|
20576
|
+
console.log("on cancel step", event);
|
|
20503
20577
|
dispatch({
|
|
20504
|
-
type:
|
|
20505
|
-
payload:
|
|
20578
|
+
type: LOADING,
|
|
20579
|
+
payload: false
|
|
20506
20580
|
});
|
|
20507
20581
|
dispatch({
|
|
20508
|
-
type:
|
|
20509
|
-
payload:
|
|
20582
|
+
type: DISABLE_SUBMIT,
|
|
20583
|
+
payload: false
|
|
20510
20584
|
});
|
|
20511
|
-
|
|
20512
|
-
|
|
20513
|
-
|
|
20514
|
-
// errorCallback function to handle any errors that may occur during the tokenization process.
|
|
20515
|
-
function errorCallback(error) {
|
|
20516
|
-
console.error("Error retrieving Registration ID:", error);
|
|
20517
|
-
// Handle error appropriately.
|
|
20518
|
-
}
|
|
20519
|
-
// errorCallback function to handle any errors that may occur during the tokenization process.
|
|
20520
|
-
function timeoutCallback() {
|
|
20521
|
-
console.error("eProtect Timeout");
|
|
20522
|
-
// Handle error appropriately.
|
|
20523
|
-
}
|
|
20524
|
-
|
|
20525
|
-
new eProtect().sendToEprotect(eProtectRequest, {}, successCallback, errorCallback, timeoutCallback, 15000);
|
|
20526
|
-
};
|
|
20527
|
-
|
|
20528
|
-
// TODO: Check if oncouponcodechanged it should be implemented
|
|
20529
|
-
// session.oncouponcodechanged = (event) => {
|
|
20530
|
-
// console.log("on coupon code changed step", event);
|
|
20531
|
-
// // Define ApplePayCouponCodeUpdate
|
|
20532
|
-
// const newTotal = calculateNewTotal(event.couponCode);
|
|
20533
|
-
// const newLineItems = calculateNewLineItems(event.couponCode);
|
|
20534
|
-
// const newShippingMethods = calculateNewShippingMethods(
|
|
20535
|
-
// event.couponCode
|
|
20536
|
-
// );
|
|
20537
|
-
// const errors = calculateErrors(event.couponCode);
|
|
20538
|
-
|
|
20539
|
-
// session.completeCouponCodeChange({
|
|
20540
|
-
// newTotal: newTotal,
|
|
20541
|
-
// newLineItems: newLineItems,
|
|
20542
|
-
// newShippingMethods: newShippingMethods,
|
|
20543
|
-
// errors: errors
|
|
20544
|
-
// });
|
|
20545
|
-
// };
|
|
20546
|
-
|
|
20547
|
-
session.oncancel = event => {
|
|
20548
|
-
// Payment cancelled by WebKit
|
|
20549
|
-
console.log("on cancel step", event);
|
|
20550
|
-
dispatch({
|
|
20551
|
-
type: LOADING,
|
|
20552
|
-
payload: false
|
|
20553
|
-
});
|
|
20554
|
-
dispatch({
|
|
20555
|
-
type: DISABLE_SUBMIT,
|
|
20556
|
-
payload: false
|
|
20557
|
-
});
|
|
20558
|
-
};
|
|
20559
|
-
session.begin();
|
|
20560
|
-
}
|
|
20561
|
-
useEffect(() => {
|
|
20585
|
+
};
|
|
20586
|
+
session.begin();
|
|
20587
|
+
}
|
|
20562
20588
|
const pelcroApplyPayButton = document.getElementById("pelcro-apple-pay-button");
|
|
20563
20589
|
if (pelcroApplyPayButton) {
|
|
20564
20590
|
pelcroApplyPayButton.addEventListener("click", onApplePayButtonClicked);
|
|
20565
20591
|
}
|
|
20566
|
-
|
|
20592
|
+
return () => {
|
|
20593
|
+
if (pelcroApplyPayButton) {
|
|
20594
|
+
pelcroApplyPayButton.removeEventListener("click", onApplePayButtonClicked);
|
|
20595
|
+
}
|
|
20596
|
+
};
|
|
20597
|
+
}, [state.updatedPrice]);
|
|
20567
20598
|
return /*#__PURE__*/React__default.createElement("apple-pay-button", {
|
|
20568
20599
|
id: "pelcro-apple-pay-button",
|
|
20569
20600
|
style: {
|