@sazito/checkout 0.3.0 → 0.4.0
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 +38 -0
- package/dist/chunks/{labels-3zH04p3y.cjs → labels-CnPllzhT.cjs} +15 -2
- package/dist/chunks/labels-CnPllzhT.cjs.map +1 -0
- package/dist/chunks/{labels-BdxqgReM.js → labels-e8w4zRbg.js} +15 -2
- package/dist/chunks/labels-e8w4zRbg.js.map +1 -0
- package/dist/chunks/{use-checkout-Bh4tXxFJ.js → use-checkout-BM810__v.js} +5 -3
- package/dist/chunks/use-checkout-BM810__v.js.map +1 -0
- package/dist/chunks/{use-checkout-DGP2xazd.cjs → use-checkout-DPtLgxlA.cjs} +5 -3
- package/dist/chunks/use-checkout-DPtLgxlA.cjs.map +1 -0
- package/dist/core/index.cjs +3 -1
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +27 -3
- package/dist/core/index.d.ts +27 -3
- package/dist/core/index.js +2 -1
- package/dist/core/index.js.map +1 -1
- package/dist/next/index.cjs +15 -7
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +24 -3
- package/dist/next/index.d.ts +24 -3
- package/dist/next/index.js +16 -8
- package/dist/next/index.js.map +1 -1
- package/dist/next/payment-return.cjs +40 -0
- package/dist/next/payment-return.cjs.map +1 -0
- package/dist/next/payment-return.d.cts +26 -0
- package/dist/next/payment-return.d.ts +26 -0
- package/dist/next/payment-return.js +38 -0
- package/dist/next/payment-return.js.map +1 -0
- package/dist/react/index.cjs +2 -2
- package/dist/react/index.d.cts +9 -1
- package/dist/react/index.d.ts +9 -1
- package/dist/react/index.js +2 -2
- package/package.json +15 -1
- package/dist/chunks/labels-3zH04p3y.cjs.map +0 -1
- package/dist/chunks/labels-BdxqgReM.js.map +0 -1
- package/dist/chunks/use-checkout-Bh4tXxFJ.js.map +0 -1
- package/dist/chunks/use-checkout-DGP2xazd.cjs.map +0 -1
package/dist/next/index.d.cts
CHANGED
|
@@ -94,14 +94,32 @@ interface CheckoutCredentials {
|
|
|
94
94
|
id: number;
|
|
95
95
|
identifier: string;
|
|
96
96
|
};
|
|
97
|
+
payment?: {
|
|
98
|
+
id: number;
|
|
99
|
+
identifier: string;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** Normalized payment callback data accepted by `SazitoCheckoutPage`. */
|
|
103
|
+
interface CheckoutPaymentReturn {
|
|
104
|
+
payment: {
|
|
105
|
+
id: number;
|
|
106
|
+
identifier: string;
|
|
107
|
+
};
|
|
108
|
+
params: Record<string, string>;
|
|
97
109
|
}
|
|
110
|
+
/** Search-param shape exposed by current Next.js App Router pages. */
|
|
111
|
+
type PaymentReturnSearchParams = Record<string, string | string[] | undefined>;
|
|
98
112
|
interface CheckoutConfig {
|
|
99
113
|
locale?: CheckoutLocale;
|
|
100
114
|
direction?: CheckoutDirection;
|
|
101
115
|
theme?: CheckoutTheme;
|
|
102
116
|
/** URL for the "continue shopping" / back-to-store action. */
|
|
103
117
|
continueShoppingUrl?: string;
|
|
104
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
* Reserved for gateways that support a caller-provided return URL.
|
|
120
|
+
* Current Sazito legacy callbacks use their generated nested result path.
|
|
121
|
+
* @deprecated Use an optional catch-all route with `parsePaymentReturn`.
|
|
122
|
+
*/
|
|
105
123
|
returnUrl?: string;
|
|
106
124
|
/** Pending-payment poll interval in ms (default 15000). */
|
|
107
125
|
pollIntervalMs?: number;
|
|
@@ -411,6 +429,9 @@ declare function ErrorBanner({ message, asChild, children, className }: ErrorBan
|
|
|
411
429
|
interface SazitoCheckoutPageProps {
|
|
412
430
|
credentials?: CheckoutCredentials;
|
|
413
431
|
config?: CheckoutConfig;
|
|
432
|
+
/** Parsed nested gateway callback. Prefer `parsePaymentReturn()` to create it. */
|
|
433
|
+
paymentReturn?: CheckoutPaymentReturn;
|
|
434
|
+
/** @deprecated Prefer `paymentReturn`; retained for query-only callbacks. */
|
|
414
435
|
paymentReturnParams?: Record<string, string>;
|
|
415
436
|
className?: string;
|
|
416
437
|
renderNextButton?: (props: RenderButtonProps) => React.ReactNode;
|
|
@@ -418,7 +439,7 @@ interface SazitoCheckoutPageProps {
|
|
|
418
439
|
renderEmptyCart?: (props: RenderEmptyCartProps) => React.ReactNode;
|
|
419
440
|
emptyCart?: EmptyCartOptions;
|
|
420
441
|
}
|
|
421
|
-
declare function SazitoCheckoutPage({ credentials, config, paymentReturnParams, className, renderNextButton, renderBackButton, renderEmptyCart, emptyCart, }: SazitoCheckoutPageProps): react_jsx_runtime.JSX.Element;
|
|
442
|
+
declare function SazitoCheckoutPage({ credentials, config, paymentReturn, paymentReturnParams, className, renderNextButton, renderBackButton, renderEmptyCart, emptyCart, }: SazitoCheckoutPageProps): react_jsx_runtime.JSX.Element;
|
|
422
443
|
|
|
423
444
|
interface CheckoutProviderProps {
|
|
424
445
|
/** Override the SazitoProvider client for this checkout instance only. */
|
|
@@ -451,4 +472,4 @@ interface SazitoProviderProps {
|
|
|
451
472
|
declare function SazitoProvider({ client, children }: SazitoProviderProps): react_jsx_runtime.JSX.Element;
|
|
452
473
|
|
|
453
474
|
export { Button, CheckoutProvider, ErrorBanner, Field, ProductPlaceholder, SazitoCheckout, SazitoCheckoutPage, SazitoProvider, SectionTitle, Spinner, useCheckout };
|
|
454
|
-
export type { ButtonProps, CheckoutProviderProps, EmptyCartOptions, ErrorBannerProps, FieldProps, ProductPlaceholderProps, RenderButtonProps, RenderEmptyCartProps as RenderEmptyCartPageProps, RenderEmptyCartProps, SazitoCheckoutPageProps, SazitoCheckoutProps, SazitoProviderProps, SectionTitleProps, SpinnerProps };
|
|
475
|
+
export type { ButtonProps, CheckoutPaymentReturn, CheckoutProviderProps, EmptyCartOptions, ErrorBannerProps, FieldProps, PaymentReturnSearchParams, ProductPlaceholderProps, RenderButtonProps, RenderEmptyCartProps as RenderEmptyCartPageProps, RenderEmptyCartProps, SazitoCheckoutPageProps, SazitoCheckoutProps, SazitoProviderProps, SectionTitleProps, SpinnerProps };
|
package/dist/next/index.d.ts
CHANGED
|
@@ -94,14 +94,32 @@ interface CheckoutCredentials {
|
|
|
94
94
|
id: number;
|
|
95
95
|
identifier: string;
|
|
96
96
|
};
|
|
97
|
+
payment?: {
|
|
98
|
+
id: number;
|
|
99
|
+
identifier: string;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** Normalized payment callback data accepted by `SazitoCheckoutPage`. */
|
|
103
|
+
interface CheckoutPaymentReturn {
|
|
104
|
+
payment: {
|
|
105
|
+
id: number;
|
|
106
|
+
identifier: string;
|
|
107
|
+
};
|
|
108
|
+
params: Record<string, string>;
|
|
97
109
|
}
|
|
110
|
+
/** Search-param shape exposed by current Next.js App Router pages. */
|
|
111
|
+
type PaymentReturnSearchParams = Record<string, string | string[] | undefined>;
|
|
98
112
|
interface CheckoutConfig {
|
|
99
113
|
locale?: CheckoutLocale;
|
|
100
114
|
direction?: CheckoutDirection;
|
|
101
115
|
theme?: CheckoutTheme;
|
|
102
116
|
/** URL for the "continue shopping" / back-to-store action. */
|
|
103
117
|
continueShoppingUrl?: string;
|
|
104
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
* Reserved for gateways that support a caller-provided return URL.
|
|
120
|
+
* Current Sazito legacy callbacks use their generated nested result path.
|
|
121
|
+
* @deprecated Use an optional catch-all route with `parsePaymentReturn`.
|
|
122
|
+
*/
|
|
105
123
|
returnUrl?: string;
|
|
106
124
|
/** Pending-payment poll interval in ms (default 15000). */
|
|
107
125
|
pollIntervalMs?: number;
|
|
@@ -411,6 +429,9 @@ declare function ErrorBanner({ message, asChild, children, className }: ErrorBan
|
|
|
411
429
|
interface SazitoCheckoutPageProps {
|
|
412
430
|
credentials?: CheckoutCredentials;
|
|
413
431
|
config?: CheckoutConfig;
|
|
432
|
+
/** Parsed nested gateway callback. Prefer `parsePaymentReturn()` to create it. */
|
|
433
|
+
paymentReturn?: CheckoutPaymentReturn;
|
|
434
|
+
/** @deprecated Prefer `paymentReturn`; retained for query-only callbacks. */
|
|
414
435
|
paymentReturnParams?: Record<string, string>;
|
|
415
436
|
className?: string;
|
|
416
437
|
renderNextButton?: (props: RenderButtonProps) => React.ReactNode;
|
|
@@ -418,7 +439,7 @@ interface SazitoCheckoutPageProps {
|
|
|
418
439
|
renderEmptyCart?: (props: RenderEmptyCartProps) => React.ReactNode;
|
|
419
440
|
emptyCart?: EmptyCartOptions;
|
|
420
441
|
}
|
|
421
|
-
declare function SazitoCheckoutPage({ credentials, config, paymentReturnParams, className, renderNextButton, renderBackButton, renderEmptyCart, emptyCart, }: SazitoCheckoutPageProps): react_jsx_runtime.JSX.Element;
|
|
442
|
+
declare function SazitoCheckoutPage({ credentials, config, paymentReturn, paymentReturnParams, className, renderNextButton, renderBackButton, renderEmptyCart, emptyCart, }: SazitoCheckoutPageProps): react_jsx_runtime.JSX.Element;
|
|
422
443
|
|
|
423
444
|
interface CheckoutProviderProps {
|
|
424
445
|
/** Override the SazitoProvider client for this checkout instance only. */
|
|
@@ -451,4 +472,4 @@ interface SazitoProviderProps {
|
|
|
451
472
|
declare function SazitoProvider({ client, children }: SazitoProviderProps): react_jsx_runtime.JSX.Element;
|
|
452
473
|
|
|
453
474
|
export { Button, CheckoutProvider, ErrorBanner, Field, ProductPlaceholder, SazitoCheckout, SazitoCheckoutPage, SazitoProvider, SectionTitle, Spinner, useCheckout };
|
|
454
|
-
export type { ButtonProps, CheckoutProviderProps, EmptyCartOptions, ErrorBannerProps, FieldProps, ProductPlaceholderProps, RenderButtonProps, RenderEmptyCartProps as RenderEmptyCartPageProps, RenderEmptyCartProps, SazitoCheckoutPageProps, SazitoCheckoutProps, SazitoProviderProps, SectionTitleProps, SpinnerProps };
|
|
475
|
+
export type { ButtonProps, CheckoutPaymentReturn, CheckoutProviderProps, EmptyCartOptions, ErrorBannerProps, FieldProps, PaymentReturnSearchParams, ProductPlaceholderProps, RenderButtonProps, RenderEmptyCartProps as RenderEmptyCartPageProps, RenderEmptyCartProps, SazitoCheckoutPageProps, SazitoCheckoutProps, SazitoProviderProps, SectionTitleProps, SpinnerProps };
|
package/dist/next/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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-
|
|
5
|
-
export { S as SazitoProvider } from '../chunks/use-checkout-
|
|
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-
|
|
4
|
+
import { u as useCheckout, b as useSazitoClient, C as CheckoutProvider } from '../chunks/use-checkout-BM810__v.js';
|
|
5
|
+
export { S as SazitoProvider } from '../chunks/use-checkout-BM810__v.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-e8w4zRbg.js';
|
|
7
7
|
import '@sazito/client-sdk';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -847,17 +847,25 @@ function SazitoCheckout({ theme, continueShoppingUrl, className, renderNextButto
|
|
|
847
847
|
return (jsxs("div", { className: `szc-root${className ? ` ${className}` : ''}`, dir: direction, style: themeVars(theme), children: [mobileHead, jsx(Stepper, {}), bootstrapping ? (jsx(CheckoutLoading, { label: t.loading })) : fatal ? (jsx(ErrorBanner, { message: error.message })) : isResult ? (jsx("div", { className: "szc-result-wrap", children: jsx(ResultStep, { continueShoppingUrl: continueShoppingUrl }) })) : (jsx(Fragment, { children: jsxs("div", { className: `szc-layout${cartEmpty ? ' szc-layout--full' : ''}`, children: [jsxs("main", { className: "szc-main", children: [error && !emptyCartError ? jsx(ErrorBanner, { message: error.message }) : null, step === 'cart' ? (jsx(CartStep, { continueShoppingUrl: continueShoppingUrl, emptyCart: emptyCart, renderEmpty: renderEmptyCart })) : null, step === 'shipping' ? jsx(ShippingStep, {}) : null, step === 'payment' ? jsx(PaymentStep, {}) : null, actionsVisible && backButtonNode ? (jsx("div", { className: "szc-back-row", children: backButtonNode })) : null] }), !cartEmpty ? (jsxs("div", { className: "szc-side", children: [jsx(OrderSummary, {}), actionsVisible ? jsx("div", { className: "szc-side__cta", children: nextButtonNode }) : null] })) : null] }) })), actionsVisible ? (jsx("div", { className: "szc-footer-bar", children: jsxs("div", { className: "szc-footer", children: [jsxs("div", { className: "szc-footer__total", children: [jsx("span", { className: "szc-footer__total-label", children: t.total }), jsx("span", { className: "szc-footer__total-value", children: money(summary.total) })] }), jsx("div", { className: "szc-footer__actions", children: nextButtonNode })] }) })) : null] }));
|
|
848
848
|
}
|
|
849
849
|
|
|
850
|
-
function SazitoCheckoutPage({ credentials, config, paymentReturnParams, className, renderNextButton, renderBackButton, renderEmptyCart, emptyCart, }) {
|
|
851
|
-
const
|
|
850
|
+
function SazitoCheckoutPage({ credentials, config, paymentReturn, paymentReturnParams, className, renderNextButton, renderBackButton, renderEmptyCart, emptyCart, }) {
|
|
851
|
+
const returnParams = paymentReturn?.params ?? paymentReturnParams;
|
|
852
|
+
const isReturn = returnParams != null;
|
|
853
|
+
const checkoutCredentials = paymentReturn
|
|
854
|
+
? { ...credentials, payment: paymentReturn.payment }
|
|
855
|
+
: credentials;
|
|
852
856
|
const client = useSazitoClient();
|
|
853
|
-
return (jsxs(CheckoutProvider, { client: client, credentials:
|
|
857
|
+
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 })] }));
|
|
854
858
|
}
|
|
855
859
|
function ResolveReturn({ params }) {
|
|
856
860
|
const { actions } = useCheckout();
|
|
861
|
+
const resolvedKey = useRef(null);
|
|
862
|
+
const paramsKey = JSON.stringify(Object.entries(params).sort(([a], [b]) => a.localeCompare(b)));
|
|
857
863
|
useEffect(() => {
|
|
864
|
+
if (resolvedKey.current === paramsKey)
|
|
865
|
+
return;
|
|
866
|
+
resolvedKey.current = paramsKey;
|
|
858
867
|
void actions.resolvePaymentReturn(params);
|
|
859
|
-
|
|
860
|
-
}, []);
|
|
868
|
+
}, [actions, params, paramsKey]);
|
|
861
869
|
return null;
|
|
862
870
|
}
|
|
863
871
|
|