@pelcro/react-pelcro-js 3.26.0-beta.5 → 3.26.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -11848,21 +11848,31 @@ const initPaywalls = () => {
11848
11848
  return;
11849
11849
  }
11850
11850
  const {
11851
- switchView
11851
+ switchView,
11852
+ isAuthenticated
11852
11853
  } = usePelcro.getStore();
11853
- if (paywallMethods !== null && paywallMethods !== void 0 && paywallMethods.displayMeterPaywall()) {
11854
- /*
11855
- showing both the meter and the entitlements notification doesn't make sense from
11856
- a product prespective + they would take half the screen on mobile devies, so we're
11857
- not showing the meter, and only showing the entitlements notification.
11858
- */
11859
- if (!didBlurContent) {
11860
- switchView("meter");
11854
+ function displayPaywalls() {
11855
+ if (paywallMethods !== null && paywallMethods !== void 0 && paywallMethods.displayMeterPaywall()) {
11856
+ /*
11857
+ showing both the meter and the entitlements notification doesn't make sense from
11858
+ a product prespective + they would take half the screen on mobile devies, so we're
11859
+ not showing the meter, and only showing the entitlements notification.
11860
+ */
11861
+ if (!didBlurContent) {
11862
+ switchView("meter");
11863
+ }
11864
+ } else if (paywallMethods !== null && paywallMethods !== void 0 && paywallMethods.displayNewsletterPaywall()) {
11865
+ switchView("newsletter");
11866
+ } else if (paywallMethods !== null && paywallMethods !== void 0 && paywallMethods.displayPaywall()) {
11867
+ switchView("plan-select");
11861
11868
  }
11862
- } else if (paywallMethods !== null && paywallMethods !== void 0 && paywallMethods.displayNewsletterPaywall()) {
11863
- switchView("newsletter");
11864
- } else if (paywallMethods !== null && paywallMethods !== void 0 && paywallMethods.displayPaywall()) {
11865
- switchView("plan-select");
11869
+ }
11870
+ if (isAuthenticated()) {
11871
+ addEventListener("PelcroUserLoaded", function () {
11872
+ displayPaywalls();
11873
+ });
11874
+ } else {
11875
+ displayPaywalls();
11866
11876
  }
11867
11877
  }
11868
11878
  };
@@ -11874,6 +11884,7 @@ const loadPaymentSDKs = () => {
11874
11884
  if (!window.Stripe && !supportsVantiv && !supportsTap) {
11875
11885
  pure_1(window.Pelcro.environment.stripe);
11876
11886
  }
11887
+ window.Pelcro.helpers.loadSDK("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js", "apple-pay-sdk");
11877
11888
 
11878
11889
  // Load PayPal SDKs
11879
11890
  const supportsPaypal = Boolean(window.Pelcro.site.read().braintree_tokenization);
@@ -11887,6 +11898,8 @@ const loadPaymentSDKs = () => {
11887
11898
  if (!window.jQuery) {
11888
11899
  window.Pelcro.helpers.loadSDK("https://code.jquery.com/jquery-3.6.0.slim.min.js", "vantiv-jquery-sdk");
11889
11900
  }
11901
+ window.Pelcro.helpers.loadSDK("https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "vantiv-jquery-sdk");
11902
+ window.Pelcro.helpers.loadSDK("https://request.eprotect.vantivprelive.com/eProtect/eProtect-api3.js", "vantiv-eprotect-api");
11890
11903
  if (!window.EprotectIframeClient) {
11891
11904
  const PRELIVE_URL = "https://request.eprotect.vantivprelive.com/eProtect/js/eProtect-iframe-client.min.js";
11892
11905
  const PRODUCTION_URL = "https://request.eprotect.vantivcnp.com/eProtect/js/eProtect-iframe-client3.min.js";
@@ -12758,6 +12771,7 @@ const LOADING = "LOADING";
12758
12771
  const SUBMIT_PAYMENT = "SUBMIT_PAYMENT";
12759
12772
  const SUBSCRIBE = "CREATE_SUBSCRIPTION";
12760
12773
  const HANDLE_PAYPAL_SUBSCRIPTION = "HANDLE_PAYPAL_SUBSCRIPTION";
12774
+ const HANDLE_APPLEPAY_SUBSCRIPTION = "HANDLE_APPLEPAY_SUBSCRIPTION";
12761
12775
  const DISABLE_COUPON_BUTTON = "DISABLE_COUPON_BUTTON";
12762
12776
  const APPLY_COUPON_CODE = "APPLY_COUPON_CODE";
12763
12777
  const REMOVE_APPLIED_COUPON = "REMOVE_APPLIED_COUPON";
@@ -18132,7 +18146,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18132
18146
  });
18133
18147
  };
18134
18148
 
18135
- /*====== Start Cybersource integration ========*/
18149
+ /* ====== Start Cybersource integration ======== */
18136
18150
  const cybersourceErrorHandle = err => {
18137
18151
  var _err$details, _err$details$response, _err$details$response2;
18138
18152
  if ((err === null || err === void 0 ? void 0 : (_err$details = err.details) === null || _err$details === void 0 ? void 0 : (_err$details$response = _err$details.responseStatus) === null || _err$details$response === void 0 ? void 0 : (_err$details$response2 = _err$details$response.details) === null || _err$details$response2 === void 0 ? void 0 : _err$details$response2.length) > 0) {
@@ -18401,9 +18415,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18401
18415
  });
18402
18416
  };
18403
18417
 
18404
- /*====== End Cybersource integration ========*/
18418
+ /* ====== End Cybersource integration ======== */
18405
18419
 
18406
- /*====== Start Tap integration ========*/
18420
+ /* ====== Start Tap integration ======== */
18407
18421
  const submitUsingTap = state => {
18408
18422
  var _ref4, _ref5, _getPlanAmount;
18409
18423
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
@@ -18675,28 +18689,28 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18675
18689
  cardHolder: "Card Holder Name"
18676
18690
  };
18677
18691
 
18678
- //payment options
18692
+ // payment options
18679
18693
  let paymentOptions = {
18680
18694
  labels: labels,
18681
18695
  TextDirection: "ltr"
18682
18696
  };
18683
18697
 
18684
- //create element, pass style and payment options
18698
+ // create element, pass style and payment options
18685
18699
  let card = elements.create("card", {
18686
18700
  style: style
18687
18701
  }, paymentOptions);
