Skip to main content

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.
data
object
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>
reference
string
required
The transaction reference to verify
data
object
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>
input
TxnListInput
required
Query parameters for listing transactions.
data
array
Array of transaction objects
meta
object
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>
id
number
required
The ID of the transaction
data
object
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>
input
TxnChargeInput
required
The charge details.
data
object
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>
id_or_reference
string
required
The ID or reference of the transaction
data
object
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>
input
GenericInput
required
Query parameters for transaction totals.
data
object
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>
input
TxnExportInput
required
Query parameters for exporting transactions.
data
object
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.
data
object
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}`);
}