This is a PHP package for intializing and verifying Flutterwave transactions via the Flutterave transactions API
The package requires the folowing resources:
- PHP ^8.0
- Composer
- Curl
Navigate to your project's directory
cd folder/my-projectIn your project folder, run the following command
composer require obinnaakaolisa/flutterwave-pay $apiKey = "FLWSECK_TEST-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-X";Pass in the API_KEY upon instantiation.
$transaction = new FlutterwavePay($apiKey);Define your payload data for a POST request.
$payload = [
'tx_ref' => 'FLW_TEST_'.bin2hex(random_bytes(5)),
'amount' => 2000, //in naira
'redirect_url' => "https://{$_SERVER['SERVER_NAME']}/verify.php",
'currency' => 'NGN',
'customer' => [
'name' => 'Firstname' .' '.'Lastname',
'email' => 'customer@email.com',
'phone_number' => '08031010101',
],
'payment_options' => "card, banktransfer, ussd",
'customizations' => [
'title' => 'Some Payment',
],
'meta' => [
'field_name' => 'field_value',
],
'subaccounts' => []
];Note:
- The
customizationsfield is optional. Define it if you want to customize the look and feel of the payment page. See documentation for reference. - The
subaccountsfield is optional. It is only defined when you want to split the transaction into different settlement accounts. See documentation for reference. - The
metafield is optional. It is only defined when you want to save additional info about the customer or the transaction. See documentation for reference.
The response you get for a request is a json encoded object, so you need to decode it thus:
$response = json_decode($transaction->initialize($payload));or
$request = $transaction->initialize($payload);
$response = json_decode($request);Upon a successfull transaction or close of the payment page, the customer will be redirected to the redirect_url you set when initiating the transaction. Normally, that's the url where you'll verify the status of the transaction.
It is advised to verify a transaction before you give value to the customer.
Define your API_KEY
$apiKey = "FLWSECK_TEST-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-X";Instantiate a new transaction object and pass in the API_KEY upon instantiation.
$transaction = new FlutterwavePay($apiKey);Pass in the transaction reference that was defined while intiating the transaction.
You can also get this from the query parameter of the get request returned along with the redirect_url.
$response = json_decode($transaction->verify($_GET['tx_ref']));Contributions are always welcome!
See contributing.md for ways to get started.
Please adhere to this project's code of conduct.