18688
18702
 
18689
- //mount element
18703
+ // mount element
18690
18704
  card.mount("#tapPaymentIframe");
18691
18705
 
18692
- //card change event listener
18706
+ // card change event listener
18693
18707
  card.addEventListener("change", function (event) {
18694
- //If needed
18708
+ // If needed
18695
18709
  });
18696
18710
  tapInstanceRef.current = tapKey;
18697
18711
  tapInstanceCard.current = card;
18698
18712
  };
18699
- /*====== End Tap integration ========*/
18713
+ /* ====== End Tap integration ======== */
18700
18714
 
18701
18715
  const submitUsingVantiv = state => {
18702
18716
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
@@ -18884,7 +18898,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18884
18898
  }
18885
18899
  }, [selectedPaymentMethodId]);
18886
18900
 
18887
- //Trigger the handleVantivPayment method when a vantivePaymentRequest is present
18901
+ // Trigger the handleVantivPayment method when a vantivPaymentRequest is present
18888
18902
  React.useEffect(() => {
18889
18903
  if (vantivPaymentRequest) {
18890
18904
  handleVantivPayment(vantivPaymentRequest, updatedCouponCode);
@@ -19044,7 +19058,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19044
19058
  if (err) {
19045
19059
  onFailure(err);
19046
19060
 
19047
- //reset the coupon code in local state
19061
+ // reset the coupon code in local state
19048
19062
  setUpdatedCouponCode("");
19049
19063
  dispatch({
19050
19064
  type: SET_COUPON_ERROR,
@@ -19105,7 +19119,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19105
19119
  payload: res.data.coupon
19106
19120
  });
19107
19121
 
19108
- //set the coupon code in local state to be able to use with Vantiv
19122
+ // set the coupon code in local state to be able to use with Vantiv
19109
19123
  setUpdatedCouponCode(res.data.coupon.code);
19110
19124
  dispatch({
19111
19125
  type: SET_PERCENT_OFF,
@@ -19178,7 +19192,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19178
19192
  const removeAppliedCoupon = state => {
19179
19193
  state.couponCode = "";
19180
19194
 
19181
- //reset the coupon code in local state
19195
+ // reset the coupon code in local state
19182
19196
  setUpdatedCouponCode("");
19183
19197
  dispatch({
19184
19198
  type: SET_COUPON_ERROR,
@@ -19999,6 +20013,10 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19999
20013
  handlePaypalSubscription(state, action.payload);
20000
20014
  }
20001
20015
  });
20016
+ case HANDLE_APPLEPAY_SUBSCRIPTION:
20017
+ return lib_5(state, (state, dispatch) => {
20018
+ setVantivPaymentRequest(action.payload);
20019
+ });
20002
20020
  case SET_UPDATED_PRICE:
20003
20021
  return lib_7({
20004
20022
  ...state,
@@ -21140,6 +21158,328 @@ const DonationEmail = props => /*#__PURE__*/React__default['default'].createElem
21140
21158
  store: store$k
21141
21159
  }, props));
21142
21160
 
21161
+ /* eslint-disable no-undef */
21162
+
21163
+ /**
21164
+ * ApplePayButton component
21165
+ * @return {JSX}
21166
+ */
21167
+ const ApplePayButton = _ref => {
21168
+ var _ref2, _ref3, _state$updatedPrice, _props$plan;
21169
+ let {
21170
+ onClick,
21171
+ props,
21172
+ ...otherProps
21173
+ } = _ref;
21174
+ const {
21175
+ dispatch,
21176
+ state
21177
+ } = React.useContext(store$k);
21178
+ const {
21179
+ plan,
21180
+ invoice
21181
+ } = usePelcro();
21182
+ const updatedPrice = (_ref2 = (_ref3 = (_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 && _ref3 !== void 0 ? _ref3 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref2 !== void 0 ? _ref2 : invoice.amount_remaining;
21183
+ React.useEffect(() => {
21184
+ if (window.ApplePaySession) {
21185
+ // TODO: Should not be hardcoded
21186
+ const merchantIdentifier = "merchant.pelcro.prelive";
21187
+
21188
+ // Indicates whether the device supports Apple Pay and whether the user has an active card in Wallet.
21189
+ const promise = ApplePaySession.canMakePaymentsWithActiveCard(merchantIdentifier);
21190
+ promise.then(function (canMakePayments) {
21191
+ if (canMakePayments) {
21192
+ // Display Apple Pay Buttons here…
21193
+ const pelcroApplyPayButton = document.getElementById("pelcro-apple-pay-button");
21194
+ if (pelcroApplyPayButton) {
21195
+ pelcroApplyPayButton.style.display = "block";
21196
+ }
21197
+ console.log("canMakePayments", canMakePayments);
21198
+ }
21199
+ });
21200
+ } else {
21201
+ console.error("ApplePay is not available on this browser");
21202
+ }
21203
+ }, []);
21204
+ function onApplePayButtonClicked() {
21205
+ var _window, _window$Pelcro, _window$Pelcro$user, _window$Pelcro$user$l;
21206
+ if (!ApplePaySession) {
21207
+ return;
21208
+ }
21209
+ dispatch({
21210
+ type: DISABLE_SUBMIT,
21211
+ payload: true
21212
+ });
21213
+
21214
+ // Define ApplePayPaymentRequest
21215
+ // @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session
21216
+ const ApplePayPaymentRequest = {
21217
+ 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",
21218
+ currencyCode: (plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase()) || (invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase()),
21219
+ merchantCapabilities: ["supports3DS"],
21220
+ supportedNetworks: ["visa", "masterCard", "amex", "discover"],
21221
+ total: {
21222
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21223
+ amount: updatedPrice / 100
21224
+ },
21225
+ lineItems: [plan !== null && plan !== void 0 && plan.auto_renew ? {
21226
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21227
+ amount: updatedPrice / 100,
21228
+ paymentTiming: "recurring",
21229
+ recurringPaymentStartDate: new Date().toISOString(),
21230
+ recurringPaymentIntervalUnit: plan === null || plan === void 0 ? void 0 : plan.interval,
21231
+ recurringPaymentIntervalCount: plan === null || plan === void 0 ? void 0 : plan.interval_count
21232
+ } : {
21233
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21234
+ amount: updatedPrice / 100
21235
+ }],
21236
+ ...((plan === null || plan === void 0 ? void 0 : plan.auto_renew) && {
21237
+ recurringPaymentRequest: {
21238
+ paymentDescription: "A description of the recurring payment to display to the user in the payment sheet.",
21239
+ regularBilling: {
21240
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21241
+ amount: updatedPrice / 100,
21242
+ paymentTiming: "recurring",
21243
+ recurringPaymentStartDate: new Date().toISOString(),
21244
+ recurringPaymentIntervalUnit: plan === null || plan === void 0 ? void 0 : plan.interval,
21245
+ recurringPaymentIntervalCount: plan === null || plan === void 0 ? void 0 : plan.interval_count
21246
+ },
21247
+ billingAgreement: "A localized billing agreement displayed to the user in the payment sheet prior to the payment authorization.",
21248
+ managementURL: "https://applepaydemo.apple.com",
21249
+ tokenNotificationURL: "https://applepaydemo.apple.com"
21250
+ }
21251
+ })
21252
+ };
21253
+
21254
+ // Create ApplePaySession
21255
+ // @todo - Clarify supported version parameter
21256
+ // @odo - Apple Pay demo uses version 6 (https://applepaydemo.apple.com/)
21257
+ const session = new ApplePaySession(3, ApplePayPaymentRequest);
21258
+
21259
+ // @todo - Detect whether web browser supports a particular Apple Pay version.
21260
+ // @see https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778014-supportsversion
21261
+
21262
+ session.onvalidatemerchant = async event => {
21263
+ const {
21264
+ validationURL
21265
+ } = event;
21266
+ console.log("then merchantSession step", event);
21267
+ // Call your own server to request a new merchant session.
21268
+ window.Pelcro.payment.startSession({
21269
+ auth_token: window.Pelcro.user.read().auth_token,
21270
+ site_id: window.Pelcro.siteid,
21271
+ validation_url: validationURL
21272
+ }, (err, res) => {
21273
+ if (err) {
21274
+ // Handle any errors during merchant validation
21275
+ console.error("Merchant validation SDK error: ", err);
21276
+ session.abort();
21277
+ return dispatch({
21278
+ type: SHOW_ALERT,
21279
+ payload: {
21280
+ type: "error",
21281
+ content: getErrorMessages(err)
21282
+ }
21283
+ });
21284
+ }
21285
+ // Complete merchant validation with the merchant session object
21286
+ console.log("Merchant validation SDK response: ", res);
21287
+ const merchantSession = res;
21288
+ session.completeMerchantValidation(merchantSession);
21289
+ });
21290
+ };
21291
+ session.onpaymentmethodselected = event => {
21292
+ console.log("payment method selected step", event);
21293
+ // Define ApplePayPaymentMethodUpdate based on the selected payment method.
21294
+ // No updates or errors are needed, pass an empty object.
21295
+ const newTotal = {
21296
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21297
+ amount: updatedPrice / 100
21298
+ };
21299
+ const newLineItems = [plan !== null && plan !== void 0 && plan.auto_renew ? {
21300
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21301
+ amount: updatedPrice / 100,
21302
+ paymentTiming: "recurring",
21303
+ recurringPaymentStartDate: new Date().toISOString(),
21304
+ recurringPaymentIntervalUnit: plan === null || plan === void 0 ? void 0 : plan.interval,
21305
+ recurringPaymentIntervalCount: plan === null || plan === void 0 ? void 0 : plan.interval_count
21306
+ } : {
21307
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21308
+ amount: updatedPrice / 100
21309
+ }];
21310
+ session.completePaymentMethodSelection(newTotal, newLineItems);
21311
+ };
21312
+
21313
+ // TODO: Check if onshippingmethodselected it should be implemented
21314
+ // session.onshippingmethodselected = (event) => {
21315
+ // console.log("on shipping method selected step", event);
21316
+ // // Define ApplePayShippingMethodUpdate based on the selected shipping method.
21317
+ // // No updates or errors are needed, pass an empty object.
21318
+ // const newTotal = {
21319
+ // label: plan?.nickname || `invoice #${invoice.id}`,
21320
+ // amount: updatedPrice / 100
21321
+ // };
21322
+
21323
+ // const newLineItems = [
21324
+ // plan?.auto_renew
21325
+ // ? {
21326
+ // label: plan?.nickname || `invoice #${invoice.id}`,
21327
+ // amount: updatedPrice / 100,
21328
+ // paymentTiming: "recurring",
21329
+ // recurringPaymentStartDate: new Date().toISOString(),
21330
+ // recurringPaymentIntervalUnit: plan?.interval,
21331
+ // recurringPaymentIntervalCount: plan?.interval_count
21332
+ // }
21333
+ // : {
21334
+ // label: plan?.nickname || `invoice #${invoice.id}`,
21335
+ // amount: updatedPrice / 100
21336
+ // }
21337
+ // ];
21338
+
21339
+ // session.completeShippingMethodSelection(newTotal, newLineItems);
21340
+ // };
21341
+
21342
+ // TODO: Check if onshippingcontactselected it should be implemented
21343
+ // session.onshippingcontactselected = (event) => {
21344
+ // console.log("on shipping contact selected step", event);
21345
+ // // Define ApplePayShippingContactUpdate based on the selected shipping contact.
21346
+ // const update = {};
21347
+ // session.completeShippingContactSelection(update);
21348
+ // };
21349
+
21350
+ session.onpaymentauthorized = event => {
21351
+ var _window$Pelcro$site$r, _window$Pelcro$site$r2;
21352
+ console.log("on payment authorized step", event);
21353
+ // Define ApplePayPaymentAuthorizationResult
21354
+ const result = {
21355
+ status: ApplePaySession.STATUS_SUCCESS
21356
+ };
21357
+ const {
21358
+ paymentData
21359
+ } = event.payment.token;
21360
+ const {
21361
+ data,
21362
+ signature,
21363
+ version
21364
+ } = paymentData;
21365
+ const {
21366
+ ephemeralPublicKey,
21367
+ publicKeyHash,
21368
+ transactionId
21369
+ } = paymentData.header;
21370
+ const applePayToken = {
21371
+ data: data,
21372
+ signature: signature,
21373
+ version: version,
21374
+ header: {
21375
+ ephemeralPublicKey: ephemeralPublicKey,
21376
+ publicKeyHash: publicKeyHash,
21377
+ transactionId: transactionId
21378
+ }
21379
+ };
21380
+ console.log(applePayToken);
21381
+ const payPageId = (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.vantiv_gateway_settings.pay_page_id;
21382
+ const reportGroup = (_window$Pelcro$site$r2 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : _window$Pelcro$site$r2.vantiv_gateway_settings.report_group;
21383
+ const orderId = `pelcro-${new Date().getTime()}`;
21384
+ const eProtectRequest = {
21385
+ paypageId: payPageId,
21386
+ reportGroup: reportGroup,
21387
+ orderId: orderId,
21388
+ id: orderId,
21389
+ applepay: applePayToken,
21390
+ url: "https://request.eprotect.vantivprelive.com"
21391
+ };
21392
+
21393
+ // successCallback function to handle the response from WorldPay.
21394
+ function successCallback(vantivResponse) {
21395
+ const {
21396
+ expDate
21397
+ } = vantivResponse;
21398
+ console.log("Response:", vantivResponse);
21399
+ const expMonth = expDate.substring(0, 2);
21400
+ const expYear = expDate.substring(2);
21401
+ const vantivPaymentRequest = {
21402
+ ...vantivResponse,
21403
+ expMonth: expMonth,
21404
+ expYear: expYear
21405
+ };
21406
+
21407
+ // Process the registrationId or continue with further payment processing.
21408
+ dispatch({
21409
+ type: HANDLE_APPLEPAY_SUBSCRIPTION,
21410
+ payload: vantivPaymentRequest
21411
+ });
21412
+ dispatch({
21413
+ type: LOADING,
21414
+ payload: true
21415
+ });
21416
+ session.completePayment(result);
21417
+ }
21418
+
21419
+ // errorCallback function to handle any errors that may occur during the tokenization process.
21420
+ function errorCallback(error) {
21421
+ console.error("Error retrieving Registration ID:", error);
21422
+ // Handle error appropriately.
21423
+ }
21424
+ // errorCallback function to handle any errors that may occur during the tokenization process.
21425
+ function timeoutCallback() {
21426
+ console.error("eProtect Timeout");
21427
+ // Handle error appropriately.
21428
+ }
21429
+
21430
+ new eProtect().sendToEprotect(eProtectRequest, {}, successCallback, errorCallback, timeoutCallback, 15000);
21431
+ };
21432
+
21433
+ // TODO: Check if oncouponcodechanged it should be implemented
21434
+ // session.oncouponcodechanged = (event) => {
21435
+ // console.log("on coupon code changed step", event);
21436
+ // // Define ApplePayCouponCodeUpdate
21437
+ // const newTotal = calculateNewTotal(event.couponCode);
21438
+ // const newLineItems = calculateNewLineItems(event.couponCode);
21439
+ // const newShippingMethods = calculateNewShippingMethods(
21440
+ // event.couponCode
21441
+ // );
21442
+ // const errors = calculateErrors(event.couponCode);
21443
+
21444
+ // session.completeCouponCodeChange({
21445
+ // newTotal: newTotal,
21446
+ // newLineItems: newLineItems,
21447
+ // newShippingMethods: newShippingMethods,
21448
+ // errors: errors
21449
+ // });
21450
+ // };
21451
+
21452
+ session.oncancel = event => {
21453
+ // Payment cancelled by WebKit
21454
+ console.log("on cancel step", event);
21455
+ dispatch({
21456
+ type: LOADING,
21457
+ payload: false
21458
+ });
21459
+ dispatch({
21460
+ type: DISABLE_SUBMIT,
21461
+ payload: false
21462
+ });
21463
+ };
21464
+ session.begin();
21465
+ }
21466
+ React.useEffect(() => {
21467
+ const pelcroApplyPayButton = document.getElementById("pelcro-apple-pay-button");
21468
+ if (pelcroApplyPayButton) {
21469
+ pelcroApplyPayButton.addEventListener("click", onApplePayButtonClicked);
21470
+ }
21471
+ }, []);
21472
+ return /*#__PURE__*/React__default['default'].createElement("apple-pay-button", {
21473
+ id: "pelcro-apple-pay-button",
21474
+ style: {
21475
+ display: "none"
21476
+ },
21477
+ buttonstyle: "black",
21478
+ type: "plain",
21479
+ locale: "en-US"
21480
+ });
21481
+ };
21482
+
21143
21483
  /**
21144
21484
  *
21145
21485
  */
@@ -21230,7 +21570,7 @@ function PaymentMethodView(_ref) {
21230
21570
  className: "plc-mb-2"
21231
21571
  }, /*#__PURE__*/React__default['default'].createElement(CouponCode, null), /*#__PURE__*/React__default['default'].createElement(DiscountedPrice, null)), /*#__PURE__*/React__default['default'].createElement(TaxAmount, null), /*#__PURE__*/React__default['default'].createElement("div", {
21232
21572
  className: "plc-grid plc-mt-4 plc-gap-y-2"
21233
- }, /*#__PURE__*/React__default['default'].createElement(SubmitPaymentMethod, null), showExternalPaymentMethods && !supportsVantiv && !supportsCybersource && !supportsTap ? /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement(PelcroPaymentRequestButton, null), /*#__PURE__*/React__default['default'].createElement(PaypalSubscribeButton, null)) : showExternalPaymentMethods && supportsVantiv ? /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement(PaypalSubscribeButton, null)) : null)))));
21573
+ }, /*#__PURE__*/React__default['default'].createElement(SubmitPaymentMethod, null), showExternalPaymentMethods && !supportsVantiv && !supportsCybersource && !supportsTap ? /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement(PelcroPaymentRequestButton, null), /*#__PURE__*/React__default['default'].createElement(PaypalSubscribeButton, null)) : showExternalPaymentMethods && supportsVantiv ? /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement(ApplePayButton, null), /*#__PURE__*/React__default['default'].createElement(PaypalSubscribeButton, null)) : null)))));
21234
21574
  }
