@pelcro/react-pelcro-js 3.26.0-beta.15 → 3.26.0-beta.17
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
|
@@ -21184,14 +21184,12 @@ const DonationEmail = props => /*#__PURE__*/React__default['default'].createElem
|
|
|
21184
21184
|
store: store$k
|
|
21185
21185
|
}, props));
|
|
21186
21186
|
|
|
21187
|
-
/* eslint-disable no-undef */
|
|
21188
|
-
|
|
21189
21187
|
/**
|
|
21190
21188
|
* ApplePayButton component
|
|
21191
21189
|
* @return {JSX}
|
|
21192
21190
|
*/
|
|
21193
21191
|
const ApplePayButton = _ref => {
|
|
21194
|
-
var _window$Pelcro$site$r
|
|
21192
|
+
var _window$Pelcro$site$r;
|
|
21195
21193
|
let {
|
|
21196
21194
|
onClick,
|
|
21197
21195
|
props,
|
|
@@ -21212,28 +21210,43 @@ const ApplePayButton = _ref => {
|
|
|
21212
21210
|
apple_pay_merchant_id: ApplePayMerchantId,
|
|
21213
21211
|
apple_pay_enabled: ApplePayEnabled
|
|
21214
21212
|
} = (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.vantiv_gateway_settings;
|
|
21215
|
-
const
|
|
21213
|
+
const getOrderInfo = () => {
|
|
21216
21214
|
if (!order) {
|
|
21217
|
-
return
|
|
21215
|
+
return {
|
|
21216
|
+
price: null,
|
|
21217
|
+
currency: null,
|
|
21218
|
+
label: null
|
|
21219
|
+
};
|
|
21218
21220
|
}
|
|
21219
21221
|
const isQuickPurchase = !Array.isArray(order);
|
|
21220
21222
|
if (isQuickPurchase) {
|
|
21221
|
-
return
|
|
21223
|
+
return {
|
|
21224
|
+
price: order.price * order.quantity,
|
|
21225
|
+
currency: order.currency,
|
|
21226
|
+
label: order.name
|
|
21227
|
+
};
|
|
21222
21228
|
}
|
|
21223
21229
|
if (order.length === 0) {
|
|
21224
|
-
return
|
|
21230
|
+
return {
|
|
21231
|
+
price: null,
|
|
21232
|
+
currency: null,
|
|
21233
|
+
label: null
|
|
21234
|
+
};
|
|
21225
21235
|
}
|
|
21226
|
-
|
|
21227
|
-
|
|
21228
|
-
|
|
21236
|
+
const price = order.reduce((total, item) => total + item.price * item.quantity, 0);
|
|
21237
|
+
return {
|
|
21238
|
+
price,
|
|
21239
|
+
currency: order[0].currency,
|
|
21240
|
+
label: "Order"
|
|
21241
|
+
};
|
|
21229
21242
|
};
|
|
21230
|
-
const orderPrice =
|
|
21231
|
-
const orderCurrency =
|
|
21232
|
-
const orderLabel =
|
|
21233
|
-
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;
|
|
21243
|
+
const orderPrice = getOrderInfo().price;
|
|
21244
|
+
const orderCurrency = getOrderInfo().currency;
|
|
21245
|
+
const orderLabel = getOrderInfo().label;
|
|
21234
21246
|
React.useEffect(() => {
|
|
21235
21247
|
if (window.ApplePaySession) {
|
|
21236
21248
|
// Indicates whether the device supports Apple Pay and whether the user has an active card in Wallet.
|
|
21249
|
+
// eslint-disable-next-line no-undef
|
|
21237
21250
|
const promise = ApplePaySession.canMakePaymentsWithActiveCard(ApplePayMerchantId);
|
|
21238
21251
|
promise.then(function (canMakePayments) {
|
|
21239
21252
|
if (canMakePayments && ApplePayEnabled) {
|
|
@@ -21249,233 +21262,251 @@ const ApplePayButton = _ref => {
|
|
|
21249
21262
|
console.error("ApplePay is not available on this browser");
|
|
21250
21263
|
}
|
|
21251
21264
|
}, []);
|
|
21252
|
-
|
|
21253
|
-
|
|
21254
|
-
|
|
21255
|
-
|
|
21256
|
-
|
|
21257
|
-
|
|
21258
|
-
type: DISABLE_SUBMIT,
|
|
21259
|
-
payload: true
|
|
21260
|
-
});
|
|
21261
|
-
|
|
21262
|
-
// Define ApplePayPaymentRequest
|
|
21263
|
-
// @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session
|
|
21264
|
-
const ApplePayPaymentRequest = {
|
|
21265
|
-
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",
|
|
21266
|
-
currencyCode: (plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase()) || orderCurrency.toUpperCase() || (invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase()),
|
|
21267
|
-
merchantCapabilities: ["supports3DS"],
|
|
21268
|
-
supportedNetworks: ["visa", "masterCard", "amex", "discover"],
|
|
21269
|
-
total: {
|
|
21270
|
-
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
21271
|
-
type: "final",
|
|
21272
|
-
amount: updatedPrice / 100
|
|
21265
|
+
React.useEffect(() => {
|
|
21266
|
+
function onApplePayButtonClicked() {
|
|
21267
|
+
var _ref2, _ref3, _ref4, _ref5, _state$updatedPrice, _props$plan, _window, _window$Pelcro, _window$Pelcro$user, _window$Pelcro$user$l;
|
|
21268
|
+
// eslint-disable-next-line no-undef
|
|
21269
|
+
if (!ApplePaySession) {
|
|
21270
|
+
return;
|
|
21273
21271
|
}
|
|
21274
|
-
|
|
21275
|
-
|
|
21276
|
-
|
|
21277
|
-
|
|
21278
|
-
|
|
21279
|
-
|
|
21280
|
-
|
|
21281
|
-
|
|
21282
|
-
// @see https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778014-supportsversion
|
|
21283
|
-
|
|
21284
|
-
session.onvalidatemerchant = async event => {
|
|
21285
|
-
const {
|
|
21286
|
-
validationURL
|
|
21287
|
-
} = event;
|
|
21288
|
-
console.log("then merchantSession step", event);
|
|
21289
|
-
// Call your own server to request a new merchant session.
|
|
21290
|
-
window.Pelcro.payment.startSession({
|
|
21291
|
-
auth_token: window.Pelcro.user.read().auth_token,
|
|
21292
|
-
site_id: window.Pelcro.siteid,
|
|
21293
|
-
validation_url: validationURL
|
|
21294
|
-
}, (err, res) => {
|
|
21295
|
-
if (err) {
|
|
21296
|
-
// Handle any errors during merchant validation
|
|
21297
|
-
console.error("Merchant validation SDK error: ", err);
|
|
21298
|
-
session.abort();
|
|
21299
|
-
return dispatch({
|
|
21300
|
-
type: SHOW_ALERT,
|
|
21301
|
-
payload: {
|
|
21302
|
-
type: "error",
|
|
21303
|
-
content: getErrorMessages(err)
|
|
21304
|
-
}
|
|
21305
|
-
});
|
|
21272
|
+
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;
|
|
21273
|
+
const getCurrencyCode = () => {
|
|
21274
|
+
if (plan) {
|
|
21275
|
+
return plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase();
|
|
21276
|
+
} else if (order) {
|
|
21277
|
+
return orderCurrency.toUpperCase();
|
|
21278
|
+
} else if (invoice) {
|
|
21279
|
+
return invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase();
|
|
21306
21280
|
}
|
|
21307
|
-
// Complete merchant validation with the merchant session object
|
|
21308
|
-
console.log("Merchant validation SDK response: ", res);
|
|
21309
|
-
const merchantSession = res;
|
|
21310
|
-
session.completeMerchantValidation(merchantSession);
|
|
21311
|
-
});
|
|
21312
|
-
};
|
|
21313
|
-
session.onpaymentmethodselected = event => {
|
|
21314
|
-
console.log("payment method selected step", event);
|
|
21315
|
-
// Define ApplePayPaymentMethodUpdate based on the selected payment method.
|
|
21316
|
-
// No updates or errors are needed, pass an empty object.
|
|
21317
|
-
const newTotal = {
|
|
21318
|
-
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
21319
|
-
type: "final",
|
|
21320
|
-
amount: updatedPrice / 100
|
|
21321
21281
|
};
|
|
21322
|
-
|
|
21323
|
-
|
|
21324
|
-
|
|
21325
|
-
|
|
21326
|
-
}];
|
|
21327
|
-
session.completePaymentMethodSelection(newTotal, newLineItems);
|
|
21328
|
-
};
|
|
21282
|
+
dispatch({
|
|
21283
|
+
type: DISABLE_SUBMIT,
|
|
21284
|
+
payload: true
|
|
21285
|
+
});
|
|
21329
21286
|
|
|
21330
|
-
|
|
21331
|
-
|
|
21332
|
-
|
|
21333
|
-
|
|
21334
|
-
|
|
21335
|
-
|
|
21336
|
-
|
|
21337
|
-
|
|
21338
|
-
|
|
21339
|
-
|
|
21340
|
-
|
|
21341
|
-
// const newLineItems = [
|
|
21342
|
-
// {
|
|
21343
|
-
// label: plan?.nickname || orderLabel || `invoice #${invoice?.id}`,
|
|
21344
|
-
// type: "final",
|
|
21345
|
-
// amount: updatedPrice / 100
|
|
21346
|
-
// }
|
|
21347
|
-
// ];
|
|
21348
|
-
|
|
21349
|
-
// session.completeShippingMethodSelection(newTotal, newLineItems);
|
|
21350
|
-
// };
|
|
21351
|
-
|
|
21352
|
-
// TODO: Check if onshippingcontactselected it should be implemented
|
|
21353
|
-
// session.onshippingcontactselected = (event) => {
|
|
21354
|
-
// console.log("on shipping contact selected step", event);
|
|
21355
|
-
// // Define ApplePayShippingContactUpdate based on the selected shipping contact.
|
|
21356
|
-
// const update = {};
|
|
21357
|
-
// session.completeShippingContactSelection(update);
|
|
21358
|
-
// };
|
|
21359
|
-
|
|
21360
|
-
session.onpaymentauthorized = event => {
|
|
21361
|
-
console.log("on payment authorized step", event);
|
|
21362
|
-
// Define ApplePayPaymentAuthorizationResult
|
|
21363
|
-
const result = {
|
|
21364
|
-
status: ApplePaySession.STATUS_SUCCESS
|
|
21365
|
-
};
|
|
21366
|
-
const {
|
|
21367
|
-
paymentData
|
|
21368
|
-
} = event.payment.token;
|
|
21369
|
-
const {
|
|
21370
|
-
data,
|
|
21371
|
-
signature,
|
|
21372
|
-
version
|
|
21373
|
-
} = paymentData;
|
|
21374
|
-
const {
|
|
21375
|
-
ephemeralPublicKey,
|
|
21376
|
-
publicKeyHash,
|
|
21377
|
-
transactionId
|
|
21378
|
-
} = paymentData.header;
|
|
21379
|
-
const applePayToken = {
|
|
21380
|
-
data: data,
|
|
21381
|
-
signature: signature,
|
|
21382
|
-
version: version,
|
|
21383
|
-
header: {
|
|
21384
|
-
ephemeralPublicKey: ephemeralPublicKey,
|
|
21385
|
-
publicKeyHash: publicKeyHash,
|
|
21386
|
-
transactionId: transactionId
|
|
21287
|
+
// Define ApplePayPaymentRequest
|
|
21288
|
+
// @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session
|
|
21289
|
+
const ApplePayPaymentRequest = {
|
|
21290
|
+
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",
|
|
21291
|
+
currencyCode: getCurrencyCode(),
|
|
21292
|
+
merchantCapabilities: ["supports3DS"],
|
|
21293
|
+
supportedNetworks: ["visa", "masterCard", "amex", "discover"],
|
|
21294
|
+
total: {
|
|
21295
|
+
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
21296
|
+
type: "final",
|
|
21297
|
+
amount: updatedPrice / 100
|
|
21387
21298
|
}
|
|
21388
21299
|
};
|
|
21389
|
-
console.log(
|
|
21390
|
-
|
|
21391
|
-
|
|
21392
|
-
|
|
21393
|
-
|
|
21394
|
-
|
|
21395
|
-
|
|
21396
|
-
|
|
21397
|
-
|
|
21300
|
+
console.log(ApplePayPaymentRequest);
|
|
21301
|
+
// Create ApplePaySession
|
|
21302
|
+
// @todo - Clarify supported version parameter
|
|
21303
|
+
// @odo - Apple Pay demo uses version 6 (https://applepaydemo.apple.com/)
|
|
21304
|
+
const session = new ApplePaySession(3, ApplePayPaymentRequest); // eslint-disable-line no-undef
|
|
21305
|
+
|
|
21306
|
+
// @todo - Detect whether web browser supports a particular Apple Pay version.
|
|
21307
|
+
// @see https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778014-supportsversion
|
|
21308
|
+
|
|
21309
|
+
session.onvalidatemerchant = async event => {
|
|
21310
|
+
const {
|
|
21311
|
+
validationURL
|
|
21312
|
+
} = event;
|
|
21313
|
+
console.log("then merchantSession step", event);
|
|
21314
|
+
// Call your own server to request a new merchant session.
|
|
21315
|
+
window.Pelcro.payment.startSession({
|
|
21316
|
+
auth_token: window.Pelcro.user.read().auth_token,
|
|
21317
|
+
site_id: window.Pelcro.siteid,
|
|
21318
|
+
validation_url: validationURL
|
|
21319
|
+
}, (err, res) => {
|
|
21320
|
+
if (err) {
|
|
21321
|
+
// Handle any errors during merchant validation
|
|
21322
|
+
console.error("Merchant validation SDK error: ", err);
|
|
21323
|
+
session.abort();
|
|
21324
|
+
return dispatch({
|
|
21325
|
+
type: SHOW_ALERT,
|
|
21326
|
+
payload: {
|
|
21327
|
+
type: "error",
|
|
21328
|
+
content: getErrorMessages(err)
|
|
21329
|
+
}
|
|
21330
|
+
});
|
|
21331
|
+
}
|
|
21332
|
+
// Complete merchant validation with the merchant session object
|
|
21333
|
+
console.log("Merchant validation SDK response: ", res);
|
|
21334
|
+
const merchantSession = res;
|
|
21335
|
+
session.completeMerchantValidation(merchantSession);
|
|
21336
|
+
});
|
|
21337
|
+
};
|
|
21338
|
+
session.onpaymentmethodselected = event => {
|
|
21339
|
+
console.log("payment method selected step", event);
|
|
21340
|
+
// Define ApplePayPaymentMethodUpdate based on the selected payment method.
|
|
21341
|
+
// No updates or errors are needed, pass an empty object.
|
|
21342
|
+
const newTotal = {
|
|
21343
|
+
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
21344
|
+
type: "final",
|
|
21345
|
+
amount: updatedPrice / 100
|
|
21346
|
+
};
|
|
21347
|
+
const newLineItems = [{
|
|
21348
|
+
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
21349
|
+
type: "final",
|
|
21350
|
+
amount: updatedPrice / 100
|
|
21351
|
+
}];
|
|
21352
|
+
session.completePaymentMethodSelection(newTotal, newLineItems);
|
|
21398
21353
|
};
|
|
21399
21354
|
|
|
21400
|
-
//
|
|
21401
|
-
|
|
21355
|
+
// TODO: Check if onshippingmethodselected it should be implemented
|
|
21356
|
+
// session.onshippingmethodselected = (event) => {
|
|
21357
|
+
// console.log("on shipping method selected step", event);
|
|
21358
|
+
// // Define ApplePayShippingMethodUpdate based on the selected shipping method.
|
|
21359
|
+
// // No updates or errors are needed, pass an empty object.
|
|
21360
|
+
// const newTotal = {
|
|
21361
|
+
// label: plan?.nickname || orderLabel || `invoice #${invoice?.id}`,
|
|
21362
|
+
// type: "final",
|
|
21363
|
+
// amount: updatedPrice / 100
|
|
21364
|
+
// };
|
|
21365
|
+
|
|
21366
|
+
// const newLineItems = [
|
|
21367
|
+
// {
|
|
21368
|
+
// label: plan?.nickname || orderLabel || `invoice #${invoice?.id}`,
|
|
21369
|
+
// type: "final",
|
|
21370
|
+
// amount: updatedPrice / 100
|
|
21371
|
+
// }
|
|
21372
|
+
// ];
|
|
21373
|
+
|
|
21374
|
+
// session.completeShippingMethodSelection(newTotal, newLineItems);
|
|
21375
|
+
// };
|
|
21376
|
+
|
|
21377
|
+
// TODO: Check if onshippingcontactselected it should be implemented
|
|
21378
|
+
// session.onshippingcontactselected = (event) => {
|
|
21379
|
+
// console.log("on shipping contact selected step", event);
|
|
21380
|
+
// // Define ApplePayShippingContactUpdate based on the selected shipping contact.
|
|
21381
|
+
// const update = {};
|
|
21382
|
+
// session.completeShippingContactSelection(update);
|
|
21383
|
+
// };
|
|
21384
|
+
|
|
21385
|
+
session.onpaymentauthorized = event => {
|
|
21386
|
+
console.log("on payment authorized step", event);
|
|
21387
|
+
// Define ApplePayPaymentAuthorizationResult
|
|
21388
|
+
const result = {
|
|
21389
|
+
status: ApplePaySession.STATUS_SUCCESS // eslint-disable-line no-undef
|
|
21390
|
+
};
|
|
21391
|
+
|
|
21392
|
+
const {
|
|
21393
|
+
paymentData
|
|
21394
|
+
} = event.payment.token;
|
|
21402
21395
|
const {
|
|
21403
|
-
|
|
21404
|
-
|
|
21405
|
-
|
|
21406
|
-
|
|
21407
|
-
const
|
|
21408
|
-
|
|
21409
|
-
|
|
21410
|
-
|
|
21411
|
-
|
|
21396
|
+
data,
|
|
21397
|
+
signature,
|
|
21398
|
+
version
|
|
21399
|
+
} = paymentData;
|
|
21400
|
+
const {
|
|
21401
|
+
ephemeralPublicKey,
|
|
21402
|
+
publicKeyHash,
|
|
21403
|
+
transactionId
|
|
21404
|
+
} = paymentData.header;
|
|
21405
|
+
const applePayToken = {
|
|
21406
|
+
data: data,
|
|
21407
|
+
signature: signature,
|
|
21408
|
+
version: version,
|
|
21409
|
+
header: {
|
|
21410
|
+
ephemeralPublicKey: ephemeralPublicKey,
|
|
21411
|
+
publicKeyHash: publicKeyHash,
|
|
21412
|
+
transactionId: transactionId
|
|
21413
|
+
}
|
|
21414
|
+
};
|
|
21415
|
+
console.log(applePayToken);
|
|
21416
|
+
const orderId = `pelcro-${new Date().getTime()}`;
|
|
21417
|
+
const eProtectRequest = {
|
|
21418
|
+
paypageId: payPageId,
|
|
21419
|
+
reportGroup: reportGroup,
|
|
21420
|
+
orderId: orderId,
|
|
21421
|
+
id: orderId,
|
|
21422
|
+
applepay: applePayToken,
|
|
21423
|
+
url: "https://request.eprotect.vantivprelive.com"
|
|
21412
21424
|
};
|
|
21413
21425
|
|
|
21414
|
-
//
|
|
21426
|
+
// successCallback function to handle the response from WorldPay.
|
|
21427
|
+
function successCallback(vantivResponse) {
|
|
21428
|
+
const {
|
|
21429
|
+
expDate
|
|
21430
|
+
} = vantivResponse;
|
|
21431
|
+
console.log("Response:", vantivResponse);
|
|
21432
|
+
const expMonth = expDate.substring(0, 2);
|
|
21433
|
+
const expYear = expDate.substring(2);
|
|
21434
|
+
const vantivPaymentRequest = {
|
|
21435
|
+
...vantivResponse,
|
|
21436
|
+
expMonth: expMonth,
|
|
21437
|
+
expYear: expYear
|
|
21438
|
+
};
|
|
21439
|
+
|
|
21440
|
+
// Process the registrationId or continue with further payment processing.
|
|
21441
|
+
dispatch({
|
|
21442
|
+
type: HANDLE_APPLEPAY_SUBSCRIPTION,
|
|
21443
|
+
payload: vantivPaymentRequest
|
|
21444
|
+
});
|
|
21445
|
+
dispatch({
|
|
21446
|
+
type: LOADING,
|
|
21447
|
+
payload: true
|
|
21448
|
+
});
|
|
21449
|
+
session.completePayment(result);
|
|
21450
|
+
}
|
|
21451
|
+
|
|
21452
|
+
// errorCallback function to handle any errors that may occur during the tokenization process.
|
|
21453
|
+
function errorCallback(error) {
|
|
21454
|
+
console.error("Error retrieving Registration ID:", error);
|
|
21455
|
+
// Handle error appropriately.
|
|
21456
|
+
}
|
|
21457
|
+
// errorCallback function to handle any errors that may occur during the tokenization process.
|
|
21458
|
+
function timeoutCallback() {
|
|
21459
|
+
console.error("eProtect Timeout");
|
|
21460
|
+
// Handle error appropriately.
|
|
21461
|
+
}
|
|
21462
|
+
|
|
21463
|
+
// eslint-disable-next-line no-undef
|
|
21464
|
+
new eProtect().sendToEprotect(eProtectRequest, {}, successCallback, errorCallback, timeoutCallback, 15000);
|
|
21465
|
+
};
|
|
21466
|
+
|
|
21467
|
+
// TODO: Check if oncouponcodechanged it should be implemented
|
|
21468
|
+
// session.oncouponcodechanged = (event) => {
|
|
21469
|
+
// console.log("on coupon code changed step", event);
|
|
21470
|
+
// // Define ApplePayCouponCodeUpdate
|
|
21471
|
+
// const newTotal = calculateNewTotal(event.couponCode);
|
|
21472
|
+
// const newLineItems = calculateNewLineItems(event.couponCode);
|
|
21473
|
+
// const newShippingMethods = calculateNewShippingMethods(
|
|
21474
|
+
// event.couponCode
|
|
21475
|
+
// );
|
|
21476
|
+
// const errors = calculateErrors(event.couponCode);
|
|
21477
|
+
|
|
21478
|
+
// session.completeCouponCodeChange({
|
|
21479
|
+
// newTotal: newTotal,
|
|
21480
|
+
// newLineItems: newLineItems,
|
|
21481
|
+
// newShippingMethods: newShippingMethods,
|
|
21482
|
+
// errors: errors
|
|
21483
|
+
// });
|
|
21484
|
+
// };
|
|
21485
|
+
|
|
21486
|
+
session.oncancel = event => {
|
|
21487
|
+
// Payment cancelled by WebKit
|
|
21488
|
+
console.log("on cancel step", event);
|
|
21415
21489
|
dispatch({
|
|
21416
|
-
type:
|
|
21417
|
-
payload:
|
|
21490
|
+
type: LOADING,
|
|
21491
|
+
payload: false
|
|
21418
21492
|
});
|
|
21419
21493
|
dispatch({
|
|
21420
|
-
type:
|
|
21421
|
-
payload:
|
|
21494
|
+
type: DISABLE_SUBMIT,
|
|
21495
|
+
payload: false
|
|
21422
21496
|
});
|
|
21423
|
-
|
|
21424
|
-
|
|
21425
|
-
|
|
21426
|
-
// errorCallback function to handle any errors that may occur during the tokenization process.
|
|
21427
|
-
function errorCallback(error) {
|
|
21428
|
-
console.error("Error retrieving Registration ID:", error);
|
|
21429
|
-
// Handle error appropriately.
|
|
21430
|
-
}
|
|
21431
|
-
// errorCallback function to handle any errors that may occur during the tokenization process.
|
|
21432
|
-
function timeoutCallback() {
|
|
21433
|
-
console.error("eProtect Timeout");
|
|
21434
|
-
// Handle error appropriately.
|
|
21435
|
-
}
|
|
21436
|
-
|
|
21437
|
-
new eProtect().sendToEprotect(eProtectRequest, {}, successCallback, errorCallback, timeoutCallback, 15000);
|
|
21438
|
-
};
|
|
21439
|
-
|
|
21440
|
-
// TODO: Check if oncouponcodechanged it should be implemented
|
|
21441
|
-
// session.oncouponcodechanged = (event) => {
|
|
21442
|
-
// console.log("on coupon code changed step", event);
|
|
21443
|
-
// // Define ApplePayCouponCodeUpdate
|
|
21444
|
-
// const newTotal = calculateNewTotal(event.couponCode);
|
|
21445
|
-
// const newLineItems = calculateNewLineItems(event.couponCode);
|
|
21446
|
-
// const newShippingMethods = calculateNewShippingMethods(
|
|
21447
|
-
// event.couponCode
|
|
21448
|
-
// );
|
|
21449
|
-
// const errors = calculateErrors(event.couponCode);
|
|
21450
|
-
|
|
21451
|
-
// session.completeCouponCodeChange({
|
|
21452
|
-
// newTotal: newTotal,
|
|
21453
|
-
// newLineItems: newLineItems,
|
|
21454
|
-
// newShippingMethods: newShippingMethods,
|
|
21455
|
-
// errors: errors
|
|
21456
|
-
// });
|
|
21457
|
-
// };
|
|
21458
|
-
|
|
21459
|
-
session.oncancel = event => {
|
|
21460
|
-
// Payment cancelled by WebKit
|
|
21461
|
-
console.log("on cancel step", event);
|
|
21462
|
-
dispatch({
|
|
21463
|
-
type: LOADING,
|
|
21464
|
-
payload: false
|
|
21465
|
-
});
|
|
21466
|
-
dispatch({
|
|
21467
|
-
type: DISABLE_SUBMIT,
|
|
21468
|
-
payload: false
|
|
21469
|
-
});
|
|
21470
|
-
};
|
|
21471
|
-
session.begin();
|
|
21472
|
-
}
|
|
21473
|
-
React.useEffect(() => {
|
|
21497
|
+
};
|
|
21498
|
+
session.begin();
|
|
21499
|
+
}
|
|
21474
21500
|
const pelcroApplyPayButton = document.getElementById("pelcro-apple-pay-button");
|
|
21475
21501
|
if (pelcroApplyPayButton) {
|
|
21476
21502
|
pelcroApplyPayButton.addEventListener("click", onApplePayButtonClicked);
|
|
21477
21503
|
}
|
|
21478
|
-
|
|
21504
|
+
return () => {
|
|
21505
|
+
if (pelcroApplyPayButton) {
|
|
21506
|
+
pelcroApplyPayButton.removeEventListener("click", onApplePayButtonClicked);
|
|
21507
|
+
}
|
|
21508
|
+
};
|
|
21509
|
+
}, [state.updatedPrice]);
|
|
21479
21510
|
return /*#__PURE__*/React__default['default'].createElement("apple-pay-button", {
|
|
21480
21511
|
id: "pelcro-apple-pay-button",
|
|
21481
21512
|
style: {
|
package/dist/index.esm.js
CHANGED
|
@@ -21154,14 +21154,12 @@ const DonationEmail = props => /*#__PURE__*/React__default.createElement(Email,
|
|
|
21154
21154
|
store: store$k
|
|
21155
21155
|
}, props));
|
|
21156
21156
|
|
|
21157
|
-
/* eslint-disable no-undef */
|
|
21158
|
-
|
|
21159
21157
|
/**
|
|
21160
21158
|
* ApplePayButton component
|
|
21161
21159
|
* @return {JSX}
|
|
21162
21160
|
*/
|
|
21163
21161
|
const ApplePayButton = _ref => {
|
|
21164
|
-
var _window$Pelcro$site$r
|
|
21162
|
+
var _window$Pelcro$site$r;
|
|
21165
21163
|
let {
|
|
21166
21164
|
onClick,
|
|
21167
21165
|
props,
|
|
@@ -21182,28 +21180,43 @@ const ApplePayButton = _ref => {
|
|
|
21182
21180
|
apple_pay_merchant_id: ApplePayMerchantId,
|
|
21183
21181
|
apple_pay_enabled: ApplePayEnabled
|
|
21184
21182
|
} = (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.vantiv_gateway_settings;
|
|
21185
|
-
const
|
|
21183
|
+
const getOrderInfo = () => {
|
|
21186
21184
|
if (!order) {
|
|
21187
|
-
return
|
|
21185
|
+
return {
|
|
21186
|
+
price: null,
|
|
21187
|
+
currency: null,
|
|
21188
|
+
label: null
|
|
21189
|
+
};
|
|
21188
21190
|
}
|
|
21189
21191
|
const isQuickPurchase = !Array.isArray(order);
|
|
21190
21192
|
if (isQuickPurchase) {
|
|
21191
|
-
return
|
|
21193
|
+
return {
|
|
21194
|
+
price: order.price * order.quantity,
|
|
21195
|
+
currency: order.currency,
|
|
21196
|
+
label: order.name
|
|
21197
|
+
};
|
|
21192
21198
|
}
|
|
21193
21199
|
if (order.length === 0) {
|
|
21194
|
-
return
|
|
21200
|
+
return {
|
|
21201
|
+
price: null,
|
|
21202
|
+
currency: null,
|
|
21203
|
+
label: null
|
|
21204
|
+
};
|
|
21195
21205
|
}
|
|
21196
|
-
|
|
21197
|
-
|
|
21198
|
-
|
|
21206
|
+
const price = order.reduce((total, item) => total + item.price * item.quantity, 0);
|
|
21207
|
+
return {
|
|
21208
|
+
price,
|
|
21209
|
+
currency: order[0].currency,
|
|
21210
|
+
label: "Order"
|
|
21211
|
+
};
|
|
21199
21212
|
};
|
|
21200
|
-
const orderPrice =
|
|
21201
|
-
const orderCurrency =
|
|
21202
|
-
const orderLabel =
|
|
21203
|
-
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;
|
|
21213
|
+
const orderPrice = getOrderInfo().price;
|
|
21214
|
+
const orderCurrency = getOrderInfo().currency;
|
|
21215
|
+
const orderLabel = getOrderInfo().label;
|
|
21204
21216
|
useEffect(() => {
|
|
21205
21217
|
if (window.ApplePaySession) {
|
|
21206
21218
|
// Indicates whether the device supports Apple Pay and whether the user has an active card in Wallet.
|
|
21219
|
+
// eslint-disable-next-line no-undef
|
|
21207
21220
|
const promise = ApplePaySession.canMakePaymentsWithActiveCard(ApplePayMerchantId);
|
|
21208
21221
|
promise.then(function (canMakePayments) {
|
|
21209
21222
|
if (canMakePayments && ApplePayEnabled) {
|
|
@@ -21219,233 +21232,251 @@ const ApplePayButton = _ref => {
|
|
|
21219
21232
|
console.error("ApplePay is not available on this browser");
|
|
21220
21233
|
}
|
|
21221
21234
|
}, []);
|
|
21222
|
-
|
|
21223
|
-
|
|
21224
|
-
|
|
21225
|
-
|
|
21226
|
-
|
|
21227
|
-
|
|
21228
|
-
type: DISABLE_SUBMIT,
|
|
21229
|
-
payload: true
|
|
21230
|
-
});
|
|
21231
|
-
|
|
21232
|
-
// Define ApplePayPaymentRequest
|
|
21233
|
-
// @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session
|
|
21234
|
-
const ApplePayPaymentRequest = {
|
|
21235
|
-
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",
|
|
21236
|
-
currencyCode: (plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase()) || orderCurrency.toUpperCase() || (invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase()),
|
|
21237
|
-
merchantCapabilities: ["supports3DS"],
|
|
21238
|
-
supportedNetworks: ["visa", "masterCard", "amex", "discover"],
|
|
21239
|
-
total: {
|
|
21240
|
-
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
21241
|
-
type: "final",
|
|
21242
|
-
amount: updatedPrice / 100
|
|
21235
|
+
useEffect(() => {
|
|
21236
|
+
function onApplePayButtonClicked() {
|
|
21237
|
+
var _ref2, _ref3, _ref4, _ref5, _state$updatedPrice, _props$plan, _window, _window$Pelcro, _window$Pelcro$user, _window$Pelcro$user$l;
|
|
21238
|
+
// eslint-disable-next-line no-undef
|
|
21239
|
+
if (!ApplePaySession) {
|
|
21240
|
+
return;
|
|
21243
21241
|
}
|
|
21244
|
-
|
|
21245
|
-
|
|
21246
|
-
|
|
21247
|
-
|
|
21248
|
-
|
|
21249
|
-
|
|
21250
|
-
|
|
21251
|
-
|
|
21252
|
-
// @see https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778014-supportsversion
|
|
21253
|
-
|
|
21254
|
-
session.onvalidatemerchant = async event => {
|
|
21255
|
-
const {
|
|
21256
|
-
validationURL
|
|
21257
|
-
} = event;
|
|
21258
|
-
console.log("then merchantSession step", event);
|
|
21259
|
-
// Call your own server to request a new merchant session.
|
|
21260
|
-
window.Pelcro.payment.startSession({
|
|
21261
|
-
auth_token: window.Pelcro.user.read().auth_token,
|
|
21262
|
-
site_id: window.Pelcro.siteid,
|
|
21263
|
-
validation_url: validationURL
|
|
21264
|
-
}, (err, res) => {
|
|
21265
|
-
if (err) {
|
|
21266
|
-
// Handle any errors during merchant validation
|
|
21267
|
-
console.error("Merchant validation SDK error: ", err);
|
|
21268
|
-
session.abort();
|
|
21269
|
-
return dispatch({
|
|
21270
|
-
type: SHOW_ALERT,
|
|
21271
|
-
payload: {
|
|
21272
|
-
type: "error",
|
|
21273
|
-
content: getErrorMessages(err)
|
|
21274
|
-
}
|
|
21275
|
-
});
|
|
21242
|
+
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;
|
|
21243
|
+
const getCurrencyCode = () => {
|
|
21244
|
+
if (plan) {
|
|
21245
|
+
return plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase();
|
|
21246
|
+
} else if (order) {
|
|
21247
|
+
return orderCurrency.toUpperCase();
|
|
21248
|
+
} else if (invoice) {
|
|
21249
|
+
return invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase();
|
|
21276
21250
|
}
|
|
21277
|
-
// Complete merchant validation with the merchant session object
|
|
21278
|
-
console.log("Merchant validation SDK response: ", res);
|
|
21279
|
-
const merchantSession = res;
|
|
21280
|
-
session.completeMerchantValidation(merchantSession);
|
|
21281
|
-
});
|
|
21282
|
-
};
|
|
21283
|
-
session.onpaymentmethodselected = event => {
|
|
21284
|
-
console.log("payment method selected step", event);
|
|
21285
|
-
// Define ApplePayPaymentMethodUpdate based on the selected payment method.
|
|
21286
|
-
// No updates or errors are needed, pass an empty object.
|
|
21287
|
-
const newTotal = {
|
|
21288
|
-
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
21289
|
-
type: "final",
|
|
21290
|
-
amount: updatedPrice / 100
|
|
21291
21251
|
};
|
|
21292
|
-
|
|
21293
|
-
|
|
21294
|
-
|
|
21295
|
-
|
|
21296
|
-
}];
|
|
21297
|
-
session.completePaymentMethodSelection(newTotal, newLineItems);
|
|
21298
|
-
};
|
|
21252
|
+
dispatch({
|
|
21253
|
+
type: DISABLE_SUBMIT,
|
|
21254
|
+
payload: true
|
|
21255
|
+
});
|
|
21299
21256
|
|
|
21300
|
-
|
|
21301
|
-
|
|
21302
|
-
|
|
21303
|
-
|
|
21304
|
-
|
|
21305
|
-
|
|
21306
|
-
|
|
21307
|
-
|
|
21308
|
-
|
|
21309
|
-
|
|
21310
|
-
|
|
21311
|
-
// const newLineItems = [
|
|
21312
|
-
// {
|
|
21313
|
-
// label: plan?.nickname || orderLabel || `invoice #${invoice?.id}`,
|
|
21314
|
-
// type: "final",
|
|
21315
|
-
// amount: updatedPrice / 100
|
|
21316
|
-
// }
|
|
21317
|
-
// ];
|
|
21318
|
-
|
|
21319
|
-
// session.completeShippingMethodSelection(newTotal, newLineItems);
|
|
21320
|
-
// };
|
|
21321
|
-
|
|
21322
|
-
// TODO: Check if onshippingcontactselected it should be implemented
|
|
21323
|
-
// session.onshippingcontactselected = (event) => {
|
|
21324
|
-
// console.log("on shipping contact selected step", event);
|
|
21325
|
-
// // Define ApplePayShippingContactUpdate based on the selected shipping contact.
|
|
21326
|
-
// const update = {};
|
|
21327
|
-
// session.completeShippingContactSelection(update);
|
|
21328
|
-
// };
|
|
21329
|
-
|
|
21330
|
-
session.onpaymentauthorized = event => {
|
|
21331
|
-
console.log("on payment authorized step", event);
|
|
21332
|
-
// Define ApplePayPaymentAuthorizationResult
|
|
21333
|
-
const result = {
|
|
21334
|
-
status: ApplePaySession.STATUS_SUCCESS
|
|
21335
|
-
};
|
|
21336
|
-
const {
|
|
21337
|
-
paymentData
|
|
21338
|
-
} = event.payment.token;
|
|
21339
|
-
const {
|
|
21340
|
-
data,
|
|
21341
|
-
signature,
|
|
21342
|
-
version
|
|
21343
|
-
} = paymentData;
|
|
21344
|
-
const {
|
|
21345
|
-
ephemeralPublicKey,
|
|
21346
|
-
publicKeyHash,
|
|
21347
|
-
transactionId
|
|
21348
|
-
} = paymentData.header;
|
|
21349
|
-
const applePayToken = {
|
|
21350
|
-
data: data,
|
|
21351
|
-
signature: signature,
|
|
21352
|
-
version: version,
|
|
21353
|
-
header: {
|
|
21354
|
-
ephemeralPublicKey: ephemeralPublicKey,
|
|
21355
|
-
publicKeyHash: publicKeyHash,
|
|
21356
|
-
transactionId: transactionId
|
|
21257
|
+
// Define ApplePayPaymentRequest
|
|
21258
|
+
// @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session
|
|
21259
|
+
const ApplePayPaymentRequest = {
|
|
21260
|
+
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",
|
|
21261
|
+
currencyCode: getCurrencyCode(),
|
|
21262
|
+
merchantCapabilities: ["supports3DS"],
|
|
21263
|
+
supportedNetworks: ["visa", "masterCard", "amex", "discover"],
|
|
21264
|
+
total: {
|
|
21265
|
+
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
21266
|
+
type: "final",
|
|
21267
|
+
amount: updatedPrice / 100
|
|
21357
21268
|
}
|
|
21358
21269
|
};
|
|
21359
|
-
console.log(
|
|
21360
|
-
|
|
21361
|
-
|
|
21362
|
-
|
|
21363
|
-
|
|
21364
|
-
|
|
21365
|
-
|
|
21366
|
-
|
|
21367
|
-
|
|
21270
|
+
console.log(ApplePayPaymentRequest);
|
|
21271
|
+
// Create ApplePaySession
|
|
21272
|
+
// @todo - Clarify supported version parameter
|
|
21273
|
+
// @odo - Apple Pay demo uses version 6 (https://applepaydemo.apple.com/)
|
|
21274
|
+
const session = new ApplePaySession(3, ApplePayPaymentRequest); // eslint-disable-line no-undef
|
|
21275
|
+
|
|
21276
|
+
// @todo - Detect whether web browser supports a particular Apple Pay version.
|
|
21277
|
+
// @see https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778014-supportsversion
|
|
21278
|
+
|
|
21279
|
+
session.onvalidatemerchant = async event => {
|
|
21280
|
+
const {
|
|
21281
|
+
validationURL
|
|
21282
|
+
} = event;
|
|
21283
|
+
console.log("then merchantSession step", event);
|
|
21284
|
+
// Call your own server to request a new merchant session.
|
|
21285
|
+
window.Pelcro.payment.startSession({
|
|
21286
|
+
auth_token: window.Pelcro.user.read().auth_token,
|
|
21287
|
+
site_id: window.Pelcro.siteid,
|
|
21288
|
+
validation_url: validationURL
|
|
21289
|
+
}, (err, res) => {
|
|
21290
|
+
if (err) {
|
|
21291
|
+
// Handle any errors during merchant validation
|
|
21292
|
+
console.error("Merchant validation SDK error: ", err);
|
|
21293
|
+
session.abort();
|
|
21294
|
+
return dispatch({
|
|
21295
|
+
type: SHOW_ALERT,
|
|
21296
|
+
payload: {
|
|
21297
|
+
type: "error",
|
|
21298
|
+
content: getErrorMessages(err)
|
|
21299
|
+
}
|
|
21300
|
+
});
|
|
21301
|
+
}
|
|
21302
|
+
// Complete merchant validation with the merchant session object
|
|
21303
|
+
console.log("Merchant validation SDK response: ", res);
|
|
21304
|
+
const merchantSession = res;
|
|
21305
|
+
session.completeMerchantValidation(merchantSession);
|
|
21306
|
+
});
|
|
21307
|
+
};
|
|
21308
|
+
session.onpaymentmethodselected = event => {
|
|
21309
|
+
console.log("payment method selected step", event);
|
|
21310
|
+
// Define ApplePayPaymentMethodUpdate based on the selected payment method.
|
|
21311
|
+
// No updates or errors are needed, pass an empty object.
|
|
21312
|
+
const newTotal = {
|
|
21313
|
+
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
21314
|
+
type: "final",
|
|
21315
|
+
amount: updatedPrice / 100
|
|
21316
|
+
};
|
|
21317
|
+
const newLineItems = [{
|
|
21318
|
+
label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice === null || invoice === void 0 ? void 0 : invoice.id}`,
|
|
21319
|
+
type: "final",
|
|
21320
|
+
amount: updatedPrice / 100
|
|
21321
|
+
}];
|
|
21322
|
+
session.completePaymentMethodSelection(newTotal, newLineItems);
|
|
21368
21323
|
};
|
|
21369
21324
|
|
|
21370
|
-
//
|
|
21371
|
-
|
|
21325
|
+
// TODO: Check if onshippingmethodselected it should be implemented
|
|
21326
|
+
// session.onshippingmethodselected = (event) => {
|
|
21327
|
+
// console.log("on shipping method selected step", event);
|
|
21328
|
+
// // Define ApplePayShippingMethodUpdate based on the selected shipping method.
|
|
21329
|
+
// // No updates or errors are needed, pass an empty object.
|
|
21330
|
+
// const newTotal = {
|
|
21331
|
+
// label: plan?.nickname || orderLabel || `invoice #${invoice?.id}`,
|
|
21332
|
+
// type: "final",
|
|
21333
|
+
// amount: updatedPrice / 100
|
|
21334
|
+
// };
|
|
21335
|
+
|
|
21336
|
+
// const newLineItems = [
|
|
21337
|
+
// {
|
|
21338
|
+
// label: plan?.nickname || orderLabel || `invoice #${invoice?.id}`,
|
|
21339
|
+
// type: "final",
|
|
21340
|
+
// amount: updatedPrice / 100
|
|
21341
|
+
// }
|
|
21342
|
+
// ];
|
|
21343
|
+
|
|
21344
|
+
// session.completeShippingMethodSelection(newTotal, newLineItems);
|
|
21345
|
+
// };
|
|
21346
|
+
|
|
21347
|
+
// TODO: Check if onshippingcontactselected it should be implemented
|
|
21348
|
+
// session.onshippingcontactselected = (event) => {
|
|
21349
|
+
// console.log("on shipping contact selected step", event);
|
|
21350
|
+
// // Define ApplePayShippingContactUpdate based on the selected shipping contact.
|
|
21351
|
+
// const update = {};
|
|
21352
|
+
// session.completeShippingContactSelection(update);
|
|
21353
|
+
// };
|
|
21354
|
+
|
|
21355
|
+
session.onpaymentauthorized = event => {
|
|
21356
|
+
console.log("on payment authorized step", event);
|
|
21357
|
+
// Define ApplePayPaymentAuthorizationResult
|
|
21358
|
+
const result = {
|
|
21359
|
+
status: ApplePaySession.STATUS_SUCCESS // eslint-disable-line no-undef
|
|
21360
|
+
};
|
|
21361
|
+
|
|
21362
|
+
const {
|
|
21363
|
+
paymentData
|
|
21364
|
+
} = event.payment.token;
|
|
21372
21365
|
const {
|
|
21373
|
-
|
|
21374
|
-
|
|
21375
|
-
|
|
21376
|
-
|
|
21377
|
-
const
|
|
21378
|
-
|
|
21379
|
-
|
|
21380
|
-
|
|
21381
|
-
|
|
21366
|
+
data,
|
|
21367
|
+
signature,
|
|
21368
|
+
version
|
|
21369
|
+
} = paymentData;
|
|
21370
|
+
const {
|
|
21371
|
+
ephemeralPublicKey,
|
|
21372
|
+
publicKeyHash,
|
|
21373
|
+
transactionId
|
|
21374
|
+
} = paymentData.header;
|
|
21375
|
+
const applePayToken = {
|
|
21376
|
+
data: data,
|
|
21377
|
+
signature: signature,
|
|
21378
|
+
version: version,
|
|
21379
|
+
header: {
|
|
21380
|
+
ephemeralPublicKey: ephemeralPublicKey,
|
|
21381
|
+
publicKeyHash: publicKeyHash,
|
|
21382
|
+
transactionId: transactionId
|
|
21383
|
+
}
|
|
21384
|
+
};
|
|
21385
|
+
console.log(applePayToken);
|
|
21386
|
+
const orderId = `pelcro-${new Date().getTime()}`;
|
|
21387
|
+
const eProtectRequest = {
|
|
21388
|
+
paypageId: payPageId,
|
|
21389
|
+
reportGroup: reportGroup,
|
|
21390
|
+
orderId: orderId,
|
|
21391
|
+
id: orderId,
|
|
21392
|
+
applepay: applePayToken,
|
|
21393
|
+
url: "https://request.eprotect.vantivprelive.com"
|
|
21382
21394
|
};
|
|
21383
21395
|
|
|
21384
|
-
//
|
|
21396
|
+
// successCallback function to handle the response from WorldPay.
|
|
21397
|
+
function successCallback(vantivResponse) {
|
|
21398
|
+
const {
|
|
21399
|
+
expDate
|
|
21400
|
+
} = vantivResponse;
|
|
21401
|
+
console.log("Response:", vantivResponse);
|
|
21402
|
+
const expMonth = expDate.substring(0, 2);
|
|
21403
|
+
const expYear = expDate.substring(2);
|
|
21404
|
+
const vantivPaymentRequest = {
|
|
21405
|
+
...vantivResponse,
|
|
21406
|
+
expMonth: expMonth,
|
|
21407
|
+
expYear: expYear
|
|
21408
|
+
};
|
|
21409
|
+
|
|
21410
|
+
// Process the registrationId or continue with further payment processing.
|
|
21411
|
+
dispatch({
|
|
21412
|
+
type: HANDLE_APPLEPAY_SUBSCRIPTION,
|
|
21413
|
+
payload: vantivPaymentRequest
|
|
21414
|
+
});
|
|
21415
|
+
dispatch({
|
|
21416
|
+
type: LOADING,
|
|
21417
|
+
payload: true
|
|
21418
|
+
});
|
|
21419
|
+
session.completePayment(result);
|
|
21420
|
+
}
|
|
21421
|
+
|
|
21422
|
+
// errorCallback function to handle any errors that may occur during the tokenization process.
|
|
21423
|
+
function errorCallback(error) {
|
|
21424
|
+
console.error("Error retrieving Registration ID:", error);
|
|
21425
|
+
// Handle error appropriately.
|
|
21426
|
+
}
|
|
21427
|
+
// errorCallback function to handle any errors that may occur during the tokenization process.
|
|
21428
|
+
function timeoutCallback() {
|
|
21429
|
+
console.error("eProtect Timeout");
|
|
21430
|
+
// Handle error appropriately.
|
|
21431
|
+
}
|
|
21432
|
+
|
|
21433
|
+
// eslint-disable-next-line no-undef
|
|
21434
|
+
new eProtect().sendToEprotect(eProtectRequest, {}, successCallback, errorCallback, timeoutCallback, 15000);
|
|
21435
|
+
};
|
|
21436
|
+
|
|
21437
|
+
// TODO: Check if oncouponcodechanged it should be implemented
|
|
21438
|
+
// session.oncouponcodechanged = (event) => {
|
|
21439
|
+
// console.log("on coupon code changed step", event);
|
|
21440
|
+
// // Define ApplePayCouponCodeUpdate
|
|
21441
|
+
// const newTotal = calculateNewTotal(event.couponCode);
|
|
21442
|
+
// const newLineItems = calculateNewLineItems(event.couponCode);
|
|
21443
|
+
// const newShippingMethods = calculateNewShippingMethods(
|
|
21444
|
+
// event.couponCode
|
|
21445
|
+
// );
|
|
21446
|
+
// const errors = calculateErrors(event.couponCode);
|
|
21447
|
+
|
|
21448
|
+
// session.completeCouponCodeChange({
|
|
21449
|
+
// newTotal: newTotal,
|
|
21450
|
+
// newLineItems: newLineItems,
|
|
21451
|
+
// newShippingMethods: newShippingMethods,
|
|
21452
|
+
// errors: errors
|
|
21453
|
+
// });
|
|
21454
|
+
// };
|
|
21455
|
+
|
|
21456
|
+
session.oncancel = event => {
|
|
21457
|
+
// Payment cancelled by WebKit
|
|
21458
|
+
console.log("on cancel step", event);
|
|
21385
21459
|
dispatch({
|
|
21386
|
-
type:
|
|
21387
|
-
payload:
|
|
21460
|
+
type: LOADING,
|
|
21461
|
+
payload: false
|
|
21388
21462
|
});
|
|
21389
21463
|
dispatch({
|
|
21390
|
-
type:
|
|
21391
|
-
payload:
|
|
21464
|
+
type: DISABLE_SUBMIT,
|
|
21465
|
+
payload: false
|
|
21392
21466
|
});
|
|
21393
|
-
|
|
21394
|
-
|
|
21395
|
-
|
|
21396
|
-
// errorCallback function to handle any errors that may occur during the tokenization process.
|
|
21397
|
-
function errorCallback(error) {
|
|
21398
|
-
console.error("Error retrieving Registration ID:", error);
|
|
21399
|
-
// Handle error appropriately.
|
|
21400
|
-
}
|
|
21401
|
-
// errorCallback function to handle any errors that may occur during the tokenization process.
|
|
21402
|
-
function timeoutCallback() {
|
|
21403
|
-
console.error("eProtect Timeout");
|
|
21404
|
-
// Handle error appropriately.
|
|
21405
|
-
}
|
|
21406
|
-
|
|
21407
|
-
new eProtect().sendToEprotect(eProtectRequest, {}, successCallback, errorCallback, timeoutCallback, 15000);
|
|
21408
|
-
};
|
|
21409
|
-
|
|
21410
|
-
// TODO: Check if oncouponcodechanged it should be implemented
|
|
21411
|
-
// session.oncouponcodechanged = (event) => {
|
|
21412
|
-
// console.log("on coupon code changed step", event);
|
|
21413
|
-
// // Define ApplePayCouponCodeUpdate
|
|
21414
|
-
// const newTotal = calculateNewTotal(event.couponCode);
|
|
21415
|
-
// const newLineItems = calculateNewLineItems(event.couponCode);
|
|
21416
|
-
// const newShippingMethods = calculateNewShippingMethods(
|
|
21417
|
-
// event.couponCode
|
|
21418
|
-
// );
|
|
21419
|
-
// const errors = calculateErrors(event.couponCode);
|
|
21420
|
-
|
|
21421
|
-
// session.completeCouponCodeChange({
|
|
21422
|
-
// newTotal: newTotal,
|
|
21423
|
-
// newLineItems: newLineItems,
|
|
21424
|
-
// newShippingMethods: newShippingMethods,
|
|
21425
|
-
// errors: errors
|
|
21426
|
-
// });
|
|
21427
|
-
// };
|
|
21428
|
-
|
|
21429
|
-
session.oncancel = event => {
|
|
21430
|
-
// Payment cancelled by WebKit
|
|
21431
|
-
console.log("on cancel step", event);
|
|
21432
|
-
dispatch({
|
|
21433
|
-
type: LOADING,
|
|
21434
|
-
payload: false
|
|
21435
|
-
});
|
|
21436
|
-
dispatch({
|
|
21437
|
-
type: DISABLE_SUBMIT,
|
|
21438
|
-
payload: false
|
|
21439
|
-
});
|
|
21440
|
-
};
|
|
21441
|
-
session.begin();
|
|
21442
|
-
}
|
|
21443
|
-
useEffect(() => {
|
|
21467
|
+
};
|
|
21468
|
+
session.begin();
|
|
21469
|
+
}
|
|
21444
21470
|
const pelcroApplyPayButton = document.getElementById("pelcro-apple-pay-button");
|
|
21445
21471
|
if (pelcroApplyPayButton) {
|
|
21446
21472
|
pelcroApplyPayButton.addEventListener("click", onApplePayButtonClicked);
|
|
21447
21473
|
}
|
|
21448
|
-
|
|
21474
|
+
return () => {
|
|
21475
|
+
if (pelcroApplyPayButton) {
|
|
21476
|
+
pelcroApplyPayButton.removeEventListener("click", onApplePayButtonClicked);
|
|
21477
|
+
}
|
|
21478
|
+
};
|
|
21479
|
+
}, [state.updatedPrice]);
|
|
21449
21480
|
return /*#__PURE__*/React__default.createElement("apple-pay-button", {
|
|
21450
21481
|
id: "pelcro-apple-pay-button",
|
|
21451
21482
|
style: {
|