@sazito/checkout 0.4.19 → 0.4.21

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 (47) hide show
  1. package/README.md +22 -37
  2. package/dist/chunks/{labels-Cy05dLJx.cjs → labels-BYJQjaT_.cjs} +9 -5
  3. package/dist/chunks/labels-BYJQjaT_.cjs.map +1 -0
  4. package/dist/chunks/{labels-Cysz2BgA.js → labels-Cqrb2MwA.js} +9 -5
  5. package/dist/chunks/labels-Cqrb2MwA.js.map +1 -0
  6. package/dist/chunks/{use-checkout-uWEi8iqK.js → use-checkout-BRDfZp4Z.js} +8 -5
  7. package/dist/chunks/use-checkout-BRDfZp4Z.js.map +1 -0
  8. package/dist/chunks/{use-checkout-wHkKNkbK.cjs → use-checkout-MM-Ld0Ew.cjs} +7 -4
  9. package/dist/chunks/use-checkout-MM-Ld0Ew.cjs.map +1 -0
  10. package/dist/core/index.cjs +3 -1
  11. package/dist/core/index.cjs.map +1 -1
  12. package/dist/core/index.d.cts +18 -4
  13. package/dist/core/index.d.ts +18 -4
  14. package/dist/core/index.js +2 -2
  15. package/dist/next/index.cjs +12 -6
  16. package/dist/next/index.cjs.map +1 -1
  17. package/dist/next/index.d.cts +10 -3
  18. package/dist/next/index.d.ts +10 -3
  19. package/dist/next/index.js +14 -8
  20. package/dist/next/index.js.map +1 -1
  21. package/dist/next/payment-return.cjs +52 -0
  22. package/dist/next/payment-return.cjs.map +1 -1
  23. package/dist/next/payment-return.d.cts +16 -2
  24. package/dist/next/payment-return.d.ts +16 -2
  25. package/dist/next/payment-return.js +51 -1
  26. package/dist/next/payment-return.js.map +1 -1
  27. package/dist/next/server.cjs +10 -0
  28. package/dist/next/server.cjs.map +1 -0
  29. package/dist/next/server.d.cts +33 -0
  30. package/dist/next/server.d.ts +33 -0
  31. package/dist/next/server.js +4 -0
  32. package/dist/next/server.js.map +1 -0
  33. package/dist/react/index.cjs +2 -2
  34. package/dist/react/index.d.cts +3 -2
  35. package/dist/react/index.d.ts +3 -2
  36. package/dist/react/index.js +2 -2
  37. package/dist/server/index.cjs +205 -0
  38. package/dist/server/index.cjs.map +1 -0
  39. package/dist/server/index.d.cts +33 -0
  40. package/dist/server/index.d.ts +33 -0
  41. package/dist/server/index.js +203 -0
  42. package/dist/server/index.js.map +1 -0
  43. package/package.json +30 -2
  44. package/dist/chunks/labels-Cy05dLJx.cjs.map +0 -1
  45. package/dist/chunks/labels-Cysz2BgA.js.map +0 -1
  46. package/dist/chunks/use-checkout-uWEi8iqK.js.map +0 -1
  47. package/dist/chunks/use-checkout-wHkKNkbK.cjs.map +0 -1
@@ -106,7 +106,14 @@ interface CheckoutPaymentReturn {
106
106
  identifier: string;
107
107
  };
108
108
  params: Record<string, string>;
109
+ /**
110
+ * `callback` forwards gateway fields for verification. `status` is emitted
111
+ * by the SDK server handler after it has already verified the gateway POST,
112
+ * so the browser performs only an authoritative status read.
113
+ */
114
+ resolution?: PaymentReturnResolution;
109
115
  }
116
+ type PaymentReturnResolution = 'callback' | 'status';
110
117
  /** Search-param shape exposed by current Next.js App Router pages. */
111
118
  type PaymentReturnSearchParams = Record<string, string | string[] | undefined>;