21235
21575
 
21236
21576
  const SubscriptionRenewView = _ref => {
package/dist/index.esm.js CHANGED
@@ -11818,21 +11818,31 @@ const initPaywalls = () => {
11818
11818
  return;
11819
11819
  }
11820
11820
  const {
11821
- switchView
11821
+ switchView,
11822
+ isAuthenticated
11822
11823
  } = usePelcro.getStore();
11823
- if (paywallMethods !== null && paywallMethods !== void 0 && paywallMethods.displayMeterPaywall()) {
11824
- /*
11825
- showing both the meter and the entitlements notification doesn't make sense from
11826
- a product prespective + they would take half the screen on mobile devies, so we're
11827
- not showing the meter, and only showing the entitlements notification.
11828
- */
11829
- if (!didBlurContent) {
11830
- switchView("meter");
11824
+ function displayPaywalls() {
11825
+ if (paywallMethods !== null && paywallMethods !== void 0 && paywallMethods.displayMeterPaywall()) {
11826
+ /*
11827
+ showing both the meter and the entitlements notification doesn't make sense from
11828
+ a product prespective + they would take half the screen on mobile devies, so we're
11829
+ not showing the meter, and only showing the entitlements notification.
11830
+ */
11831
+ if (!didBlurContent) {
11832
+ switchView("meter");
11833
+ }
11834
+ } else if (paywallMethods !== null && paywallMethods !== void 0 && paywallMethods.displayNewsletterPaywall()) {
11835
+ switchView("newsletter");
11836
+ } else if (paywallMethods !== null && paywallMethods !== void 0 && paywallMethods.displayPaywall()) {
11837
+ switchView("plan-select");
11831
11838
  }
11832
- } else if (paywallMethods !== null && paywallMethods !== void 0 && paywallMethods.displayNewsletterPaywall()) {
11833
- switchView("newsletter");
11834
- } else if (paywallMethods !== null && paywallMethods !== void 0 && paywallMethods.displayPaywall()) {
11835
- switchView("plan-select");
11839
+ }
11840
+ if (isAuthenticated()) {
11841
+ addEventListener("PelcroUserLoaded", function () {
11842
+ displayPaywalls();
11843
+ });
11844
+ } else {
11845
+ displayPaywalls();
11836
11846
  }
11837
11847
  }
11838
11848
  };
@@ -11844,6 +11854,7 @@ const loadPaymentSDKs = () => {
11844
11854
  if (!window.Stripe && !supportsVantiv && !supportsTap) {
11845
11855
  pure_1(window.Pelcro.environment.stripe);
11846
11856
  }
11857
+ window.Pelcro.helpers.loadSDK("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js", "apple-pay-sdk");
11847
11858
 
11848
11859
  // Load PayPal SDKs
11849
11860
  const supportsPaypal = Boolean(window.Pelcro.site.read().braintree_tokenization);
@@ -11857,6 +11868,8 @@ const loadPaymentSDKs = () => {
11857
11868
  if (!window.jQuery) {
11858
11869
  window.Pelcro.helpers.loadSDK("https://code.jquery.com/jquery-3.6.0.slim.min.js", "vantiv-jquery-sdk");
11859
11870
  }
11871
+ window.Pelcro.helpers.loadSDK("https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "vantiv-jquery-sdk");
11872
+ window.Pelcro.helpers.loadSDK("https://request.eprotect.vantivprelive.com/eProtect/eProtect-api3.js", "vantiv-eprotect-api");
11860
11873
  if (!window.EprotectIframeClient) {
11861
11874
  const PRELIVE_URL = "https://request.eprotect.vantivprelive.com/eProtect/js/eProtect-iframe-client.min.js";
11862
11875
  const PRODUCTION_URL = "https://request.eprotect.vantivcnp.com/eProtect/js/eProtect-iframe-client3.min.js";
@@ -12728,6 +12741,7 @@ const LOADING = "LOADING";
12728
12741
  const SUBMIT_PAYMENT = "SUBMIT_PAYMENT";
12729
12742
  const SUBSCRIBE = "CREATE_SUBSCRIPTION";
12730
12743
  const HANDLE_PAYPAL_SUBSCRIPTION = "HANDLE_PAYPAL_SUBSCRIPTION";
12744
+ const HANDLE_APPLEPAY_SUBSCRIPTION = "HANDLE_APPLEPAY_SUBSCRIPTION";
12731
12745
  const DISABLE_COUPON_BUTTON = "DISABLE_COUPON_BUTTON";
12732
12746
  const APPLY_COUPON_CODE = "APPLY_COUPON_CODE";
12733
12747
  const REMOVE_APPLIED_COUPON = "REMOVE_APPLIED_COUPON";
@@ -18102,7 +18116,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18102
18116
  });
18103
18117
  };
18104
18118
 
18105
- /*====== Start Cybersource integration ========*/
18119
+ /* ====== Start Cybersource integration ======== */
18106
18120
  const cybersourceErrorHandle = err => {
18107
18121
  var _err$details, _err$details$response, _err$details$response2;
18108
18122
  if ((err === null || err === void 0 ? void 0 : (_err$details = err.details) === null || _err$details === void 0 ? void 0 : (_err$details$response = _err$details.responseStatus) === null || _err$details$response === void 0 ? void 0 : (_err$details$response2 = _err$details$response.details) === null || _err$details$response2 === void 0 ? void 0 : _err$details$response2.length) > 0) {
@@ -18371,9 +18385,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18371
18385
  });
18372
18386
  };
18373
18387
 
18374
- /*====== End Cybersource integration ========*/
18388
+ /* ====== End Cybersource integration ======== */
18375
18389
 
18376
- /*====== Start Tap integration ========*/
18390
+ /* ====== Start Tap integration ======== */
18377
18391
  const submitUsingTap = state => {
18378
18392
  var _ref4, _ref5, _getPlanAmount;
18379
18393
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
@@ -18645,28 +18659,28 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18645
18659
  cardHolder: "Card Holder Name"
18646
18660
  };
18647
18661
 
18648
- //payment options
18662
+ // payment options
18649
18663
  let paymentOptions = {
18650
18664
  labels: labels,
18651
18665
  TextDirection: "ltr"
18652
18666
  };
18653
18667
 
18654
- //create element, pass style and payment options
18668
+ // create element, pass style and payment options
18655
18669
  let card = elements.create("card", {
18656
18670
  style: style
18657
18671
  }, paymentOptions);
18658
18672
 
18659
- //mount element
18673
+ // mount element
18660
18674
  card.mount("#tapPaymentIframe");
18661
18675
 
18662
- //card change event listener
18676
+ // card change event listener
18663
18677
  card.addEventListener("change", function (event) {
18664
- //If needed
18678
+ // If needed
18665
18679
  });
18666
18680
  tapInstanceRef.current = tapKey;
18667
18681
  tapInstanceCard.current = card;
18668
18682
  };
