Blog Detail

02

Sep
Laravel Payment Gateways for All the Payment Providers APIs cover image

arrow_back Laravel Payment Gateways for All the Payment Providers APIs

A simple Laravel implementation for all payment providers. This package supports Paystack, Flutterwave, Klasha, and Stripe.

Use Case

Have you had to implement limited SDKs for accepting payments on your mobile app? That’s the problem this package solved.

With this package, you can generate a payment link and return it to your mobile app when they make API calls and when the payment can be completed on the in-app browser.

When the customer completes their payment, this package verifies the payment and executes the code defined in your custom closure.

Installation

You can install the package via composer:

composer require stephenjude/laravel-payment-gateways

You can publish the config file with:

php artisan vendor:publish --tag="payment-gateways-config"

Optionally, you can publish the views using

php artisan vendor:publish --tag="payment-gateways-views"

Usage

This package currently supports paystack, flutterwave, klasha, and stripe.

How to initialize a payment session

use Stephenjude\PaymentGateway\PaymentGateway;
use Stephenjude\PaymentGateway\DataObjects\PaymentData;

$provider = PaymentGateway::make('paystack')

$paymentSession = $provider->initializePayment([
                'currency' => 'NGN', // required
                'amount' => 100, // required
                'email' => 'customer@email.com', // required
                'meta' => [ 'name' => 'Stephen Jude', 'phone' => '081xxxxxxxxx'],
                'closure' => function (PaymentData $payment){
                    /* 
                     * Payment verification happens immediately after the customer makes a payment. 
                     * The payment data gotten from the verification will be injected into this closure.
                     */
                    logger('payment details', [
                       'currency' => $payment->currency, 
                       'amount' => $payment->amount, 
                       'status' => $payment->status,
                       'reference' => $payment->reference,   
                       'provider' => $payment->provider,   
                       'date' => $payment->date,                   
                    ]);
                },
            ]);

$paymentSession->provider;
$paymentSession->checkoutUrl;
$paymentSession->expires;

Paystack Setup

PAYSTACK_PUBLIC=
PAYSTACK_SECRET=

Flutterwave Setup

FLUTTERWAVE_PUBLIC=
FLUTTERWAVE_SECRET=

Klasha Setup

KLASHA_PUBLIC=
KLASHA_SECRET=

Stripe Setup

STRIPE_PUBLIC=
STRIPE_SECRET=

For more details, You can visit Github.

Closing Notes

The team of Codebrisk Laravel developers is always ready to execute even your boldest ideas. Our expert team can design and develop any type of custom CRM solution, SAAS app, or e-commerce app to meet our customer’s needs and transform our customer’s experiences. Get in touch with our team to discuss your bespoke ideas and learn more about the next steps to launching cooperation.

Published at : 02-09-2022

Author : Rizwan Aslam
AUTHOR
Rizwan Aslam

I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.

Launch your project

Launch project