@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.
package/README.md CHANGED
@@ -97,6 +97,11 @@ export default async function CheckoutPage({
97
97
  `paymentReturnParams` remains available for existing query-only callback
98
98
  integrations.
99
99
 
100
+ As a fallback, `SazitoCheckoutPage` also recognizes this callback suffix from
101
+ the browser URL when `paymentReturn` is omitted. The catch-all route is still
102
+ required so Next.js serves the callback URL, and explicit server parsing remains
103
+ recommended because it validates the route before rendering.
104
+
100
105
  ### Theme variables
101
106
 
102
107
  `config.theme` (or the `theme` prop on `SazitoCheckout`) accepts:
@@ -41,4 +41,5 @@ exports.strings = labels.strings;
41
41
  exports.toEnglishDigits = labels.toEnglishDigits;
42
42
  exports.toPersianDigits = labels.toPersianDigits;
43
43
  exports.parsePaymentReturn = next_paymentReturn.parsePaymentReturn;
44
+ exports.parsePaymentReturnUrl = next_paymentReturn.parsePaymentReturnUrl;
44
45
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -308,6 +308,12 @@ declare const noopEffectExecutor: CheckoutEffectExecutor;
308
308
  * Returns undefined for ordinary checkout URLs and malformed callbacks.
309
309
  */
310
310
  declare function parsePaymentReturn(segments: readonly string[] | undefined, searchParams?: PaymentReturnSearchParams): CheckoutPaymentReturn | undefined;
311
+ /**
312
+ * Parse a complete checkout URL containing Sazito's nested payment callback.
313
+ * The callback may be mounted below any checkout base path; only its final
314
+ * five path segments are significant.
315
+ */
316
+ declare function parsePaymentReturnUrl(url: string | URL): CheckoutPaymentReturn | undefined;
311
317
 
312
318
  /**
313
319
  * Typed event bus helpers.
@@ -516,5 +522,5 @@ declare function selectSummary(invoice: Invoice | null): CheckoutSummary;
516
522
  /** Items that don't require shipping (digital), for display in the shipping step. */
517
523
  declare function selectDigitalItems(invoice: Invoice | null, groups: ShippingGroup[], applicable: ApplicableShippingMethods | null): InvoiceItem[];
518
524
 
519
- export { addressFormFromInvoice, buildShippingAssignments, classifyAppliedDiscount, createBrowserEffectExecutor, createCheckoutEngine, createSdkBinding, createStore, defaultCurrencyLabel, deriveShippingGroups, emptyAddressForm, formatMoney, formatNumber, formatPercent, formatPrice, fromSdkError, isAddressComplete, isAddressDirty, isDigitalServiceGroup, isShippingComplete, isValidIranianMobile, isValidIranianPhone, makeError, makeEvent, messageForCode, noopEffectExecutor, normalizeIranianPhone, parsePaymentReturn, paymentMethodInfo, paymentMethodLabel, selectDigitalItems, selectSummary, sortCartItemsNewestFirst, strings, toEnglishDigits, toPersianDigits };
525
+ export { addressFormFromInvoice, buildShippingAssignments, classifyAppliedDiscount, createBrowserEffectExecutor, createCheckoutEngine, createSdkBinding, createStore, defaultCurrencyLabel, deriveShippingGroups, emptyAddressForm, formatMoney, formatNumber, formatPercent, formatPrice, fromSdkError, isAddressComplete, isAddressDirty, isDigitalServiceGroup, isShippingComplete, isValidIranianMobile, isValidIranianPhone, makeError, makeEvent, messageForCode, noopEffectExecutor, normalizeIranianPhone, parsePaymentReturn, parsePaymentReturnUrl, paymentMethodInfo, paymentMethodLabel, selectDigitalItems, selectSummary, sortCartItemsNewestFirst, strings, toEnglishDigits, toPersianDigits };
520
526
  export type { AddressFormValues, AppliedDiscount, CheckoutActions, CheckoutCity, CheckoutConfig, CheckoutCredentials, CheckoutDirection, CheckoutEffect, CheckoutEffectExecutor, CheckoutEngine, CheckoutEngineOptions, CheckoutError, CheckoutErrorCode, CheckoutEvent, CheckoutEventName, CheckoutFlags, CheckoutLocale, CheckoutPaymentReturn, CheckoutRegion, CheckoutResult, CheckoutResultStatus, CheckoutSdkBinding, CheckoutState, CheckoutStatus, CheckoutStep, CheckoutSummary, CheckoutTheme, DiscountKind, PaymentMethodInfo, PaymentMethodKind, PaymentReturnSearchParams, ShippingGroup, Store, Strings, SummaryLine, SummaryLineKey };
@@ -308,6 +308,12 @@ declare const noopEffectExecutor: CheckoutEffectExecutor;
308
308
  * Returns undefined for ordinary checkout URLs and malformed callbacks.
309
309
  */
310
310
  declare function parsePaymentReturn(segments: readonly string[] | undefined, searchParams?: PaymentReturnSearchParams): CheckoutPaymentReturn | undefined;
311
+ /**
312
+ * Parse a complete checkout URL containing Sazito's nested payment callback.
313
+ * The callback may be mounted below any checkout base path; only its final
314
+ * five path segments are significant.
315
+ */
316
+ declare function parsePaymentReturnUrl(url: string | URL): CheckoutPaymentReturn | undefined;
311
317
 
312
318
  /**
313
319
  * Typed event bus helpers.
@@ -516,5 +522,5 @@ declare function selectSummary(invoice: Invoice | null): CheckoutSummary;
516
522
  /** Items that don't require shipping (digital), for display in the shipping step. */
517
523
  declare function selectDigitalItems(invoice: Invoice | null, groups: ShippingGroup[], applicable: ApplicableShippingMethods | null): InvoiceItem[];
518
524
 
519
- export { addressFormFromInvoice, buildShippingAssignments, classifyAppliedDiscount, createBrowserEffectExecutor, createCheckoutEngine, createSdkBinding, createStore, defaultCurrencyLabel, deriveShippingGroups, emptyAddressForm, formatMoney, formatNumber, formatPercent, formatPrice, fromSdkError, isAddressComplete, isAddressDirty, isDigitalServiceGroup, isShippingComplete, isValidIranianMobile, isValidIranianPhone, makeError, makeEvent, messageForCode, noopEffectExecutor, normalizeIranianPhone, parsePaymentReturn, paymentMethodInfo, paymentMethodLabel, selectDigitalItems, selectSummary, sortCartItemsNewestFirst, strings, toEnglishDigits, toPersianDigits };
525
+ export { addressFormFromInvoice, buildShippingAssignments, classifyAppliedDiscount, createBrowserEffectExecutor, createCheckoutEngine, createSdkBinding, createStore, defaultCurrencyLabel, deriveShippingGroups, emptyAddressForm, formatMoney, formatNumber, formatPercent, formatPrice, fromSdkError, isAddressComplete, isAddressDirty, isDigitalServiceGroup, isShippingComplete, isValidIranianMobile, isValidIranianPhone, makeError, makeEvent, messageForCode, noopEffectExecutor, normalizeIranianPhone, parsePaymentReturn, parsePaymentReturnUrl, paymentMethodInfo, paymentMethodLabel, selectDigitalItems, selectSummary, sortCartItemsNewestFirst, strings, toEnglishDigits, toPersianDigits };
520
526
  export type { AddressFormValues, AppliedDiscount, CheckoutActions, CheckoutCity, CheckoutConfig, CheckoutCredentials, CheckoutDirection, CheckoutEffect, CheckoutEffectExecutor, CheckoutEngine, CheckoutEngineOptions, CheckoutError, CheckoutErrorCode, CheckoutEvent, CheckoutEventName, CheckoutFlags, CheckoutLocale, CheckoutPaymentReturn, CheckoutRegion, CheckoutResult, CheckoutResultStatus, CheckoutSdkBinding, CheckoutState, CheckoutStatus, CheckoutStep, CheckoutSummary, CheckoutTheme, DiscountKind, PaymentMethodInfo, PaymentMethodKind, PaymentReturnSearchParams, ShippingGroup, Store, Strings, SummaryLine, SummaryLineKey };
@@ -1,4 +1,4 @@
1
1
  export { a as addressFormFromInvoice, b as buildShippingAssignments, c as classifyAppliedDiscount, d as createBrowserEffectExecutor, e as createCheckoutEngine, f as createSdkBinding, g as createStore, h as defaultCurrencyLabel, i as deriveShippingGroups, j as emptyAddressForm, k as formatMoney, l as formatNumber, m as formatPercent, n as formatPrice, o as fromSdkError, p as isAddressComplete, q as isAddressDirty, r as isDigitalServiceGroup, s as isShippingComplete, t as isValidIranianMobile, u as isValidIranianPhone, v as makeError, w as makeEvent, x as messageForCode, y as noopEffectExecutor, z as normalizeIranianPhone, A as paymentMethodInfo, B as paymentMethodLabel, C as selectDigitalItems, D as selectSummary, E as sortCartItemsNewestFirst, F as strings, G as toEnglishDigits, H as toPersianDigits } from '../chunks/labels-e8w4zRbg.js';
2
- export { parsePaymentReturn } from '../next/payment-return.js';
2
+ export { parsePaymentReturn, parsePaymentReturnUrl } from '../next/payment-return.js';
3
3
  import '@sazito/client-sdk';
4
4
  //# sourceMappingURL=index.js.map
@@ -5,6 +5,7 @@ var jsxRuntime = require('react/jsx-runtime');
5
5
  var react = require('react');
6
6
  var useCheckout = require('../chunks/use-checkout-DPtLgxlA.cjs');
7
7
  var labels = require('../chunks/labels-CnPllzhT.cjs');
8
+ var next_paymentReturn = require('./payment-return.cjs');
8
9
  require('@sazito/client-sdk');
9
10
 
10
11
  /**
@@ -849,10 +850,20 @@ function SazitoCheckout({ theme, continueShoppingUrl, className, renderNextButto
849
850
  }
850
851
 
851
852
  function SazitoCheckoutPage({ credentials, config, paymentReturn, paymentReturnParams, className, renderNextButton, renderBackButton, renderEmptyCart, emptyCart, }) {
852
- const returnParams = paymentReturn?.params ?? paymentReturnParams;
853
+ // The explicit server-parsed value remains authoritative. As a fallback,
854
+ // detect Sazito's well-known nested callback in the browser. This prevents a
855
+ // caught callback route from silently booting a fresh checkout when the host
856
+ // forgot to forward its catch-all params.
857
+ const detectedPaymentReturn = paymentReturn == null &&
858
+ paymentReturnParams == null &&
859
+ typeof window !== 'undefined'
860
+ ? next_paymentReturn.parsePaymentReturnUrl(window.location.href)
861
+ : undefined;
862
+ const resolvedPaymentReturn = paymentReturn ?? detectedPaymentReturn;
863
+ const returnParams = resolvedPaymentReturn?.params ?? paymentReturnParams;
853
864
  const isReturn = returnParams != null;
854
- const checkoutCredentials = paymentReturn
855
- ? { ...credentials, payment: paymentReturn.payment }
865
+ const checkoutCredentials = resolvedPaymentReturn
866
+ ? { ...credentials, payment: resolvedPaymentReturn.payment }
856
867
  : credentials;
857
868
  const client = useCheckout.useSazitoClient();
858
869
  return (jsxRuntime.jsxs(useCheckout.CheckoutProvider, { client: client, credentials: checkoutCredentials, config: config, autoStart: !isReturn, children: [returnParams ? jsxRuntime.jsx(ResolveReturn, { params: returnParams }) : null, jsxRuntime.jsx(SazitoCheckout, { theme: config?.theme, continueShoppingUrl: config?.continueShoppingUrl, className: className, renderNextButton: renderNextButton, renderBackButton: renderBackButton, renderEmptyCart: renderEmptyCart, emptyCart: emptyCart })] }));