Transactions
The TransactionResource allows you to handle payments, verify status, and retrieve transaction details.
Initialize a Transaction
To start a payment flow, you need to initialize a transaction. This generates an authorization URL where the user can make the payment.
Important: The amount should be in the subunit of the supported currency (e.g., kobo for Naira, pesewas for Cedi).
$response = paystack()->transaction()->initialize([
'email' => '[email protected]',
'amount' => 5000 , // Amount in lowest form pesewas/kobo
'metadata' => [],
]);
// Redirect the user to the payment page
return redirect($response['data']['authorization_url']);Parameters
When initializing a transaction, you can pass the following parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
amount | String | Yes | Amount should be in the subunit of the supported currency (e.g., kobo). |
email | String | Yes | Customer's email address. |
currency | String | No | The transaction currency. Defaults to your integration currency. |
reference | String | No | Unique transaction reference. Only -, ., = and alphanumeric characters allowed. |
callback_url | String | No | Fully qualified url, e.g. https://stephenasare.dev/. Overrides the dashboard callback URL. If not provided, it uses the PAYSTACK_CALLBACK_URL from your .env config. |
plan | String | No | If transaction is to create a subscription to a predefined plan, provide plan code here. This invalidates the amount. |
invoice_limit | Integer | No | Number of times to charge customer during subscription to plan. |
metadata | String | No | Stringified JSON object of custom data. |
channels | Array | No | An array of payment channels to control what channels you want to make available to the user. Available: ["card", "bank", "apple_pay", "ussd", "qr", "mobile_money", "bank_transfer", "eft", "payattitude"] |
split_code | String | No | The split code of the transaction split. e.g. SPL_98WF13Eb3w. |
subaccount | String | No | The code for the subaccount that owns the payment. e.g. ACCT_8f4s1eq7ml6rlzj. |
transaction_charge | Integer | No | An amount used to override the split configuration for a single split payment. |
bearer | String | No | Who bears the transaction charges. Allowed values: account or subaccount (defaults to account). |
Using Paystack Popup (Inline JS)
If you are using the Paystack Popup (Inline JS) on your frontend, you should initialize the transaction from your backend to get an access_code, then pass it to your frontend.
Backend:
$response = paystack()->transaction()->initialize([
'email' => '[email protected]',
'amount' => 5000 * 100,
]);
$accessCode = $response['data']['access_code'];
return response()->json(['access_code' => $accessCode]);Frontend (JS):
// Assuming you have fetched the access_code from your backend
const popup = new PaystackPop();
popup.resumeTransaction(access_code);Get Authorization URL Directly
If you only need the authorization URL for a standard redirect flow:
$url = paystack()->transaction()->getAuthorizationUrl([
'email' => '[email protected]',
'amount' => 5000 * 100
]);
return redirect($url);Verify a Transaction
After a payment is made, Paystack redirects the user to your callback URL with a reference. You must verify this reference to confirm the payment status.
Security Note: Always verify the transaction status and amount on your server before giving value to the customer. Do not trust the frontend status alone.
$reference = request('reference');
try {
$response = paystack()->transaction()->verify($reference);
if ($response['data']['status'] === 'success') {
// Verify the amount matches what you expect
if ($response['data']['amount'] === 500000) {
// Give value to the customer
}
}
} catch (\Exception $e) {
// Handle verification error
}List Transactions
Retrieve a list of transactions carried out on your integration.
// List all transactions
$transactions = paystack()->transaction()->list();
// Filter transactions
$filtered = paystack()->transaction()->list([
'perPage' => 20,
'status' => 'success'
]);Fetch a Transaction
Get details of a specific transaction by its ID.
$transactionId = 123456;
$details = paystack()->transaction()->fetch($transactionId);