112
119
  interface CheckoutConfig {
@@ -234,8 +241,8 @@ interface CheckoutActions {
234
241
  placeOrder(): Promise<void>;
235
242
  /** Rehydrate a failed gateway return and reopen a usable payment step. */
236
243
  retryPayment(): Promise<void>;
237
- /** Resolve a return from the payment gateway (query params from the URL). */
238
- resolvePaymentReturn(params: Record<string, string>): Promise<void>;
244
+ /** Resolve a gateway callback or a server-verified payment status return. */
245
+ resolvePaymentReturn(params: Record<string, string>, resolution?: PaymentReturnResolution): Promise<void>;
239
246
  reset(): void;
240
247
  }
241
248
 
@@ -499,4 +506,4 @@ interface SazitoProviderProps {
499
506
  declare function SazitoProvider({ client, children }: SazitoProviderProps): react_jsx_runtime.JSX.Element;
500
507
 
501
508
  export { Button, CheckoutProvider, ErrorBanner, Field, ProductPlaceholder, SazitoCheckout, SazitoCheckoutPage, SazitoProvider, SectionTitle, Spinner, useCheckout };
502
- export type { ButtonProps, CheckoutPaymentReturn, CheckoutProviderProps, EmptyCartOptions, ErrorBannerProps, FieldProps, PaymentReturnSearchParams, ProductPlaceholderProps, RenderButtonProps, RenderEmptyCartProps as RenderEmptyCartPageProps, RenderEmptyCartProps, RenderResultProps, SazitoCheckoutPageProps, SazitoCheckoutProps, SazitoProviderProps, SectionTitleProps, SpinnerProps };
509
+ export type { ButtonProps, CheckoutPaymentReturn, CheckoutProviderProps, EmptyCartOptions, ErrorBannerProps, FieldProps, PaymentReturnResolution, PaymentReturnSearchParams, ProductPlaceholderProps, RenderButtonProps, RenderEmptyCartProps as RenderEmptyCartPageProps, RenderEmptyCartProps, RenderResultProps, SazitoCheckoutPageProps, SazitoCheckoutProps, SazitoProviderProps, SectionTitleProps, SpinnerProps };
@@ -106,7 +106,14 @@ interface CheckoutPaymentReturn {
106
106
  identifier: string;
107
107
  };
108
108
  params: Record<string, string>;
109
+ /**
110
+ * `callback` forwards gateway fields for verification. `status` is emitted
111
+ * by the SDK server handler after it has already verified the gateway POST,
112
+ * so the browser performs only an authoritative status read.
113
+ */
114
+ resolution?: PaymentReturnResolution;
109
115
  }
116
+ type PaymentReturnResolution = 'callback' | 'status';
110
117
  /** Search-param shape exposed by current Next.js App Router pages. */
111
118
  type PaymentReturnSearchParams = Record<string, string | string[] | undefined>;
112
119
  interface CheckoutConfig {
@@ -234,8 +241,8 @@ interface CheckoutActions {
234
241
  placeOrder(): Promise<void>;
235
242
  /** Rehydrate a failed gateway return and reopen a usable payment step. */
236
243
  retryPayment(): Promise<void>;
237
- /** Resolve a return from the payment gateway (query params from the URL). */
238
- resolvePaymentReturn(params: Record<string, string>): Promise<void>;
244
+ /** Resolve a gateway callback or a server-verified payment status return. */
245
+ resolvePaymentReturn(params: Record<string, string>, resolution?: PaymentReturnResolution): Promise<void>;
239
246
  reset(): void;
240
247
  }
241
248
 
@@ -499,4 +506,4 @@ interface SazitoProviderProps {
499
506
  declare function SazitoProvider({ client, children }: SazitoProviderProps): react_jsx_runtime.JSX.Element;
500
507
 
501
508
  export { Button, CheckoutProvider, ErrorBanner, Field, ProductPlaceholder, SazitoCheckout, SazitoCheckoutPage, SazitoProvider, SectionTitle, Spinner, useCheckout };
502
- export type { ButtonProps, CheckoutPaymentReturn, CheckoutProviderProps, EmptyCartOptions, ErrorBannerProps, FieldProps, PaymentReturnSearchParams, ProductPlaceholderProps, RenderButtonProps, RenderEmptyCartProps as RenderEmptyCartPageProps, RenderEmptyCartProps, RenderResultProps, SazitoCheckoutPageProps, SazitoCheckoutProps, SazitoProviderProps, SectionTitleProps, SpinnerProps };
509
+ export type { ButtonProps, CheckoutPaymentReturn, CheckoutProviderProps, EmptyCartOptions, ErrorBannerProps, FieldProps, PaymentReturnResolution, PaymentReturnSearchParams, ProductPlaceholderProps, RenderButtonProps, RenderEmptyCartProps as RenderEmptyCartPageProps, RenderEmptyCartProps, RenderResultProps, SazitoCheckoutPageProps, SazitoCheckoutProps, SazitoProviderProps, SectionTitleProps, SpinnerProps };
@@ -1,10 +1,10 @@
1
1
  'use client';
2
2
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
3
3
  import { isValidElement, cloneElement, useMemo, useState, useRef, useEffect, useCallback } from 'react';
4
- import { u as useCheckout, b as useSazitoClient, C as CheckoutProvider } from '../chunks/use-checkout-uWEi8iqK.js';
5
- export { S as SazitoProvider } from '../chunks/use-checkout-uWEi8iqK.js';
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-Cysz2BgA.js';
7
- import { parsePaymentReturnUrl } from './payment-return.js';
4
+ import { u as useCheckout, b as useSazitoClient, C as CheckoutProvider } from '../chunks/use-checkout-BRDfZp4Z.js';
5
+ export { S as SazitoProvider } from '../chunks/use-checkout-BRDfZp4Z.js';
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-Cqrb2MwA.js';
7
+ import { parsePaymentReturnUrl, stripPaymentStatusReturn } from './payment-return.js';
8
8
  import '@sazito/client-sdk';
9
9
 
10
10
  /**
@@ -934,14 +934,15 @@ function SazitoCheckoutPage({ credentials, config, paymentReturn, paymentReturnP
934
934
  : undefined;
935
935
  const resolvedPaymentReturn = paymentReturn ?? detectedPaymentReturn;
936
936
  const returnParams = resolvedPaymentReturn?.params ?? paymentReturnParams;
937
+ const returnResolution = resolvedPaymentReturn?.resolution ?? 'callback';
937
938
  const isReturn = returnParams != null;
938
939
  const checkoutCredentials = resolvedPaymentReturn
939
940
  ? { ...credentials, payment: resolvedPaymentReturn.payment }
940
941
  : credentials;
941
942
  const client = useSazitoClient();
942
- 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, renderResult: renderResult, emptyCart: emptyCart })] }));
943
+ return (jsxs(CheckoutProvider, { client: client, credentials: checkoutCredentials, config: config, autoStart: !isReturn, children: [returnParams ? (jsx(ResolveReturn, { params: returnParams, resolution: returnResolution })) : null, jsx(SazitoCheckout, { theme: config?.theme, continueShoppingUrl: config?.continueShoppingUrl, className: className, renderNextButton: renderNextButton, renderBackButton: renderBackButton, renderEmptyCart: renderEmptyCart, renderResult: renderResult, emptyCart: emptyCart })] }));
943
944
  }
944
- function ResolveReturn({ params }) {
945
+ function ResolveReturn({ params, resolution }) {
945
946
  const { actions } = useCheckout();
946
947
  const resolvedKey = useRef(null);
947
948
  const paramsKey = JSON.stringify(Object.entries(params).sort(([a], [b]) => a.localeCompare(b)));
@@ -949,8 +950,13 @@ function ResolveReturn({ params }) {
949
950
  if (resolvedKey.current === paramsKey)
950
951
  return;
951
952
  resolvedKey.current = paramsKey;
952
- void actions.resolvePaymentReturn(params);
953
- }, [actions, params, paramsKey]);
953
+ void actions.resolvePaymentReturn(params, resolution);
954
+ if (typeof window !== 'undefined') {
955
+ const cleanUrl = stripPaymentStatusReturn(window.location.href);
956
+ if (cleanUrl)
957
+ window.history.replaceState(window.history.state, '', cleanUrl);
958
+ }
959
+ }, [actions, params, paramsKey, resolution]);
954
960
  return null;
955
961
  }
956
962