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

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,329 @@ 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 _window$Pelcro$site$r, _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 {
21183
+ payPageId,
21184
+ reportGroup,
21185
+ apple_pay_merchant_id: ApplePayMerchantId,
21186
+ apple_pay_enabled: ApplePayEnabled,
21187
+ apple_pay_billing_agreement: ApplePayBillingAgreement
21188
+ } = (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.vantiv_gateway_settings;
21189
+ 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;
21190
+ React.useEffect(() => {
21191
+ if (window.ApplePaySession) {
21192
+ // Indicates whether the device supports Apple Pay and whether the user has an active card in Wallet.
21193
+ const promise = ApplePaySession.canMakePaymentsWithActiveCard(ApplePayMerchantId);
21194
+ promise.then(function (canMakePayments) {
21195
+ if (canMakePayments && ApplePayEnabled) {
21196
+ // Display Apple Pay Buttons here…
21197
+ const pelcroApplyPayButton = document.getElementById("pelcro-apple-pay-button");
21198
+ if (pelcroApplyPayButton) {
21199
+ pelcroApplyPayButton.style.display = "block";
21200
+ }
21201
+ console.log("canMakePayments", canMakePayments);
21202
+ }
21203
+ });
21204
+ } else {
21205
+ console.error("ApplePay is not available on this browser");
21206
+ }
21207
+ }, []);
21208
+ function onApplePayButtonClicked() {
21209
+ var _window, _window$Pelcro, _window$Pelcro$user, _window$Pelcro$user$l;
21210
+ if (!ApplePaySession) {
21211
+ return;
21212
+ }
21213
+ dispatch({
21214
+ type: DISABLE_SUBMIT,
21215
+ payload: true
21216
+ });
21217
+
21218
+ // Define ApplePayPaymentRequest
21219
+ // @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session
21220
+ const ApplePayPaymentRequest = {
21221
+ 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",
21222
+ currencyCode: (plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase()) || (invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase()),
21223
+ merchantCapabilities: ["supports3DS"],
21224
+ supportedNetworks: ["visa", "masterCard", "amex", "discover"],
21225
+ total: {
21226
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21227
+ amount: updatedPrice / 100
21228
+ },
21229
+ lineItems: [plan !== null && plan !== void 0 && plan.auto_renew ? {
21230
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21231
+ amount: updatedPrice / 100,
21232
+ paymentTiming: "recurring",
21233
+ recurringPaymentStartDate: new Date().toISOString(),
21234
+ recurringPaymentIntervalUnit: (plan === null || plan === void 0 ? void 0 : plan.interval) === "week" ? "day" : plan === null || plan === void 0 ? void 0 : plan.interval,
21235
+ recurringPaymentIntervalCount: (plan === null || plan === void 0 ? void 0 : plan.interval) === "week" ? (plan === null || plan === void 0 ? void 0 : plan.interval_count) * 7 : plan === null || plan === void 0 ? void 0 : plan.interval_count
21236
+ } : {
21237
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21238
+ amount: updatedPrice / 100
21239
+ }],
21240
+ ...((plan === null || plan === void 0 ? void 0 : plan.auto_renew) && {
21241
+ recurringPaymentRequest: {
21242
+ paymentDescription: "A description of the recurring payment to display to the user in the payment sheet.",
21243
+ regularBilling: {
21244
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21245
+ amount: updatedPrice / 100,
21246
+ paymentTiming: "recurring",
21247
+ recurringPaymentStartDate: new Date().toISOString(),
21248
+ recurringPaymentIntervalUnit: (plan === null || plan === void 0 ? void 0 : plan.interval) === "week" ? "day" : plan === null || plan === void 0 ? void 0 : plan.interval,
21249
+ recurringPaymentIntervalCount: (plan === null || plan === void 0 ? void 0 : plan.interval) === "week" ? (plan === null || plan === void 0 ? void 0 : plan.interval_count) * 7 : plan === null || plan === void 0 ? void 0 : plan.interval_count
21250
+ },
21251
+ billingAgreement: ApplePayBillingAgreement !== null && ApplePayBillingAgreement !== void 0 ? ApplePayBillingAgreement : "",
21252
+ managementURL: "https://applepaydemo.apple.com",
21253
+ tokenNotificationURL: "https://applepaydemo.apple.com"
21254
+ }
21255
+ })
21256
+ };
21257
+ console.log(ApplePayPaymentRequest);
21258
+ // Create ApplePaySession
21259
+ // @todo - Clarify supported version parameter
21260
+ // @odo - Apple Pay demo uses version 6 (https://applepaydemo.apple.com/)
21261
+ const session = new ApplePaySession(3, ApplePayPaymentRequest);
21262
+
21263
+ // @todo - Detect whether web browser supports a particular Apple Pay version.
21264
+ // @see https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778014-supportsversion
21265
+
21266
+ session.onvalidatemerchant = async event => {
21267
+ const {
21268
+ validationURL
21269
+ } = event;
21270
+ console.log("then merchantSession step", event);
21271
+ // Call your own server to request a new merchant session.
21272
+ window.Pelcro.payment.startSession({
21273
+ auth_token: window.Pelcro.user.read().auth_token,
21274
+ site_id: window.Pelcro.siteid,
21275
+ validation_url: validationURL
21276
+ }, (err, res) => {
21277
+ if (err) {
21278
+ // Handle any errors during merchant validation
21279
+ console.error("Merchant validation SDK error: ", err);
21280
+ session.abort();
21281
+ return dispatch({
21282
+ type: SHOW_ALERT,
21283
+ payload: {
21284
+ type: "error",
21285
+ content: getErrorMessages(err)
21286
+ }
21287
+ });
21288
+ }
21289
+ // Complete merchant validation with the merchant session object
21290
+ console.log("Merchant validation SDK response: ", res);
21291
+ const merchantSession = res;
21292
+ session.completeMerchantValidation(merchantSession);
21293
+ });
21294
+ };
21295
+ session.onpaymentmethodselected = event => {
21296
+ console.log("payment method selected step", event);
21297
+ // Define ApplePayPaymentMethodUpdate based on the selected payment method.
21298
+ // No updates or errors are needed, pass an empty object.
21299
+ const newTotal = {
21300
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21301
+ amount: updatedPrice / 100
21302
+ };
21303
+ const newLineItems = [plan !== null && plan !== void 0 && plan.auto_renew ? {
21304
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21305
+ amount: updatedPrice / 100,
21306
+ paymentTiming: "recurring",
21307
+ recurringPaymentStartDate: new Date().toISOString(),
21308
+ recurringPaymentIntervalUnit: (plan === null || plan === void 0 ? void 0 : plan.interval) === "week" ? "day" : plan === null || plan === void 0 ? void 0 : plan.interval,
21309
+ recurringPaymentIntervalCount: (plan === null || plan === void 0 ? void 0 : plan.interval) === "week" ? (plan === null || plan === void 0 ? void 0 : plan.interval_count) * 7 : plan === null || plan === void 0 ? void 0 : plan.interval_count
21310
+ } : {
21311
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21312
+ amount: updatedPrice / 100
21313
+ }];
21314
+ session.completePaymentMethodSelection(newTotal, newLineItems);
21315
+ };
21316
+
21317
+ // TODO: Check if onshippingmethodselected it should be implemented
21318
+ // session.onshippingmethodselected = (event) => {
21319
+ // console.log("on shipping method selected step", event);
21320
+ // // Define ApplePayShippingMethodUpdate based on the selected shipping method.
21321
+ // // No updates or errors are needed, pass an empty object.
21322
+ // const newTotal = {
21323
+ // label: plan?.nickname || `invoice #${invoice.id}`,
21324
+ // amount: updatedPrice / 100
21325
+ // };
21326
+
21327
+ // const newLineItems = [
21328
+ // plan?.auto_renew
21329
+ // ? {
21330
+ // label: plan?.nickname || `invoice #${invoice.id}`,
21331
+ // amount: updatedPrice / 100,
21332
+ // paymentTiming: "recurring",
21333
+ // recurringPaymentStartDate: new Date().toISOString(),
21334
+ // recurringPaymentIntervalUnit: plan?.interval,
21335
+ // recurringPaymentIntervalCount: plan?.interval_count
21336
+ // }
21337
+ // : {
21338
+ // label: plan?.nickname || `invoice #${invoice.id}`,
21339
+ // amount: updatedPrice / 100
21340
+ // }
21341
+ // ];
21342
+
21343
+ // session.completeShippingMethodSelection(newTotal, newLineItems);
21344
+ // };
21345
+
21346
+ // TODO: Check if onshippingcontactselected it should be implemented
21347
+ // session.onshippingcontactselected = (event) => {
21348
+ // console.log("on shipping contact selected step", event);
21349
+ // // Define ApplePayShippingContactUpdate based on the selected shipping contact.
21350
+ // const update = {};
21351
+ // session.completeShippingContactSelection(update);
21352
+ // };
21353
+
21354
+ session.onpaymentauthorized = event => {
21355
+ console.log("on payment authorized step", event);
21356
+ // Define ApplePayPaymentAuthorizationResult
21357
+ const result = {
21358
+ status: ApplePaySession.STATUS_SUCCESS
21359
+ };
21360
+ const {
21361
+ paymentData
21362
+ } = event.payment.token;
21363
+ const {
21364
+ data,
21365
+ signature,
21366
+ version
21367
+ } = paymentData;
21368
+ const {
21369
+ ephemeralPublicKey,
21370
+ publicKeyHash,
21371
+ transactionId
21372
+ } = paymentData.header;
21373
+ const applePayToken = {
21374
+ data: data,
21375
+ signature: signature,
21376
+ version: version,
21377
+ header: {
21378
+ ephemeralPublicKey: ephemeralPublicKey,
21379
+ publicKeyHash: publicKeyHash,
21380
+ transactionId: transactionId
21381
+ }
21382
+ };
21383
+ console.log(applePayToken);
21384
+ const orderId = `pelcro-${new Date().getTime()}`;
21385
+ const eProtectRequest = {
21386
+ paypageId: payPageId,
21387
+ reportGroup: reportGroup,
21388
+ orderId: orderId,
21389
+ id: orderId,
21390
+ applepay: applePayToken,
21391
+ url: "https://request.eprotect.vantivprelive.com"
21392
+ };
21393
+
21394
+ // successCallback function to handle the response from WorldPay.
21395
+ function successCallback(vantivResponse) {
21396
+ const {
21397
+ expDate
21398
+ } = vantivResponse;
21399
+ console.log("Response:", vantivResponse);
21400
+ const expMonth = expDate.substring(0, 2);
21401
+ const expYear = expDate.substring(2);
21402
+ const vantivPaymentRequest = {
21403
+ ...vantivResponse,
21404
+ expMonth: expMonth,
21405
+ expYear: expYear
21406
+ };
21407
+
21408
+ // Process the registrationId or continue with further payment processing.
21409
+ dispatch({
21410
+ type: HANDLE_APPLEPAY_SUBSCRIPTION,
21411
+ payload: vantivPaymentRequest
21412
+ });
21413
+ dispatch({
21414
+ type: LOADING,
21415
+ payload: true
21416
+ });
21417
+ session.completePayment(result);
21418
+ }
21419
+
21420
+ // errorCallback function to handle any errors that may occur during the tokenization process.
21421
+ function errorCallback(error) {
21422
+ console.error("Error retrieving Registration ID:", error);
21423
+ // Handle error appropriately.
21424
+ }
21425
+ // errorCallback function to handle any errors that may occur during the tokenization process.
21426
+ function timeoutCallback() {
21427
+ console.error("eProtect Timeout");
21428
+ // Handle error appropriately.
21429
+ }
21430
+
21431
+ new eProtect().sendToEprotect(eProtectRequest, {}, successCallback, errorCallback, timeoutCallback, 15000);
21432
+ };
21433
+
21434
+ // TODO: Check if oncouponcodechanged it should be implemented
21435
+ // session.oncouponcodechanged = (event) => {
21436
+ // console.log("on coupon code changed step", event);
21437
+ // // Define ApplePayCouponCodeUpdate
21438
+ // const newTotal = calculateNewTotal(event.couponCode);
21439
+ // const newLineItems = calculateNewLineItems(event.couponCode);
21440
+ // const newShippingMethods = calculateNewShippingMethods(
21441
+ // event.couponCode
21442
+ // );
21443
+ // const errors = calculateErrors(event.couponCode);
21444
+
21445
+ // session.completeCouponCodeChange({
21446
+ // newTotal: newTotal,
21447
+ // newLineItems: newLineItems,
21448
+ // newShippingMethods: newShippingMethods,
21449
+ // errors: errors
21450
+ // });
21451
+ // };
21452
+
21453
+ session.oncancel = event => {
21454
+ // Payment cancelled by WebKit
21455
+ console.log("on cancel step", event);
21456
+ dispatch({
21457
+ type: LOADING,
21458
+ payload: false
21459
+ });
21460
+ dispatch({
21461
+ type: DISABLE_SUBMIT,
21462
+ payload: false
21463
+ });
21464
+ };
21465
+ session.begin();
21466
+ }
21467
+ React.useEffect(() => {
21468
+ const pelcroApplyPayButton = document.getElementById("pelcro-apple-pay-button");
21469
+ if (pelcroApplyPayButton) {
21470
+ pelcroApplyPayButton.addEventListener("click", onApplePayButtonClicked);
21471
+ }
21472
+ }, []);
21473
+ return /*#__PURE__*/React__default['default'].createElement("apple-pay-button", {
21474
+ id: "pelcro-apple-pay-button",
21475
+ style: {
21476
+ display: "none"
21477
+ },
21478
+ buttonstyle: "black",
21479
+ type: "plain",
21480
+ locale: "en-US"
21481
+ });
21482
+ };
21483
+
21143
21484
  /**
21144
21485
  *
21145
21486
  */
