Skip to content

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).

php

$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:

ParameterTypeRequiredDescription
amountStringYesAmount should be in the subunit of the supported currency (e.g., kobo).
emailStringYesCustomer's email address.
currencyStringNoThe transaction currency. Defaults to your integration currency.
referenceStringNoUnique transaction reference. Only -, ., = and alphanumeric characters allowed.
callback_urlStringNoFully 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.
planStringNoIf transaction is to create a subscription to a predefined plan, provide plan code here. This invalidates the amount.
invoice_limitIntegerNoNumber of times to charge customer during subscription to plan.
metadataStringNoStringified JSON object of custom data.
channelsArrayNoAn 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_codeStringNoThe split code of the transaction split. e.g. SPL_98WF13Eb3w.
subaccountStringNoThe code for the subaccount that owns the payment. e.g. ACCT_8f4s1eq7ml6rlzj.
transaction_chargeIntegerNoAn amount used to override the split configuration for a single split payment.
bearerStringNoWho 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:

php
$response = paystack()->transaction()->initialize([
    'email' => '[email protected]',
    'amount' => 5000 * 100,
]);

$accessCode = $response['data']['access_code'];

return response()->json(['access_code' => $accessCode]);

Frontend (JS):

javascript
// 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:

php
$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.

php
$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.

php
// 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.

php
$transactionId = 123456;

$details = paystack()->transaction()->fetch($transactionId);

Released under the MIT License.