paymob-pixel-alpha 1.0.9 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/main.js +52 -29
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -26890,7 +26890,8 @@ function ApplePay(props) {
26890
26890
  checkDiscount,
26891
26891
  isPixel,
26892
26892
  isLoading,
26893
- paymentName
26893
+ paymentName,
26894
+ onLayerClick
26894
26895
  } = props;
26895
26896
  const [loading, setLoading] = (0,react.useState)(false);
26896
26897
  const [discount, setDiscount] = (0,react.useState)({
@@ -26937,13 +26938,6 @@ function ApplePay(props) {
26937
26938
  payload.requiredShippingContactFields = ['email', 'phone', 'name'];
26938
26939
  }
26939
26940
  const session = new window.ApplePaySession(3, payload);
26940
- if (onBeforePaymentComplete) {
26941
- const result = await onBeforePaymentComplete(paymentName);
26942
- if (!result) {
26943
- setLoading(false);
26944
- return;
26945
- }
26946
- }
26947
26941
  session.onvalidatemerchant = async event => {
26948
26942
  console.log("start validation request");
26949
26943
  console.log(`validationURL: ${event.validationURL}`);
@@ -27039,7 +27033,7 @@ function ApplePay(props) {
27039
27033
  session.begin();
27040
27034
  };
27041
27035
  return /*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
27042
- className: `w-full ${discount.hasDiscount ? `flex flex-col gap-2 !h-auto ${!isPixel ? 'sm:mb-6' : ''}` : ''}`,
27036
+ className: `w-full ${isPixel ? 'relative' : ''} ${discount.hasDiscount ? `flex flex-col gap-2 !h-auto ${!isPixel ? 'sm:mb-6' : ''}` : ''}`,
27043
27037
  children: [/*#__PURE__*/(0,jsx_runtime.jsx)(Button_Button, {
27044
27038
  id: "apple-pay-button",
27045
27039
  icon: apple_pay_namespaceObject,
@@ -27049,6 +27043,9 @@ function ApplePay(props) {
27049
27043
  customStyle: customStyle,
27050
27044
  disabled: loading || isLoading,
27051
27045
  loading: loading || isLoading
27046
+ }), isPixel && /*#__PURE__*/(0,jsx_runtime.jsx)("button", {
27047
+ onClick: () => onLayerClick == null ? void 0 : onLayerClick(setLoading),
27048
+ className: "absolute inset-0 cursor-pointer"
27052
27049
  }), discount.hasDiscount && /*#__PURE__*/(0,jsx_runtime.jsx)("p", {
27053
27050
  className: "flex text-center flex-col justify-center text-green-400 text-sm font-medium leading-6 tracking-[0.01rem]",
27054
27051
  children: discount.discountMessage
@@ -27253,7 +27250,6 @@ function GooglePayElement({
27253
27250
  keyPrefix: 'googlePay'
27254
27251
  });
27255
27252
  const [loading, setLoading] = (0,react.useState)(false);
27256
- const [googlePayload, setGooglePayload] = (0,react.useState)(null);
27257
27253
  const [startGooglePay, setStartGooglePay] = (0,react.useState)(false);
27258
27254
  const {
27259
27255
  amount,
@@ -27263,12 +27259,11 @@ function GooglePayElement({
27263
27259
  const integrationId = googlePay == null ? void 0 : googlePay.integrationId;
27264
27260
  (0,react.useEffect)(() => {
27265
27261
  if (startGooglePay && isProcessingPayment) {
27266
- handlePay(googlePay == null ? void 0 : googlePay.token, googlePayload);
27267
- setStartGooglePay(false);
27268
- onProcessingPayment(false);
27262
+ const googlePayButton = document.getElementById('gpay-button-online-api-id');
27263
+ googlePayButton == null || googlePayButton.click();
27269
27264
  }
27270
27265
  }, [startGooglePay, isProcessingPayment]);
27271
- const handleSubmit = async (paymentToken, googlePayload) => {
27266
+ const handleLayerClick = async () => {
27272
27267
  setLoading(true);
27273
27268
  if (onBeforePaymentComplete) {
27274
27269
  const result = await onBeforePaymentComplete(payment.name);
@@ -27279,9 +27274,8 @@ function GooglePayElement({
27279
27274
  }
27280
27275
  setStartGooglePay(true);
27281
27276
  onProcessingPayment(true);
27282
- setGooglePayload(googlePayload);
27283
27277
  };
27284
- const handlePay = async (paymentToken, googlePayload) => {
27278
+ const handleSubmit = async (paymentToken, googlePayload) => {
27285
27279
  var _res$data;
27286
27280
  const res = await payWithGooglePay(paymentToken, integrationId, googlePayload);
27287
27281
  setLoading(false);
@@ -27328,17 +27322,23 @@ function GooglePayElement({
27328
27322
  }
27329
27323
  };
27330
27324
  return /*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment, {
27331
- children: [/*#__PURE__*/(0,jsx_runtime.jsx)(GooglePay, {
27332
- onSubmit: handleSubmit,
27333
- paymentToken: (googlePay == null ? void 0 : googlePay.token) || '',
27334
- paymentGateway: (googlePay == null ? void 0 : googlePay.gateway) || '',
27335
- isLiveIntegration: googlePay == null ? void 0 : googlePay.live,
27336
- merchantIdentifier: googlePay == null ? void 0 : googlePay.merchantIdentifier,
27337
- amount: (_String = String(amount)) == null ? void 0 : _String.replace(/,/g, ''),
27338
- currency: currency,
27339
- countryCode: currency == null ? void 0 : currency.slice(0, 2),
27340
- customStyle: customStyle,
27341
- isLoading: isLoading
27325
+ children: [/*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
27326
+ className: "relative w-full",
27327
+ children: [/*#__PURE__*/(0,jsx_runtime.jsx)(GooglePay, {
27328
+ onSubmit: handleSubmit,
27329
+ paymentToken: (googlePay == null ? void 0 : googlePay.token) || '',
27330
+ paymentGateway: (googlePay == null ? void 0 : googlePay.gateway) || '',
27331
+ isLiveIntegration: googlePay == null ? void 0 : googlePay.live,
27332
+ merchantIdentifier: googlePay == null ? void 0 : googlePay.merchantIdentifier,
27333
+ amount: (_String = String(amount)) == null ? void 0 : _String.replace(/,/g, ''),
27334
+ currency: currency,
27335
+ countryCode: currency == null ? void 0 : currency.slice(0, 2),
27336
+ customStyle: customStyle,
27337
+ isLoading: isLoading
27338
+ }), /*#__PURE__*/(0,jsx_runtime.jsx)("button", {
27339
+ onClick: handleLayerClick,
27340
+ className: "absolute inset-0 cursor-pointer"
27341
+ })]
27342
27342
  }), /*#__PURE__*/(0,jsx_runtime.jsx)(LoadingModal, {
27343
27343
  show: loading,
27344
27344
  text: t('LOADING_MSG')
@@ -27374,21 +27374,43 @@ const checkDiscount = paymentToken => {
27374
27374
 
27375
27375
 
27376
27376
 
27377
+
27377
27378
  function ApplePayElements({
27378
27379
  payment,
27379
27380
  customStyle,
27380
27381
  onBeforePaymentComplete,
27381
27382
  onAfterPaymentComplete,
27382
27383
  onPaymentCancel,
27383
- isLoading
27384
+ isLoading,
27385
+ onProcessingPayment,
27386
+ isProcessingPayment
27384
27387
  }) {
27385
27388
  var _amount$toString;
27389
+ const [startApplePay, setStartApplePay] = (0,react.useState)(false);
27386
27390
  const {
27387
27391
  amount,
27388
27392
  currency,
27389
27393
  merchantName
27390
27394
  } = payment;
27391
27395
  const applePay = payment;
27396
+ (0,react.useEffect)(() => {
27397
+ if (startApplePay && isProcessingPayment) {
27398
+ const applePayButton = document.getElementById('apple-pay-button');
27399
+ applePayButton == null || applePayButton.click();
27400
+ }
27401
+ }, [startApplePay, isProcessingPayment]);
27402
+ const handleLayerClick = async setLoading => {
27403
+ setLoading(true);
27404
+ if (onBeforePaymentComplete) {
27405
+ const result = await onBeforePaymentComplete(payment.name);
27406
+ if (!result) {
27407
+ setLoading(false);
27408
+ return;
27409
+ }
27410
+ }
27411
+ setStartApplePay(true);
27412
+ onProcessingPayment(true);
27413
+ };
27392
27414
  const handleSubmit = (status, resData) => {
27393
27415
  window.location.href = resData.redirection_url;
27394
27416
  };
@@ -27409,7 +27431,8 @@ function ApplePayElements({
27409
27431
  checkDiscount: checkDiscount,
27410
27432
  isPixel: true,
27411
27433
  isLoading: isLoading,
27412
- paymentName: payment.name
27434
+ paymentName: payment.name,
27435
+ onLayerClick: handleLayerClick
27413
27436
  });
27414
27437
  }
27415
27438
  /* harmony default export */ const Payments_ApplePay = (ApplePayElements);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paymob-pixel-alpha",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "keywords": ["paymob","pixel","paymob-pixel"],
5
5
  "main": "./main.js",
6
6
  "homepage": "https://developers.paymob.com",