18669
- /*====== End Tap integration ========*/
18683
+ /* ====== End Tap integration ======== */
18670
18684
 
18671
18685
  const submitUsingVantiv = state => {
18672
18686
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
@@ -18854,7 +18868,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18854
18868
  }
18855
18869
  }, [selectedPaymentMethodId]);
18856
18870
 
18857
- //Trigger the handleVantivPayment method when a vantivePaymentRequest is present
18871
+ // Trigger the handleVantivPayment method when a vantivPaymentRequest is present
18858
18872
  useEffect(() => {
18859
18873
  if (vantivPaymentRequest) {
18860
18874
  handleVantivPayment(vantivPaymentRequest, updatedCouponCode);
@@ -19014,7 +19028,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19014
19028
  if (err) {
19015
19029
  onFailure(err);
19016
19030
 
19017
- //reset the coupon code in local state
19031
+ // reset the coupon code in local state
19018
19032
  setUpdatedCouponCode("");
19019
19033
  dispatch({
19020
19034
  type: SET_COUPON_ERROR,
@@ -19075,7 +19089,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19075
19089
  payload: res.data.coupon
19076
19090
  });
19077
19091
 
19078
- //set the coupon code in local state to be able to use with Vantiv
19092
+ // set the coupon code in local state to be able to use with Vantiv
19079
19093
  setUpdatedCouponCode(res.data.coupon.code);
19080
19094
  dispatch({
19081
19095
  type: SET_PERCENT_OFF,
@@ -19148,7 +19162,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19148
19162
  const removeAppliedCoupon = state => {
19149
19163
  state.couponCode = "";
19150
19164
 
19151
- //reset the coupon code in local state
19165
+ // reset the coupon code in local state
19152
19166
  setUpdatedCouponCode("");
19153
19167
  dispatch({
19154
19168
  type: SET_COUPON_ERROR,
@@ -19969,6 +19983,10 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19969
19983
  handlePaypalSubscription(state, action.payload);
19970
19984
  }
19971
19985
  });
19986
+ case HANDLE_APPLEPAY_SUBSCRIPTION:
19987
+ return lib_5(state, (state, dispatch) => {
19988
+ setVantivPaymentRequest(action.payload);
19989
+ });
19972
19990
  case SET_UPDATED_PRICE:
19973
19991
  return lib_7({
19974
19992
  ...state,
@@ -21110,6 +21128,328 @@ const DonationEmail = props => /*#__PURE__*/React__default.createElement(Email,
21110
21128
  store: store$k
21111
21129
  }, props));
21112
21130
 
21131
+ /* eslint-disable no-undef */
21132
+
21133
+ /**
21134
+ * ApplePayButton component
21135
+ * @return {JSX}
21136
+ */
21137
+ const ApplePayButton = _ref => {
21138
+ var _ref2, _ref3, _state$updatedPrice, _props$plan;
21139
+ let {
21140
+ onClick,
21141
+ props,
21142
+ ...otherProps
21143
+ } = _ref;
21144
+ const {
21145
+ dispatch,
21146
+ state
21147
+ } = useContext(store$k);
21148
+ const {
21149
+ plan,
21150
+ invoice
21151
+ } = usePelcro();
21152
+ const updatedPrice = (_ref2 = (_ref3 = (_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 && _ref3 !== void 0 ? _ref3 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref2 !== void 0 ? _ref2 : invoice.amount_remaining;
21153
+ useEffect(() => {
21154
+ if (window.ApplePaySession) {
21155
+ // TODO: Should not be hardcoded
21156
+ const merchantIdentifier = "merchant.pelcro.prelive";
21157
+
21158
+ // Indicates whether the device supports Apple Pay and whether the user has an active card in Wallet.
21159
+ const promise = ApplePaySession.canMakePaymentsWithActiveCard(merchantIdentifier);
21160
+ promise.then(function (canMakePayments) {
21161
+ if (canMakePayments) {
21162
+ // Display Apple Pay Buttons here…
21163
+ const pelcroApplyPayButton = document.getElementById("pelcro-apple-pay-button");
21164
+ if (pelcroApplyPayButton) {
21165
+ pelcroApplyPayButton.style.display = "block";
21166
+ }
21167
+ console.log("canMakePayments", canMakePayments);
21168
+ }
21169
+ });
21170
+ } else {
21171
+ console.error("ApplePay is not available on this browser");
21172
+ }
21173
+ }, []);
21174
+ function onApplePayButtonClicked() {
21175
+ var _window, _window$Pelcro, _window$Pelcro$user, _window$Pelcro$user$l;
21176
+ if (!ApplePaySession) {
21177
+ return;
21178
+ }
21179
+ dispatch({
21180
+ type: DISABLE_SUBMIT,
21181
+ payload: true
21182
+ });
21183
+
21184
+ // Define ApplePayPaymentRequest
21185
+ // @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session
21186
+ const ApplePayPaymentRequest = {
21187
+ 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",
21188
+ currencyCode: (plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase()) || (invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase()),
21189
+ merchantCapabilities: ["supports3DS"],
21190
+ supportedNetworks: ["visa", "masterCard", "amex", "discover"],
21191
+ total: {
21192
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21193
+ amount: updatedPrice / 100
21194
+ },
21195
+ lineItems: [plan !== null && plan !== void 0 && plan.auto_renew ? {
21196
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21197
+ amount: updatedPrice / 100,
21198
+ paymentTiming: "recurring",
21199
+ recurringPaymentStartDate: new Date().toISOString(),
21200
+ recurringPaymentIntervalUnit: plan === null || plan === void 0 ? void 0 : plan.interval,
21201
+ recurringPaymentIntervalCount: plan === null || plan === void 0 ? void 0 : plan.interval_count
21202
+ } : {
21203
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21204
+ amount: updatedPrice / 100
21205
+ }],
21206
+ ...((plan === null || plan === void 0 ? void 0 : plan.auto_renew) && {
21207
+ recurringPaymentRequest: {
21208
+ paymentDescription: "A description of the recurring payment to display to the user in the payment sheet.",
21209
+ regularBilling: {
21210
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21211
+ amount: updatedPrice / 100,
21212
+ paymentTiming: "recurring",
21213
+ recurringPaymentStartDate: new Date().toISOString(),
21214
+ recurringPaymentIntervalUnit: plan === null || plan === void 0 ? void 0 : plan.interval,
21215
+ recurringPaymentIntervalCount: plan === null || plan === void 0 ? void 0 : plan.interval_count
21216
+ },
21217
+ billingAgreement: "A localized billing agreement displayed to the user in the payment sheet prior to the payment authorization.",
21218
+ managementURL: "https://applepaydemo.apple.com",
21219
+ tokenNotificationURL: "https://applepaydemo.apple.com"
21220
+ }
21221
+ })
21222
+ };
21223
+
21224
+ // Create ApplePaySession
21225
+ // @todo - Clarify supported version parameter
21226
+ // @odo - Apple Pay demo uses version 6 (https://applepaydemo.apple.com/)
21227
+ const session = new ApplePaySession(3, ApplePayPaymentRequest);
21228
+
21229
+ // @todo - Detect whether web browser supports a particular Apple Pay version.
21230
+ // @see https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778014-supportsversion
21231
+
21232
+ session.onvalidatemerchant = async event => {
21233
+ const {
21234
+ validationURL
21235
+ } = event;
21236
+ console.log("then merchantSession step", event);
21237
+ // Call your own server to request a new merchant session.
21238
+ window.Pelcro.payment.startSession({
21239
+ auth_token: window.Pelcro.user.read().auth_token,
21240
+ site_id: window.Pelcro.siteid,
21241
+ validation_url: validationURL
21242
+ }, (err, res) => {
21243
+ if (err) {
21244
+ // Handle any errors during merchant validation
21245
+ console.error("Merchant validation SDK error: ", err);
21246
+ session.abort();
21247
+ return dispatch({
21248
+ type: SHOW_ALERT,
21249
+ payload: {
21250
+ type: "error",
21251
+ content: getErrorMessages(err)
21252
+ }
21253
+ });
21254
+ }
21255
+ // Complete merchant validation with the merchant session object
21256
+ console.log("Merchant validation SDK response: ", res);
21257
+ const merchantSession = res;
21258
+ session.completeMerchantValidation(merchantSession);
21259
+ });
21260
+ };
21261
+ session.onpaymentmethodselected = event => {
21262
+ console.log("payment method selected step", event);
21263
+ // Define ApplePayPaymentMethodUpdate based on the selected payment method.
21264
+ // No updates or errors are needed, pass an empty object.
21265
+ const newTotal = {
21266
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21267
+ amount: updatedPrice / 100
21268
+ };
21269
+ const newLineItems = [plan !== null && plan !== void 0 && plan.auto_renew ? {
21270
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21271
+ amount: updatedPrice / 100,
21272
+ paymentTiming: "recurring",
21273
+ recurringPaymentStartDate: new Date().toISOString(),
21274
+ recurringPaymentIntervalUnit: plan === null || plan === void 0 ? void 0 : plan.interval,
21275
+ recurringPaymentIntervalCount: plan === null || plan === void 0 ? void 0 : plan.interval_count
21276
+ } : {
21277
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21278
+ amount: updatedPrice / 100
21279
+ }];
21280
+ session.completePaymentMethodSelection(newTotal, newLineItems);
21281
+ };
21282
+
21283
+ // TODO: Check if onshippingmethodselected it should be implemented
21284
+ // session.onshippingmethodselected = (event) => {
21285
+ // console.log("on shipping method selected step", event);
21286
+ // // Define ApplePayShippingMethodUpdate based on the selected shipping method.
21287
+ // // No updates or errors are needed, pass an empty object.
21288
+ // const newTotal = {
21289
+ // label: plan?.nickname || `invoice #${invoice.id}`,
21290
+ // amount: updatedPrice / 100
21291
+ // };
21292
+
21293
+ // const newLineItems = [
21294
+ // plan?.auto_renew
21295
+ // ? {
21296
+ // label: plan?.nickname || `invoice #${invoice.id}`,
21297
+ // amount: updatedPrice / 100,
21298
+ // paymentTiming: "recurring",
21299
+ // recurringPaymentStartDate: new Date().toISOString(),
21300
+ // recurringPaymentIntervalUnit: plan?.interval,
21301
+ // recurringPaymentIntervalCount: plan?.interval_count
21302
+ // }
21303
+ // : {
21304
+ // label: plan?.nickname || `invoice #${invoice.id}`,
21305
+ // amount: updatedPrice / 100
21306
+ // }
21307
+ // ];
21308
+
21309
+ // session.completeShippingMethodSelection(newTotal, newLineItems);
21310
+ // };
21311
+
21312
+ // TODO: Check if onshippingcontactselected it should be implemented
21313
+ // session.onshippingcontactselected = (event) => {
21314
+ // console.log("on shipping contact selected step", event);
21315
+ // // Define ApplePayShippingContactUpdate based on the selected shipping contact.
21316
+ // const update = {};
21317
+ // session.completeShippingContactSelection(update);
21318
+ // };
21319
+
21320
+ session.onpaymentauthorized = event => {
21321
+ var _window$Pelcro$site$r, _window$Pelcro$site$r2;
21322
+ console.log("on payment authorized step", event);
21323
+ // Define ApplePayPaymentAuthorizationResult
21324
+ const result = {
21325
+ status: ApplePaySession.STATUS_SUCCESS
21326
+ };
21327
+ const {
21328
+ paymentData
21329
+ } = event.payment.token;
21330
+ const {
21331
+ data,
21332
+ signature,
21333
+ version
21334
+ } = paymentData;
21335
+ const {
21336
+ ephemeralPublicKey,
21337
+ publicKeyHash,
21338
+ transactionId
21339
+ } = paymentData.header;
21340
+ const applePayToken = {
21341
+ data: data,
21342
+ signature: signature,
21343
+ version: version,
21344
+ header: {
21345
+ ephemeralPublicKey: ephemeralPublicKey,
21346
+ publicKeyHash: publicKeyHash,
21347
+ transactionId: transactionId
21348
+ }
21349
+ };
21350
+ console.log(applePayToken);
21351
+ const payPageId = (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.vantiv_gateway_settings.pay_page_id;
21352
+ const reportGroup = (_window$Pelcro$site$r2 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : _window$Pelcro$site$r2.vantiv_gateway_settings.report_group;
21353
+ const orderId = `pelcro-${new Date().getTime()}`;
21354
+ const eProtectRequest = {
21355
+ paypageId: payPageId,
21356
+ reportGroup: reportGroup,
21357
+ orderId: orderId,
21358
+ id: orderId,
21359
+ applepay: applePayToken,
21360
+ url: "https://request.eprotect.vantivprelive.com"
21361
+ };
21362
+
21363
+ // successCallback function to handle the response from WorldPay.
21364
+ function successCallback(vantivResponse) {
21365
+ const {
21366
+ expDate
21367
+ } = vantivResponse;
21368
+ console.log("Response:", vantivResponse);
21369
+ const expMonth = expDate.substring(0, 2);
21370
+ const expYear = expDate.substring(2);
21371
+ const vantivPaymentRequest = {
21372
+ ...vantivResponse,
21373
+ expMonth: expMonth,
21374
+ expYear: expYear
21375
+ };
21376
+
21377
+ // Process the registrationId or continue with further payment processing.
21378
+ dispatch({
21379
+ type: HANDLE_APPLEPAY_SUBSCRIPTION,
21380
+ payload: vantivPaymentRequest
21381
+ });
21382
+ dispatch({
21383
+ type: LOADING,
21384
+ payload: true
21385
+ });
21386
+ session.completePayment(result);
21387
+ }
21388
+
21389
+ // errorCallback function to handle any errors that may occur during the tokenization process.
21390
+ function errorCallback(error) {
21391
+ console.error("Error retrieving Registration ID:", error);
21392
+ // Handle error appropriately.
21393
+ }
21394
+ // errorCallback function to handle any errors that may occur during the tokenization process.
21395
+ function timeoutCallback() {
21396
+ console.error("eProtect Timeout");
21397
+ // Handle error appropriately.
21398
+ }
21399
+
21400
+ new eProtect().sendToEprotect(eProtectRequest, {}, successCallback, errorCallback, timeoutCallback, 15000);
21401
+ };
21402
+
21403
+ // TODO: Check if oncouponcodechanged it should be implemented
21404
+ // session.oncouponcodechanged = (event) => {
21405
+ // console.log("on coupon code changed step", event);
21406
+ // // Define ApplePayCouponCodeUpdate
21407
+ // const newTotal = calculateNewTotal(event.couponCode);
21408
+ // const newLineItems = calculateNewLineItems(event.couponCode);
21409
+ // const newShippingMethods = calculateNewShippingMethods(
21410
+ // event.couponCode
21411
+ // );
21412
+ // const errors = calculateErrors(event.couponCode);
21413
+
21414
+ // session.completeCouponCodeChange({
21415
+ // newTotal: newTotal,
21416
+ // newLineItems: newLineItems,
21417
+ // newShippingMethods: newShippingMethods,
21418
+ // errors: errors
21419
+ // });
21420
+ // };
21421
+
21422
+ session.oncancel = event => {
21423
+ // Payment cancelled by WebKit
21424
+ console.log("on cancel step", event);
21425
+ dispatch({
21426
+ type: LOADING,
21427
+ payload: false
21428
+ });
21429
+ dispatch({
21430
+ type: DISABLE_SUBMIT,
21431
+ payload: false
21432
+ });
21433
+ };
21434
+ session.begin();
21435
+ }
21436
+ useEffect(() => {
21437
+ const pelcroApplyPayButton = document.getElementById("pelcro-apple-pay-button");
21438
+ if (pelcroApplyPayButton) {
21439
+ pelcroApplyPayButton.addEventListener("click", onApplePayButtonClicked);
21440
+ }
21441
+ }, []);
21442
+ return /*#__PURE__*/React__default.createElement("apple-pay-button", {
21443
+ id: "pelcro-apple-pay-button",
21444
+ style: {
21445
+ display: "none"
21446
+ },
21447
+ buttonstyle: "black",
21448
+ type: "plain",
21449
+ locale: "en-US"
21450
+ });
21451
+ };
21452
+
21113
21453
  /**
21114
21454
  *
21115
21455
  */
@@ -21200,7 +21540,7 @@ function PaymentMethodView(_ref) {
21200
21540
  className: "plc-mb-2"
21201
21541
  }, /*#__PURE__*/React__default.createElement(CouponCode, null), /*#__PURE__*/React__default.createElement(DiscountedPrice, null)), /*#__PURE__*/React__default.createElement(TaxAmount, null), /*#__PURE__*/React__default.createElement("div", {
21202
21542
  className: "plc-grid plc-mt-4 plc-gap-y-2"
21203
- }, /*#__PURE__*/React__default.createElement(SubmitPaymentMethod, null), showExternalPaymentMethods && !supportsVantiv && !supportsCybersource && !supportsTap ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(PelcroPaymentRequestButton, null), /*#__PURE__*/React__default.createElement(PaypalSubscribeButton, null)) : showExternalPaymentMethods && supportsVantiv ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(PaypalSubscribeButton, null)) : null)))));
21543
+ }, /*#__PURE__*/React__default.createElement(SubmitPaymentMethod, null), showExternalPaymentMethods && !supportsVantiv && !supportsCybersource && !supportsTap ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(PelcroPaymentRequestButton, null), /*#__PURE__*/React__default.createElement(PaypalSubscribeButton, null)) : showExternalPaymentMethods && supportsVantiv ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(ApplePayButton, null), /*#__PURE__*/React__default.createElement(PaypalSubscribeButton, null)) : null)))));
21204
21544
  }
21205
21545
 
21206
21546
  const SubscriptionRenewView = _ref => {
package/dist/pelcro.css CHANGED
@@ -1728,6 +1728,14 @@ layer components {
1728
1728
  }
1729
1729
  }
1730
1730
 
1731
+ apple-pay-button {
1732
+ --apple-pay-button-width: 100%;
1733
+ --apple-pay-button-height: 48px;
1734
+ --apple-pay-button-border-radius: 0.25rem;
1735
+ --apple-pay-button-padding: 0px 0px;
1736
+ --apple-pay-button-box-sizing: border-box;
1737
+ }
1738
+
1731
1739
  /* utilities */
1732
1740
 
1733
1741
  .pelcro-root .plc-space-x-0 > :not([hidden]) ~ :not([hidden]) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pelcro/react-pelcro-js",
3
3
  "description": "Pelcro's React UI Elements",
4
- "version": "3.26.0-beta.5",
4
+ "version": "3.26.0-beta.6",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",