@flopay/react 0.5.14 → 0.5.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -83,6 +83,33 @@ function CheckoutPage() {
83
83
 
84
84
  The mode can also be set on the session itself via the billing API's `checkoutMode` field. The `checkoutMode` prop overrides the session value.
85
85
 
86
+ #### Expired Sessions
87
+
88
+ When `FloPayCheckout` or `FloPayAutomaticPaymentButton` loads a checkout session whose `status` is `expired`, the component calls `onError` with a `FloPayError` so your app can route the customer into a recovery flow.
89
+
90
+ The error has:
91
+
92
+ - `message: 'Checkout session has expired.'`
93
+ - `type: 'api_error'`
94
+ - `code: 'checkout_session_expired'`
95
+
96
+ Use this code to create or request a fresh checkout session, then send the customer back through checkout:
97
+
98
+ ```tsx
99
+ <FloPayCheckout
100
+ sessionId={sessionId}
101
+ onComplete={() => router.push('/success')}
102
+ onError={(error) => {
103
+ if (error.code === 'checkout_session_expired') {
104
+ router.push('/checkout/expired');
105
+ return;
106
+ }
107
+
108
+ console.error(error);
109
+ }}
110
+ />
111
+ ```
112
+
86
113
  ### Automatic Payment Buttons
87
114
 
88
115
  Use `FloPayAutomaticPaymentButton` when you want a single reusable button that:
package/dist/index.cjs CHANGED
@@ -3611,6 +3611,11 @@ function FloPayCheckout({
3611
3611
  onSessionCompletedRef.current?.(sess.successUrl ?? "");
3612
3612
  return;
3613
3613
  }
3614
+ if (sess.status === "expired") {
3615
+ throw new import_shared7.FloPayError("Checkout session has expired.", "api_error", {
3616
+ code: "checkout_session_expired"
3617
+ });
3618
+ }
3614
3619
  const effectiveMode = checkoutModeProp ?? sess.checkoutMode ?? "full";
3615
3620
  setCurrentMode(effectiveMode);
3616
3621
  const hasPayPalRedirectParams = typeof window !== "undefined" && new URLSearchParams(window.location.search).has("payment_intent");
@@ -3782,8 +3787,10 @@ function FloPayCheckout({
3782
3787
  ] });
3783
3788
  }
3784
3789
  if (loadError) {
3785
- if (errorNode) return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: errorNode(loadError) });
3786
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3790
+ if (errorNode) {
3791
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CheckoutContext.Provider, { value: checkoutValue, children: errorNode(loadError) });
3792
+ }
3793
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CheckoutContext.Provider, { value: checkoutValue, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3787
3794
  "div",
3788
3795
  {
3789
3796
  style: {
@@ -3794,7 +3801,7 @@ function FloPayCheckout({
3794
3801
  },
3795
3802
  children: loadError.message
3796
3803
  }
3797
- );
3804
+ ) });
3798
3805
  }
3799
3806
  if (shouldShowInterimButtons) {
3800
3807
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
@@ -4933,6 +4940,11 @@ function FloPayAutomaticPaymentButton({
4933
4940
  });
4934
4941
  return;
4935
4942
  }
4943
+ if (session.status === "expired") {
4944
+ throw new import_shared10.FloPayError("Checkout session has expired.", "api_error", {
4945
+ code: "checkout_session_expired"
4946
+ });
4947
+ }
4936
4948
  try {
4937
4949
  let paymentResult = null;
4938
4950
  const redirectResult = getRedirectResultFromCheckoutProcessError(apiResult.autoProcessingError);