chistel/multi-payment

A multiple payment gateway adapter for laravel

v0.0.3 2022-05-30 14:42 UTC

This package is auto-updated.

Last update: 2024-04-29 04:59:55 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

This is a very simple and light package that allows you to add multiple payment methods in your application without having to use lots of conditional statements and is library agnostic.

With this package, you can keep the uniformity of initiating and verifying payments.

Installation

This package can be installed through Composer.

composer require chistel/multi-payment

In Laravel 5.5 and above the service provider will automatically get registered. In older versions of the framework just add the service provider in config/app.php file:

'providers'=> [
    ...
    Chistel\MultiPayment\MultiPaymentServiceProvider::class,
];

Optionally you can publish the config file with:

php artisan vendor:publish --provider="Chistel\MultiPayment\MultiPaymentServiceProvider" --tag="config"

This is the content of the file that will be published in config/multi-payment.php

return [
  /*
   * An array of supported gateways
   */
  'gateways' => [
        'paystack' => [
            'name' => 'Paystack',
            'driver' => PaystackGateway::class
        ]
  ]
];

Usage

First create a gateway class of your choice with extends Chistel\MultiPayment\AbstractGateway which should implement the purchase and complete method. A couple of action classes for initiating and completing payments were also made available.

Based on the action classes, there are also events which can be used for listeners after success or failed payments. They return the gateway name, payer and the gateway response.

The sample below shows how the events get used via the EventProvider

  PaymentWasSuccessful::class => [
            PaymentSuccessfulListener::class
        ],
        PaymentWasUnsuccessful::class => [
            PaymentUnsuccessfulListener::class
        ]
  ]

And your listener should be similar to the sample below

class PaymentSuccessfulListener
{
    public function handle(PaymentWasSuccessful $event)
    {
        $payer = $event->user;
        $response = $event->responses
        $provider = $event->gateway;
        
        // Other code you want to added
    }
}

check out a full usage in the Comprehensive demo repository

Tests

The test is currently not done

Security

If you discover any security related issues, please email me@chistel.com instead of using the issue tracker.

Credits