Overview
The Transaction class provides methods for interacting with Paystack’s Transaction API. This module allows you to initialize transactions, verify payments, list transactions, charge saved authorizations, and more.
Methods
initialize
Initializes a transaction from your backend.
async initialize ( transaction : TxnInitializeInput ): Promise < TxnInitializeSuccess | GenericError >
transaction
TxnInitializeInput
required
The transaction details to initialize. Amount to charge (in kobo for NGN, pesewas for GHS, cents for ZAR and USD)
currency
'NGN' | 'USD' | 'GHS' | 'ZAR' | 'KES' | 'XOF'
Currency in which amount should be charged (defaults to NGN)
Unique transaction reference. Only alphanumeric characters allowed
Fully qualified URL to redirect to when transaction is completed
If transaction is to create a subscription, provide plan code here
Number of invoices to raise during subscription
Stringified JSON object of custom data
An array of payment channels to control what channels you want to make available to the user. Available channels: card, bank, ussd, qr, mobile_money, bank_transfer, eft, apple_pay
The split code of the transaction split
The code for the subaccount that owns the payment
A flat fee to charge the subaccount for this transaction
Who bears Paystack charges
URL to redirect user to for payment
Access code for the transaction
Unique reference for this transaction
Example Usage:
const { data , error } = await paystack . transaction . initialize ({
amount: "20000" ,
email: "customer@email.com" ,
currency: "NGN" ,
reference: "unique-reference-123" ,
});
if ( error ) {
console . error ( "Transaction initialization failed:" , error );
} else {
console . log ( "Redirect user to:" , data . authorization_url );
}
verify
Confirms the status of a transaction.
async verify ( reference : string ): Promise < TxnVerifySuccess | GenericError >
The transaction reference to verify
Transaction status (success, failed, abandoned, etc.)
Amount charged in kobo/cents
Customer information object
Authorization details (for card payments)
Custom metadata passed during initialization
ISO datetime when payment was made
ISO datetime when transaction was created
Example Usage:
const { data , error } = await paystack . transaction . verify ( "reference-123" );
if ( error ) {
console . error ( "Verification failed:" , error );
} else if ( data . status === "success" ) {
console . log ( "Payment successful:" , data );
}
list
Lists transactions carried out on your integration.
async list ( input : TxnListInput ): Promise < TxnListSuccess | GenericError >
Query parameters for listing transactions. Number of records to fetch per page (defaults to 50)
Page number to retrieve (defaults to 1)
status
'success' | 'failed' | 'abandoned'
Filter by transaction status
Start date for date range filter
End date for date range filter (ISO datetime)
Array of transaction objects
Example Usage:
const { data , error } = await paystack . transaction . list ({
perPage: 100 ,
page: 1 ,
status: "success" ,
});
if ( error ) {
console . error ( "Failed to list transactions:" , error );
} else {
console . log ( `Found ${ data . length } transactions` );
}
getTransactionById
Retrieves details of a transaction carried out on your integration.
async getTransactionById ( id : number ): Promise < TxnSingleSuccess | GenericError >
The ID of the transaction
Complete transaction object with all details (same structure as verify response)
Example Usage:
const { data , error } = await paystack . transaction . getTransactionById ( 12345 );
if ( error ) {
console . error ( "Failed to fetch transaction:" , error );
} else {
console . log ( "Transaction details:" , data );
}
chargeAuthorization
Charges an authorization marked as reusable.
async chargeAuthorization ( input : TxnChargeInput ): Promise < TxnChargeSuccess | GenericError >
The charge details. Amount to charge in kobo/cents
Valid authorization code to charge
Unique transaction reference
currency
'NGN' | 'USD' | 'GHS' | 'ZAR' | 'KES' | 'XOF'
Currency in which amount should be charged
Payment channels to use (card or bank)
Flat fee to charge the subaccount
Who bears Paystack charges (defaults to account)
Queue transaction (defaults to false)
ISO datetime of transaction
Example Usage:
const { data , error } = await paystack . transaction . chargeAuthorization ({
amount: 10000 ,
email: "customer@email.com" ,
authorization_code: "AUTH_code123" ,
});
if ( error ) {
console . error ( "Charge failed:" , error );
} else {
console . log ( "Charge successful:" , data . status );
}
viewTxnTimeline
Views the timeline of a transaction.
async viewTxnTimeline ( id_or_reference : string ): Promise < TxnTimelineSuccess | GenericError >
The ID or reference of the transaction
ISO time when transaction started
Time spent in milliseconds
Whether transaction succeeded
Whether transaction was from mobile
Example Usage:
const { data , error } = await paystack . transaction . viewTxnTimeline ( "reference-123" );
if ( error ) {
console . error ( "Failed to fetch timeline:" , error );
} else {
console . log ( "Transaction timeline:" , data . history );
}
getTxnTotals
Retrieves the total volume of transactions received on your integration.
async getTxnTotals ( input : GenericInput ): Promise < TxnTotalsSuccess | GenericError >
Query parameters for transaction totals. Start date (ISO datetime)
Total number of transactions
Volume breakdown by currency
pending_transfers_by_currency
Pending transfers by currency
Example Usage:
const { data , error } = await paystack . transaction . getTxnTotals ({
perPage: 50 ,
page: 1 ,
});
if ( error ) {
console . error ( "Failed to fetch totals:" , error );
} else {
console . log ( `Total transactions: ${ data . total_transactions } ` );
}
exportTxns
Exports a list of transactions carried out on your integration.
async exportTxns ( input : TxnExportInput ): Promise < TxnExportSuccess | GenericError >
Query parameters for exporting transactions. Start date (ISO datetime)
status
'success' | 'failed' | 'abandoned'
Transaction status filter
URL to download the export file
ISO datetime when the export expires
Example Usage:
const { data , error } = await paystack . transaction . exportTxns ({
from: "2024-01-01T00:00:00Z" ,
to: "2024-12-31T23:59:59Z" ,
status: "success" ,
});
if ( error ) {
console . error ( "Export failed:" , error );
} else {
console . log ( "Download export from:" , data . path );
}
partialDebit
Retrieves part of a payment from a customer.
async partialDebit ( input : TxnPartialDebitInput ): Promise < TxnPartialDebitSuccess | GenericError >
input
TxnPartialDebitInput
required
The partial debit details. Authorization code for the transaction
Currency (defaults to NGN)
Unique transaction reference
Originally requested amount
Example Usage:
const { data , error } = await paystack . transaction . partialDebit ({
authorization_code: "AUTH_code123" ,
currency: "NGN" ,
amount: 50000 ,
email: "customer@email.com" ,
at_least: 30000 ,
});
if ( error ) {
console . error ( "Partial debit failed:" , error );
} else {
console . log ( `Charged ${ data . amount } of ${ data . requested_amount } ` );
}