@sazito/checkout 0.4.0 → 0.4.1

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.
@@ -4,6 +4,7 @@ import { isValidElement, cloneElement, useMemo, useState, useRef, useEffect, use
4
4
  import { u as useCheckout, b as useSazitoClient, C as CheckoutProvider } from '../chunks/use-checkout-BM810__v.js';
5
5
  export { S as SazitoProvider } from '../chunks/use-checkout-BM810__v.js';
6
6
  import { m as formatPercent, E as sortCartItemsNewestFirst, H as toPersianDigits, r as isDigitalServiceGroup, t as isValidIranianMobile, z as normalizeIranianPhone, A as paymentMethodInfo, l as formatNumber } from '../chunks/labels-e8w4zRbg.js';
7
+ import { parsePaymentReturnUrl } from './payment-return.js';
7
8
  import '@sazito/client-sdk';
8
9
 
9
10
  /**
@@ -848,10 +849,20 @@ function SazitoCheckout({ theme, continueShoppingUrl, className, renderNextButto
848
849
  }
849
850
 
850
851
  function SazitoCheckoutPage({ credentials, config, paymentReturn, paymentReturnParams, className, renderNextButton, renderBackButton, renderEmptyCart, emptyCart, }) {
851
- const returnParams = paymentReturn?.params ?? paymentReturnParams;
852
+ // The explicit server-parsed value remains authoritative. As a fallback,
853
+ // detect Sazito's well-known nested callback in the browser. This prevents a
854
+ // caught callback route from silently booting a fresh checkout when the host
855
+ // forgot to forward its catch-all params.
856
+ const detectedPaymentReturn = paymentReturn == null &&
857
+ paymentReturnParams == null &&
858
+ typeof window !== 'undefined'
859
+ ? parsePaymentReturnUrl(window.location.href)
860
+ : undefined;
861
+ const resolvedPaymentReturn = paymentReturn ?? detectedPaymentReturn;
862
+ const returnParams = resolvedPaymentReturn?.params ?? paymentReturnParams;
852
863
  const isReturn = returnParams != null;
853
- const checkoutCredentials = paymentReturn
854
- ? { ...credentials, payment: paymentReturn.payment }
864
+ const checkoutCredentials = resolvedPaymentReturn
865
+ ? { ...credentials, payment: resolvedPaymentReturn.payment }
855
866
  : credentials;
856
867
  const client = useSazitoClient();
857
868
  return (jsxs(CheckoutProvider, { client: client, credentials: checkoutCredentials, config: config, autoStart: !isReturn, children: [returnParams ? jsx(ResolveReturn, { params: returnParams }) : null, jsx(SazitoCheckout, { theme: config?.theme, continueShoppingUrl: config?.continueShoppingUrl, className: className, renderNextButton: renderNextButton, renderBackButton: renderBackButton, renderEmptyCart: renderEmptyCart, emptyCart: emptyCart })] }));