Skip to main content

Payments API

The Payments API allows you to create and manage payment intents and transactions.

Methods

createPaymentIntent

Create a new payment intent.

const intent = await zenpays.payments.createPaymentIntent({
amount: 1000,
currency: 'USD',
description: 'Order #123',
customerDetails: {
name: 'John Doe',
email: 'john@example.com',
},
metadata: {
orderId: 'order_123',
},
})

Parameters:

FieldTypeRequiredDescription
amountnumberYesAmount in smallest currency unit
currencystringYesThree-letter currency code
descriptionstringNoPayment description
customerDetailsCustomerDetailsNoCustomer information
paymentMethodPaymentMethodTypeNoPreferred payment method
metadataRecord<string, unknown>NoCustom metadata
expiresInnumberNoExpiration time in seconds
successUrlstringNoRedirect URL on success
cancelUrlstringNoRedirect URL on cancel

Returns: CreatePaymentIntentResponse


getPaymentIntent

Get payment intent details (authenticated).

const intent = await zenpays.payments.getPaymentIntent('pi_xxx')

Returns: PaymentIntent


getPublicPaymentIntent

Get payment intent details (public, no authentication required).

const intent = await zenpays.payments.getPublicPaymentIntent('pi_xxx', token?)

Returns: PaymentIntent


confirmPayment

Confirm a payment intent with payment details.

const result = await zenpays.payments.confirmPayment('pi_xxx', {
customerDetails: {
name: 'John Doe',
email: 'john@example.com',
address: { country: 'US' },
},
paymentMethodDetails: {
type: 'credit_card',
cardNumber: '4111111111111111',
expiryMonth: '12',
expiryYear: '2025',
cvv: '123',
},
})

Parameters:

FieldTypeRequiredDescription
customerDetailsCustomerDetailsYesCustomer information
deviceInfoDeviceInfoNoDevice fingerprint data
paymentMethodDetailsPaymentMethodDetailsNoPayment method details
paymentRailIdstringNoSpecific payment rail to use
quoteIdstringNoQuote ID for crypto payments

Returns: ConfirmPaymentResponse


processPayment

Process a payment directly.

const result = await zenpays.payments.processPayment('pi_xxx', {
customerDetails: { ... },
paymentMethodDetails: { ... },
})

cancelPaymentIntent

Cancel a payment intent.

const intent = await zenpays.payments.cancelPaymentIntent('pi_xxx')

updateIntelligence

Update device intelligence for fraud prevention.

await zenpays.payments.updateIntelligence('pi_xxx', {
userAgent: navigator.userAgent,
screenWidth: window.screen.width,
screenHeight: window.screen.height,
deviceFingerprint: 'fp_xxx',
})

getTransaction

Get a transaction by ID.

const transaction = await zenpays.payments.getTransaction('txn_xxx')

Returns: Transaction


getTransactionsByIntent

Get all transactions for a payment intent.

const transactions = await zenpays.payments.getTransactionsByIntent('pi_xxx')

Returns: Transaction[]


listTransactions

List transactions with filters.

const { data, total } = await zenpays.payments.listTransactions({
status: 'succeeded',
from: '2024-01-01',
to: '2024-12-31',
limit: 50,
})

Filters:

FieldTypeDescription
statusPaymentStatus | PaymentStatus[]Filter by status
paymentMethodPaymentMethodType | PaymentMethodType[]Filter by payment method
currencystringFilter by currency
customerIdstringFilter by customer
minAmountnumberMinimum amount
maxAmountnumberMaximum amount
fromstring | DateStart date
tostring | DateEnd date

Returns: PaginatedResponse<Transaction>


getTransactionAnalytics

Get transaction analytics.

const analytics = await zenpays.payments.getTransactionAnalytics('30d')

Returns: TransactionAnalytics


exportTransactions

Export transactions to CSV or XLSX.

const downloadUrl = await zenpays.payments.exportTransactions(
{ status: 'succeeded', from: '2024-01-01' },
'csv'
)

Types

PaymentIntent

interface PaymentIntent {
id: string
merchantId: string
merchantName?: string
merchantLogo?: string
description?: string
amount: number
currency: string
status: PaymentStatus
customerName?: string
customerEmail?: string
customerPhone?: string
processingFee?: number
expiresAt?: string
metadata?: Record<string, unknown>
createdAt?: string
updatedAt?: string
}

PaymentStatus

type PaymentStatus
= | 'pending'
| 'processing'
| 'succeeded'
| 'failed'
| 'cancelled'
| 'expired'
| 'confirmed'

PaymentMethodType

type PaymentMethodType
= | 'crypto'
| 'credit_card'
| 'debit_card'
| 'net_banking'
| 'upi'
| 'wallet'
| 'bank_transfer'
| 'mobile_money'