Payments
Checkout payment APIs for gateway selection, payment creation, verification steps, and final order action.
Module role in sales flow
payments is the final checkout module before order completion.
- Depends on invoice credentials (
invoices.createmust run first). - Supports redirect/post gateways and manual step-based flows like card-to-card upload/code verification.
- When payment reaches
showOrder, SDK runs checkout finalization automatically.
V2 contract notes
payments.getMethodssends the current invoice identifier to/api/v2/payments/list./api/v2/payments/{id}/process_payment_stepbehavior depends on exactContent-Type.- JSON mode must use exact
application/jsonwhen top-levelpaymentIdentifieris needed. - Use form mode for gateways that post callback/form payloads.
Methods
Get Methods
Use: payments.getMethods(options?).
Returns available payment methods for current invoice credentials.
const methodsRes = await client.payments.getMethods();Create
Use: payments.create(paymentTypeId, options?).
| Parameter | Type | Required | Description |
|---|---|---|---|
paymentTypeId | number | Required | Payment method ID (PaymentMethod.id). |
options | RequestOptions | Optional | Per-request controls. |
Returns: SazitoResponse<Payment>.
const methodsRes = await client.payments.getMethods();
if (methodsRes.data?.length) {
await client.payments.create(methodsRes.data[0].id);
}Initialize
Use: payments.initialize(options?).
Initializes current payment and returns next action.
Returns: SazitoResponse<PaymentAction>.
When payment verification succeeds (action === 'showOrder'), the SDK automatically
calls POST /api/v1/pinch/order as part of checkout completion.
const actionRes = await client.payments.initialize();
if (actionRes.data?.action === 'REDIRECT') {
console.log('Redirect to:', actionRes.data.address);
}Process Step
Use: payments.processStep(input, options?).
Use this for JSON-mode step requests (commonly cardtocardpayment) after create/initialize.
| Field | Type | Required | Description |
|---|---|---|---|
input.paymentIdentifier | string | Optional | Overrides stored payment identifier in JSON mode. |
input.id | number | Optional | Optional payment ID override in JSON body. |
input.payload | Record<string, any> | Optional | Gateway-specific JSON payload. |
input.tatoken | string | Optional | Gateway/session token. |
input.trackingData | Record<string, any> | Optional | Tracking payload. |
input.isFailed | string | Optional | Mark payment failed ("true"). |
input.imageUrl | string | Optional | Uploaded payment proof URL. |
input.code | string | Optional | Verification code (e.g., card-to-card). |
options | RequestOptions | Optional | Per-request controls. |
const cardToCardStep = await client.payments.processStep({
imageUrl: 'https://cdn.example.com/payment-proof.png',
code: '894512',
});Process Step (Form Mode)
Use: payments.processStepForm(input, options?).
Use this when gateway flow requires non-JSON form payload handling for
/api/v2/payments/{id}/process_payment_step.
| Field | Type | Required | Description |
|---|---|---|---|
input | FormData | Record<string, string | number | boolean | null | undefined> | Required | Form fields sent with non-JSON content type. |
options | RequestOptions | Optional | Per-request controls. |
const stepRes = await client.payments.processStepForm({
code: '894512',
imageUrl: 'https://cdn.example.com/payment-proof.png',
});Poll Until Settled
Use: payments.pollUntilSettled(options?, intervalMs?).
Polls payment state via process_payment_step every 15 seconds by default until action !== 'pending'.
const finalAction = await client.payments.pollUntilSettled(undefined, 5000);Clear Payment
Use: payments.clearPayment().
Clears persisted payment credentials.
client.payments.clearPayment();Response key fields
Payment Method
| Field | Type | Required | Description |
|---|---|---|---|
id | number | Required | Payment method ID. |
code | PaymentGateway | Required | Gateway code enum (from reference_code). |
title | string | Required | Display title (English). |
titleFa | string | Required | Display title (Persian). |
description | string | null | Required | Method description; often null. |
paymentSubType | number | null | Required | Payment sub-type id; null when absent. |
order | number | Required | Display order. |
isDefault | boolean | Required | Default method flag. |
Payment Action
| Field | Type | Required | Description |
|---|---|---|---|
action | 'POST' | 'REDIRECT' | 'UPLOAD' | 'pending' | 'showOrder' | 'FAIL' | 'StockViolated' | Required | Next action type. |
address | string | Optional | Redirect/post URL. |
payload | Record<string, any> | Optional | POST payload for gateway. |
order | Order | Optional | Finalized order when action is showOrder. |
time | number | Optional | Upload deadline timestamp/seconds. |
message | string | Optional | Error/action message. |
Known errors
| Type | When it happens |
|---|---|
validation | Missing invoice/payment credentials. |
Examples
// app/lib/sazito-client.ts
import { createSazitoClient } from '@sazito/client-sdk';
export const sazito = createSazitoClient({
domain: process.env.NEXT_PUBLIC_SAZITO_DOMAIN!,
});// app/[lang]/(home)/page.tsx
'use client';
import { useEffect, useState } from 'react';
import { sazito } from '@/app/lib/sazito-client';
export default function Example() {
const [data, setData] = useState<any>(null);
useEffect(() => {
(async () => {
await sazito.cart.addItem(12001, 1);
await sazito.invoices.create();
const methods = await sazito.payments.getMethods();
if (!methods.data?.length) {
setData({ message: 'No payment methods available' });
return;
}
await sazito.payments.create(methods.data[0].id);
const action = await sazito.payments.initialize();
setData(action.data ?? null);
})();
}, []);
return <pre>{JSON.stringify(data, null, 2)}</pre>;
}Type Details
The following tables are generated from SDK TypeScript types and include nested object fields.
PaymentMethod
Source: src/types/payment.ts
| Field | Type | Required |
|---|---|---|
id | number | Required |
code | PaymentGateway | Required |
title | string | Required |
titleFa | string | Required |
description | string | null | Required |
paymentSubType | number | null | Required |
order | number | Required |
isDefault | boolean | Required |
Payment
Source: src/types/payment.ts
| Field | Type | Required |
|---|---|---|
id | number | Required |
identifier | string | Required |
paymentType | { id?: number; code: PaymentGateway; } | Required |
paymentType.id | number | Optional |
paymentType.code | PaymentGateway | Required |
amount | number | Required |
PaymentAction
Source: src/types/payment.ts
| Field | Type | Required |
|---|---|---|
action | 'POST' | 'REDIRECT' | 'UPLOAD' | 'pending' | 'showOrder' | 'StockViolated' | 'FAIL' | Required |
address | string | Optional |
payload | Record<string, any> | Optional |
order | Order | Optional |
time | number | Optional |
message | string | Optional |
PaymentStepInput
Source: src/types/payment.ts
| Field | Type | Required |
|---|---|---|
isFailed | string | Optional |
imageUrl | string | Optional |
code | string | Optional |