Skip to content

This is a PHP package for intializing and verifying Fluttwerwave transactions via the Flutterwave transactions API

Notifications You must be signed in to change notification settings

obinnaakaolisa/flutterwave-pay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flutterwave-pay

This is a PHP package for intializing and verifying Flutterwave transactions via the Flutterave transactions API

Requirements

The package requires the folowing resources:

  1. PHP ^8.0
  2. Composer
  3. Curl

Getting started

Installation

Navigate to your project's directory

    cd folder/my-project

In your project folder, run the following command

    composer require obinnaakaolisa/flutterwave-pay

Set your api key

    $apiKey = "FLWSECK_TEST-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-X";

Instantiate a new transaction object

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:

  1. The customizations field is optional. Define it if you want to customize the look and feel of the payment page. See documentation for reference.
  2. The subaccounts field is optional. It is only defined when you want to split the transaction into different settlement accounts. See documentation for reference.
  3. The meta field is optional. It is only defined when you want to save additional info about the customer or the transaction. See documentation for reference.

Intialize the transaction

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

Verifying a transaction

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']));

Contributing

Contributions are always welcome!

See contributing.md for ways to get started.

Please adhere to this project's code of conduct.

License

MIT

About

This is a PHP package for intializing and verifying Fluttwerwave transactions via the Flutterwave transactions API

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages