SazitoSazito SDKv1.2.2
API Reference

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.create must 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.getMethods sends the current invoice identifier to /api/v2/payments/list.
  • /api/v2/payments/{id}/process_payment_step behavior depends on exact Content-Type.
  • JSON mode must use exact application/json when top-level paymentIdentifier is 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?).

ParameterTypeRequiredDescription
paymentTypeIdnumberRequiredPayment method ID (PaymentMethod.id).
optionsRequestOptionsOptionalPer-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.

FieldTypeRequiredDescription
input.paymentIdentifierstringOptionalOverrides stored payment identifier in JSON mode.
input.idnumberOptionalOptional payment ID override in JSON body.
input.payloadRecord<string, any>OptionalGateway-specific JSON payload.
input.tatokenstringOptionalGateway/session token.
input.trackingDataRecord<string, any>OptionalTracking payload.
input.isFailedstringOptionalMark payment failed ("true").
input.imageUrlstringOptionalUploaded payment proof URL.
input.codestringOptionalVerification code (e.g., card-to-card).
optionsRequestOptionsOptionalPer-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.

FieldTypeRequiredDescription
inputFormData | Record<string, string | number | boolean | null | undefined>RequiredForm fields sent with non-JSON content type.
optionsRequestOptionsOptionalPer-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

FieldTypeRequiredDescription
idnumberRequiredPayment method ID.
codePaymentGatewayRequiredGateway code enum (from reference_code).
titlestringRequiredDisplay title (English).
titleFastringRequiredDisplay title (Persian).
descriptionstring | nullRequiredMethod description; often null.
paymentSubTypenumber | nullRequiredPayment sub-type id; null when absent.
ordernumberRequiredDisplay order.
isDefaultbooleanRequiredDefault method flag.

Payment Action

FieldTypeRequiredDescription
action'POST' | 'REDIRECT' | 'UPLOAD' | 'pending' | 'showOrder' | 'FAIL' | 'StockViolated'RequiredNext action type.
addressstringOptionalRedirect/post URL.
payloadRecord<string, any>OptionalPOST payload for gateway.
orderOrderOptionalFinalized order when action is showOrder.
timenumberOptionalUpload deadline timestamp/seconds.
messagestringOptionalError/action message.

Known errors

TypeWhen it happens
validationMissing 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

FieldTypeRequired
idnumberRequired
codePaymentGatewayRequired
titlestringRequired
titleFastringRequired
descriptionstring | nullRequired
paymentSubTypenumber | nullRequired
ordernumberRequired
isDefaultbooleanRequired

Payment

Source: src/types/payment.ts

FieldTypeRequired
idnumberRequired
identifierstringRequired
paymentType{ id?: number; code: PaymentGateway; }Required
paymentType.idnumberOptional
paymentType.codePaymentGatewayRequired
amountnumberRequired

PaymentAction

Source: src/types/payment.ts

FieldTypeRequired
action'POST' | 'REDIRECT' | 'UPLOAD' | 'pending' | 'showOrder' | 'StockViolated' | 'FAIL'Required
addressstringOptional
payloadRecord<string, any>Optional
orderOrderOptional
timenumberOptional
messagestringOptional

PaymentStepInput

Source: src/types/payment.ts

FieldTypeRequired
isFailedstringOptional
imageUrlstringOptional
codestringOptional

On this page