@flopay/react 0.4.1 → 0.4.3

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.mjs CHANGED
@@ -2461,7 +2461,7 @@ function FloPayCheckout({
2461
2461
  )
2462
2462
  ] }) }) });
2463
2463
  }
2464
- return /* @__PURE__ */ jsx5(CheckoutContext.Provider, { value: checkoutValue, children: /* @__PURE__ */ jsxs3(FloPayProvider, { flopay, options: providerOptions, children: [
2464
+ return /* @__PURE__ */ jsx5(CheckoutContext.Provider, { value: checkoutValue, children: /* @__PURE__ */ jsxs3(FloPayProvider, { flopay, paypalFlopay, options: providerOptions, children: [
2465
2465
  modeError && /* @__PURE__ */ jsx5(
2466
2466
  "div",
2467
2467
  {
@@ -2777,6 +2777,7 @@ function CheckoutFormInner({
2777
2777
  innerRef
2778
2778
  }) {
2779
2779
  const flopay = useFloPay();
2780
+ const paypalFlopay = usePayPalFloPay();
2780
2781
  const elements = useElements();
2781
2782
  const contextBillingUrl = useBillingApiUrl();
2782
2783
  const [processing, setProcessing] = useState4(false);
@@ -2861,20 +2862,35 @@ function CheckoutFormInner({
2861
2862
  return;
2862
2863
  }
2863
2864
  if (json?.type === "paypal_redirect_required") {
2864
- const secret = json["clientSecret"];
2865
+ const secret = json["threeDSecureToken"] ?? json["clientSecret"];
2865
2866
  const pmId = json["paymentMethodId"];
2866
- if (flopay && secret) {
2867
- localStorage.setItem(WALLET_RESUME_KEY2, JSON.stringify({
2868
- sessionId,
2869
- paymentIntentId: "",
2870
- tokenType: "card",
2871
- tokenId: pmId,
2872
- status: "pending_redirect"
2873
- }));
2874
- await flopay.confirmPayment({
2875
- clientSecret: secret,
2876
- returnUrl: window.location.href
2877
- });
2867
+ const paypalStripe = (paypalFlopay ?? flopay)?.getRawProvider();
2868
+ if (!paypalStripe || !secret) {
2869
+ const message = "PayPal is not available.";
2870
+ updateError(message);
2871
+ onDecline?.(buildDeclineEvent("paypal", message));
2872
+ return;
2873
+ }
2874
+ localStorage.setItem(WALLET_RESUME_KEY2, JSON.stringify({
2875
+ sessionId,
2876
+ paymentIntentId: "",
2877
+ tokenType: "card",
2878
+ tokenId: pmId ?? "",
2879
+ status: "pending_redirect"
2880
+ }));
2881
+ const confirmParams = {
2882
+ return_url: window.location.href
2883
+ };
2884
+ if (pmId) confirmParams["payment_method"] = pmId;
2885
+ const { error: confirmError } = await paypalStripe.confirmPayment({
2886
+ clientSecret: secret,
2887
+ confirmParams,
2888
+ redirect: "if_required"
2889
+ });
2890
+ if (confirmError) {
2891
+ const message = confirmError.message ?? "PayPal payment failed.";
2892
+ updateError(message);
2893
+ onDecline?.(buildDeclineEvent("paypal", message, { code: confirmError.code }));
2878
2894
  }
2879
2895
  return;
2880
2896
  }
@@ -2890,7 +2906,7 @@ function CheckoutFormInner({
2890
2906
  setProcessing(false);
2891
2907
  }
2892
2908
  },
2893
- [baseUrl, sessionId, userId, email, firstName, lastName, chv, flopay, onComplete, onError, updateError, emitDecline]
2909
+ [baseUrl, sessionId, userId, email, firstName, lastName, chv, flopay, paypalFlopay, onComplete, onError, onDecline, updateError, emitDecline]
2894
2910
  );
2895
2911
  const dispatchTokenizedBody = useCallback3(
2896
2912
  (tokenizedBody) => {