UNPKG

zarinpal-checkout

Version:

Type-safe ZarinPal checkout client for Node.js with modern tooling and backwards-compatible API methods.

110 lines (106 loc) 3.76 kB
type Currency = 'IRR' | 'IRT'; interface PaymentRequestInput { Amount: number; CallbackURL: string; Description: string; Email?: string; Mobile?: string; } interface PaymentRequestResponse { status: number; authority: string; url: string; } interface PaymentVerificationInput { Amount: number; Authority: string; } interface PaymentVerificationResponse { status: number; message: string; cardHash?: string; cardPan?: string; refId?: number; feeType?: string; fee?: number; } interface UnverifiedTransactionsResponse { code: number; message: string; authorities: string[]; } interface RefreshAuthorityInput { Authority: string; Expire: number; } interface RefreshAuthorityResponse { code: number; message: string; } interface ZarinPalError { errors: { code: number; message: string; validations?: Record<string, string[]>; }; } interface HttpRequestConfig { url: string; method: 'POST'; data: unknown; } interface HttpResponse<T = unknown> { data: T; } interface HttpClient { request: <T = unknown>(config: HttpRequestConfig) => Promise<HttpResponse<T>>; } interface DefaultHttpClientOptions { timeoutMs?: number; headers?: Record<string, string>; } interface ZarinPalClientOptions { sandbox?: boolean; currency?: Currency; timeoutMs?: number; requestConfig?: Omit<DefaultHttpClientOptions, 'timeoutMs'>; /** @deprecated Use requestConfig instead. */ axiosConfig?: Omit<DefaultHttpClientOptions, 'timeoutMs'>; httpClient?: HttpClient; } interface ZarinPalModule { version: string; create: (merchantId: string, sandbox?: boolean, currency?: Currency) => ZarinPal; createWithOptions: (merchantId: string, options?: ZarinPalClientOptions) => ZarinPal; } interface ZarinPal { readonly merchant: string; readonly sandbox: boolean; readonly currency: Currency; PaymentRequest(input: PaymentRequestInput): Promise<PaymentRequestResponse>; PaymentVerification(input: PaymentVerificationInput): Promise<PaymentVerificationResponse>; UnverifiedTransactions(): Promise<UnverifiedTransactionsResponse>; RefreshAuthority(input: RefreshAuthorityInput): Promise<RefreshAuthorityResponse>; TokenBeautifier(token: string): string[]; } declare class ZarinPalCheckout { readonly merchant: string; readonly sandbox: boolean; readonly currency: Currency; private readonly client; constructor(merchantId: string, options?: ZarinPalClientOptions); PaymentRequest(input: PaymentRequestInput): Promise<PaymentRequestResponse>; PaymentVerification(input: PaymentVerificationInput): Promise<PaymentVerificationResponse>; UnverifiedTransactions(): Promise<UnverifiedTransactionsResponse>; RefreshAuthority(input: RefreshAuthorityInput): Promise<RefreshAuthorityResponse>; TokenBeautifier(token: string): string[]; private getApiBaseUrl; private getStartPayUrl; private request; } declare const version = "1.0.0"; declare const createWithOptions: (merchantId: string, options?: ZarinPalClientOptions) => ZarinPalCheckout; declare const create: (merchantId: string, sandbox?: boolean, currency?: Currency) => ZarinPalCheckout; declare const ZarinpalCheckout: ZarinPalModule; export { ZarinPalCheckout, create, createWithOptions, ZarinpalCheckout as default, version }; export type { Currency, DefaultHttpClientOptions, HttpClient, HttpRequestConfig, HttpResponse, PaymentRequestInput, PaymentRequestResponse, PaymentVerificationInput, PaymentVerificationResponse, RefreshAuthorityInput, RefreshAuthorityResponse, UnverifiedTransactionsResponse, ZarinPal, ZarinPalClientOptions, ZarinPalError, ZarinPalModule };