@@ -21230,7 +21571,7 @@ function PaymentMethodView(_ref) {
21230
21571
  className: "plc-mb-2"
21231
21572
  }, /*#__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
21573
  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)))));
21574
+ }, /*#__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
21575
  }
21235
21576
 
21236
21577
  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,329 @@ 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 _window$Pelcro$site$r, _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 {
21153
+ payPageId,
21154
+ reportGroup,
21155
+ apple_pay_merchant_id: ApplePayMerchantId,
21156
+ apple_pay_enabled: ApplePayEnabled,
21157
+ apple_pay_billing_agreement: ApplePayBillingAgreement
21158
+ } = (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.vantiv_gateway_settings;
21159
+ 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;
21160
+ useEffect(() => {
21161
+ if (window.ApplePaySession) {
21162
+ // Indicates whether the device supports Apple Pay and whether the user has an active card in Wallet.
21163
+ const promise = ApplePaySession.canMakePaymentsWithActiveCard(ApplePayMerchantId);
21164
+ promise.then(function (canMakePayments) {
21165
+ if (canMakePayments && ApplePayEnabled) {
21166
+ // Display Apple Pay Buttons here…
21167
+ const pelcroApplyPayButton = document.getElementById("pelcro-apple-pay-button");
21168
+ if (pelcroApplyPayButton) {
21169
+ pelcroApplyPayButton.style.display = "block";
21170
+ }
21171
+ console.log("canMakePayments", canMakePayments);
21172
+ }
21173
+ });
21174
+ } else {
21175
+ console.error("ApplePay is not available on this browser");
21176
+ }
21177
+ }, []);
21178
+ function onApplePayButtonClicked() {
21179
+ var _window, _window$Pelcro, _window$Pelcro$user, _window$Pelcro$user$l;
21180
+ if (!ApplePaySession) {
21181
+ return;
21182
+ }
21183
+ dispatch({
21184
+ type: DISABLE_SUBMIT,
21185
+ payload: true
21186
+ });
21187
+
21188
+ // Define ApplePayPaymentRequest
21189
+ // @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session
21190
+ const ApplePayPaymentRequest = {
21191
+ 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",
21192
+ currencyCode: (plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase()) || (invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase()),
21193
+ merchantCapabilities: ["supports3DS"],
21194
+ supportedNetworks: ["visa", "masterCard", "amex", "discover"],
21195
+ total: {
21196
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21197
+ amount: updatedPrice / 100
21198
+ },
21199
+ lineItems: [plan !== null && plan !== void 0 && plan.auto_renew ? {
21200
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21201
+ amount: updatedPrice / 100,
21202
+ paymentTiming: "recurring",
21203
+ recurringPaymentStartDate: new Date().toISOString(),
21204
+ recurringPaymentIntervalUnit: (plan === null || plan === void 0 ? void 0 : plan.interval) === "week" ? "day" : plan === null || plan === void 0 ? void 0 : plan.interval,
21205
+ recurringPaymentIntervalCount: (plan === null || plan === void 0 ? void 0 : plan.interval) === "week" ? (plan === null || plan === void 0 ? void 0 : plan.interval_count) * 7 : plan === null || plan === void 0 ? void 0 : plan.interval_count
21206
+ } : {
21207
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21208
+ amount: updatedPrice / 100
21209
+ }],
21210
+ ...((plan === null || plan === void 0 ? void 0 : plan.auto_renew) && {
21211
+ recurringPaymentRequest: {
21212
+ paymentDescription: "A description of the recurring payment to display to the user in the payment sheet.",
21213
+ regularBilling: {
21214
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21215
+ amount: updatedPrice / 100,
21216
+ paymentTiming: "recurring",
21217
+ recurringPaymentStartDate: new Date().toISOString(),
21218
+ recurringPaymentIntervalUnit: (plan === null || plan === void 0 ? void 0 : plan.interval) === "week" ? "day" : plan === null || plan === void 0 ? void 0 : plan.interval,
21219
+ recurringPaymentIntervalCount: (plan === null || plan === void 0 ? void 0 : plan.interval) === "week" ? (plan === null || plan === void 0 ? void 0 : plan.interval_count) * 7 : plan === null || plan === void 0 ? void 0 : plan.interval_count
21220
+ },
21221
+ billingAgreement: ApplePayBillingAgreement !== null && ApplePayBillingAgreement !== void 0 ? ApplePayBillingAgreement : "",
21222
+ managementURL: "https://applepaydemo.apple.com",
21223
+ tokenNotificationURL: "https://applepaydemo.apple.com"
21224
+ }
21225
+ })
21226
+ };
21227
+ console.log(ApplePayPaymentRequest);
21228
+ // Create ApplePaySession
21229
+ // @todo - Clarify supported version parameter
21230
+ // @odo - Apple Pay demo uses version 6 (https://applepaydemo.apple.com/)
21231
+ const session = new ApplePaySession(3, ApplePayPaymentRequest);
21232
+
21233
+ // @todo - Detect whether web browser supports a particular Apple Pay version.
21234
+ // @see https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778014-supportsversion
21235
+
21236
+ session.onvalidatemerchant = async event => {
21237
+ const {
21238
+ validationURL
21239
+ } = event;
21240
+ console.log("then merchantSession step", event);
21241
+ // Call your own server to request a new merchant session.
21242
+ window.Pelcro.payment.startSession({
21243
+ auth_token: window.Pelcro.user.read().auth_token,
21244
+ site_id: window.Pelcro.siteid,
21245
+ validation_url: validationURL
21246
+ }, (err, res) => {
21247
+ if (err) {
21248
+ // Handle any errors during merchant validation
21249
+ console.error("Merchant validation SDK error: ", err);
21250
+ session.abort();
21251
+ return dispatch({
21252
+ type: SHOW_ALERT,
21253
+ payload: {
21254
+ type: "error",
21255
+ content: getErrorMessages(err)
21256
+ }
21257
+ });
21258
+ }
21259
+ // Complete merchant validation with the merchant session object
21260
+ console.log("Merchant validation SDK response: ", res);
21261
+ const merchantSession = res;
21262
+ session.completeMerchantValidation(merchantSession);
21263
+ });
21264
+ };
21265
+ session.onpaymentmethodselected = event => {
21266
+ console.log("payment method selected step", event);
21267
+ // Define ApplePayPaymentMethodUpdate based on the selected payment method.
21268
+ // No updates or errors are needed, pass an empty object.
21269
+ const newTotal = {
21270
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21271
+ amount: updatedPrice / 100
21272
+ };
21273
+ const newLineItems = [plan !== null && plan !== void 0 && plan.auto_renew ? {
21274
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21275
+ amount: updatedPrice / 100,
21276
+ paymentTiming: "recurring",
21277
+ recurringPaymentStartDate: new Date().toISOString(),
21278
+ recurringPaymentIntervalUnit: (plan === null || plan === void 0 ? void 0 : plan.interval) === "week" ? "day" : plan === null || plan === void 0 ? void 0 : plan.interval,
21279
+ recurringPaymentIntervalCount: (plan === null || plan === void 0 ? void 0 : plan.interval) === "week" ? (plan === null || plan === void 0 ? void 0 : plan.interval_count) * 7 : plan === null || plan === void 0 ? void 0 : plan.interval_count
21280
+ } : {
21281
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21282
+ amount: updatedPrice / 100
21283
+ }];
21284
+ session.completePaymentMethodSelection(newTotal, newLineItems);
21285
+ };
21286
+
21287
+ // TODO: Check if onshippingmethodselected it should be implemented
21288
+ // session.onshippingmethodselected = (event) => {
21289
+ // console.log("on shipping method selected step", event);
21290
+ // // Define ApplePayShippingMethodUpdate based on the selected shipping method.
21291
+ // // No updates or errors are needed, pass an empty object.
21292
+ // const newTotal = {
21293
+ // label: plan?.nickname || `invoice #${invoice.id}`,
21294
+ // amount: updatedPrice / 100
21295
+ // };
21296
+
21297
+ // const newLineItems = [
21298
+ // plan?.auto_renew
21299
+ // ? {
21300
+ // label: plan?.nickname || `invoice #${invoice.id}`,
21301
+ // amount: updatedPrice / 100,
21302
+ // paymentTiming: "recurring",
21303
+ // recurringPaymentStartDate: new Date().toISOString(),
21304
+ // recurringPaymentIntervalUnit: plan?.interval,
21305
+ // recurringPaymentIntervalCount: plan?.interval_count
21306
+ // }
21307
+ // : {
21308
+ // label: plan?.nickname || `invoice #${invoice.id}`,
21309
+ // amount: updatedPrice / 100
21310
+ // }
21311
+ // ];
21312
+
21313
+ // session.completeShippingMethodSelection(newTotal, newLineItems);
21314
+ // };
21315
+
21316
+ // TODO: Check if onshippingcontactselected it should be implemented
21317
+ // session.onshippingcontactselected = (event) => {
21318
+ // console.log("on shipping contact selected step", event);
21319
+ // // Define ApplePayShippingContactUpdate based on the selected shipping contact.
21320
+ // const update = {};
21321
+ // session.completeShippingContactSelection(update);
21322
+ // };
21323
+
21324
+ session.onpaymentauthorized = event => {
21325
+ console.log("on payment authorized step", event);
21326
+ // Define ApplePayPaymentAuthorizationResult
21327
+ const result = {
21328
+ status: ApplePaySession.STATUS_SUCCESS
21329
+ };
21330
+ const {
21331
+ paymentData
21332
+ } = event.payment.token;
21333
+ const {
21334
+ data,
21335
+ signature,
21336
+ version
21337
+ } = paymentData;
21338
+ const {
21339
+ ephemeralPublicKey,
21340
+ publicKeyHash,
21341
+ transactionId
21342
+ } = paymentData.header;
21343
+ const applePayToken = {
21344
+ data: data,
21345
+ signature: signature,
21346
+ version: version,
21347
+ header: {
21348
+ ephemeralPublicKey: ephemeralPublicKey,
21349
+ publicKeyHash: publicKeyHash,
21350
+ transactionId: transactionId
21351
+ }
21352
+ };
21353
+ console.log(applePayToken);
21354
+ const orderId = `pelcro-${new Date().getTime()}`;
21355
+ const eProtectRequest = {
21356
+ paypageId: payPageId,
21357
+ reportGroup: reportGroup,
21358
+ orderId: orderId,
21359
+ id: orderId,
21360
+ applepay: applePayToken,
21361
+ url: "https://request.eprotect.vantivprelive.com"
21362
+ };
21363
+
21364
+ // successCallback function to handle the response from WorldPay.
21365
+ function successCallback(vantivResponse) {
21366
+ const {
21367
+ expDate
21368
+ } = vantivResponse;
21369
+ console.log("Response:", vantivResponse);
21370
+ const expMonth = expDate.substring(0, 2);
21371
+ const expYear = expDate.substring(2);
21372
+ const vantivPaymentRequest = {
21373
+ ...vantivResponse,
21374
+ expMonth: expMonth,
21375
+ expYear: expYear
21376
+ };
21377
+
21378
+ // Process the registrationId or continue with further payment processing.
21379
+ dispatch({
21380
+ type: HANDLE_APPLEPAY_SUBSCRIPTION,
21381
+ payload: vantivPaymentRequest
21382
+ });
21383
+ dispatch({
21384
+ type: LOADING,
21385
+ payload: true
21386
+ });
21387
+ session.completePayment(result);
21388
+ }
21389
+
21390
+ // errorCallback function to handle any errors that may occur during the tokenization process.
21391
+ function errorCallback(error) {
21392
+ console.error("Error retrieving Registration ID:", error);
21393
+ // Handle error appropriately.
21394
+ }
21395
+ // errorCallback function to handle any errors that may occur during the tokenization process.
21396
+ function timeoutCallback() {
21397
+ console.error("eProtect Timeout");
21398
+ // Handle error appropriately.
21399
+ }
21400
+
21401
+ new eProtect().sendToEprotect(eProtectRequest, {}, successCallback, errorCallback, timeoutCallback, 15000);
21402
+ };
21403
+
21404
+ // TODO: Check if oncouponcodechanged it should be implemented
21405
+ // session.oncouponcodechanged = (event) => {
21406
+ // console.log("on coupon code changed step", event);
21407
+ // // Define ApplePayCouponCodeUpdate
21408
+ // const newTotal = calculateNewTotal(event.couponCode);
21409
+ // const newLineItems = calculateNewLineItems(event.couponCode);
21410
+ // const newShippingMethods = calculateNewShippingMethods(
21411
+ // event.couponCode
21412
+ // );
21413
+ // const errors = calculateErrors(event.couponCode);
21414
+
21415
+ // session.completeCouponCodeChange({
21416
+ // newTotal: newTotal,
21417
+ // newLineItems: newLineItems,
21418
+ // newShippingMethods: newShippingMethods,
21419
+ // errors: errors
21420
+ // });
21421
+ // };
21422
+
21423
+ session.oncancel = event => {
21424
+ // Payment cancelled by WebKit
21425
+ console.log("on cancel step", event);
21426
+ dispatch({
21427
+ type: LOADING,
21428
+ payload: false
21429
+ });
21430
+ dispatch({
21431
+ type: DISABLE_SUBMIT,
21432
+ payload: false
21433
+ });
21434
+ };
21435
+ session.begin();
21436
+ }
21437
+ useEffect(() => {
21438
+ const pelcroApplyPayButton = document.getElementById("pelcro-apple-pay-button");
21439
+ if (pelcroApplyPayButton) {
21440
+ pelcroApplyPayButton.addEventListener("click", onApplePayButtonClicked);
21441
+ }
21442
+ }, []);
21443
+ return /*#__PURE__*/React__default.createElement("apple-pay-button", {
21444
+ id: "pelcro-apple-pay-button",
21445
+ style: {
21446
+ display: "none"
21447
+ },
21448
+ buttonstyle: "black",
21449
+ type: "plain",
21450
+ locale: "en-US"
21451
+ });
21452
+ };
21453
+
21113
21454
  /**
21114
21455
  *
21115
21456
  */
@@ -21200,7 +21541,7 @@ function PaymentMethodView(_ref) {
21200
21541
  className: "plc-mb-2"
21201
21542
  }, /*#__PURE__*/React__default.createElement(CouponCode, null), /*#__PURE__*/React__default.createElement(DiscountedPrice, null)), /*#__PURE__*/React__default.createElement(TaxAmount, null), /*#__PURE__*/React__default.createElement("div", {
21202
21543
  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)))));
21544
+ }, /*#__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
21545
  }
21205
21546
 
21206
21547
  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.7",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",