softare development

FlutterWave Payment Integration With PHP

FlutterWave payment integration with PHP can be a tedious process if you’re just starting out.

Payment integration is the process of integrating a payment gateway or processor into a website or application to enable users to make online payments. This allows businesses to accept payments from customers using a variety of payment methods, such as credit and debit cards, digital wallets, bank transfers, and more. Some popular payment gateway providers include PayPal, Stripe, Authorize.net, Square, and Braintree, among others.

Payment integration is an essential component of e-commerce websites, online marketplaces, and mobile applications that facilitate transactions. It helps to streamline the payment process, making it faster and more convenient for customers to make purchases. In addition, payment integration can provide added security measures, such as fraud detection and prevention, to ensure that transactions are safe and secure.

To implement payment integration, developers typically use application programming interfaces (APIs) provided by the payment gateway provider to connect the payment system to the website or application.

Together with PayStack, FlutterWave is one of the most popular payment platforms in Africa.

It has a rich documentation which you can follow through. But if you’re pressed for time and also a PHP dev, here’s a quick and comprehensive implementation for you to follow.

FlutterWave Code Integration Snippet

 <?php  
    $amount = 11300;
    $first_name = "Lawson";
    $last_name = "Luke";

      $request = [
        'tx_ref' => time(),
        'amount' => $amount,
        'currency' => 'NGN',
        'payment_options' => 'card',
        'redirect_url' => 'your_success.php', //replace with yours
        'customer' => [
            'email' => $email,
            'name' => $first_name. ' '.$last_name
        ],
        'meta' => [
            'price' => $amount
        ],
        'customizations' => [
            'title' => 'Paying for a service', //Set your title
            'description' => 'Level'
        ]
    ];

    //* Call fluterwave endpoint
    $curl = curl_init();

    curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://api.flutterwave.com/v3/payments', //don't change this
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => json_encode($request),
    CURLOPT_HTTPHEADER => array(
        'Authorization: Bearer YOUR_SECRET KEY',
        'Content-Type: application/json'
    ),
    ));

    $response = curl_exec($curl);

    curl_close($curl);
    
    $res = json_decode($response);
    if($res->status == 'success')
    {
        $link = $res->data->link;
        header('Location: '.$link);
    }
    else
    {
        // echo 'We can not process your payment';
        echo $res->status;
    }
 ?>

Don’t forget to add Secret key and set your redirect link.

You should have something like this.

FlutterWave Payment integration with PHP

Summary

Overall, payment integration is a critical aspect of software development for any business that wants to accept online payments. By integrating a payment gateway, businesses can improve their online presence and provide a more convenient, secure, and reliable payment experience for their customers.

Start Learning Software Development

How to Install Composer on NameCheap Server

How Do I Start A Software Development Journey?

View Comments

  • It was such a great article which was on payment processing in flutter app. I would like to add some more points to it. I hope readers will like it.
    1.Choose a Payment Gateway
    2.Set Up an Account
    3.Obtain API Keys
    4.Add Dependencies
    5.Configure Platform-Specific Files
    6.Implement Payment Logic
    7.Integrate Payment Gateway SDK
    8.Test and Debug
    9.Handle Webhooks (if applicable)
    By implementing the above points we can integrate the payment process in flutter. Reades, If you want to develop your flutter app, you can take a visit from an IT company like Alakmalak technologies. They have 17+ years of experience in this field.

    • Yes, you add your redirect link after the operation is successful here on this line:
      'redirect_url' => 'your_success.php'

          • Several ways. You can get it from the successful response and insert it. Or you can check if the payment is successful, then you write the logic that inserts the amount into the database. Let me know if you need more clarification.

Recent Posts

Perks of Being a Copy-Paste Developer

Why borrowing code is a skill—when you understand what you're copying. For years, "copy-paste developer"…

1 day ago

Conditionally Disable an Input Field Using React Hook Form

Interactive forms rarely keep every field active all the time. Sometimes an input should only…

1 day ago

JavaScript Temporal API

A modern JavaScript API for working with dates, times, time zones, and calendars without the…

4 days ago

Node.js Under the Hood

Understanding What Happens Behind the Scenes Node.js looks simple from the outside—you write JavaScript, call…

4 days ago

This is How You Cultivate Negative Capability

The need for absolute certainty is the greatest disease the engineering mind faces. The moment…

6 days ago

You Don’t have to become the World’s Greatest Programmer.

The software industry is one of the most competitive places to build a career. Every…

1 week ago