laraditz/bayar

Expressive and fluent interface to multiple payment gateways.

0.0.6 2023-09-07 06:40 UTC

This package is auto-updated.

Last update: 2024-12-07 09:14:15 UTC


README

Laravel Bayar

Laravel Bayar

Latest Version on Packagist Total Downloads GitHub Actions

Laravel Bayar is a multi-payment processing library for Laravel. It is easy to use and handle most of the tedious tasks when integrating with a payment gateway. You also can easily create a new payment gateway provider to use with this library package.

Installation

You can install the package via composer:

composer require laraditz/bayar

Run the migration command to create the necessary database table.

php artisan migrate

Then install the payment gateway provider that you wish to use. See supported providers section to see list of all available providers.

composer require gerbang-bayar/provider-name

Go to respective provider's repository to see how to set it up.

Usage

To create a payment intent, first create a PaymentData object. Then pass it into the createPayment method.

Here is the data that you can pass when creating PaymentData object. The extra prorperties can be used to pass an extra properties needed and it must follows the same property name as in the payment gateway respective's API.

public string $currency,
public int $amount, // smallest currency unit
public string $returnUrl,
public string $description,
public array $customer,
public ?string $callbackUrl = null,
public ?string $merchantRefId = null,
public ?array $extra = [],

To create payment and get the payment URL to be redirected to.

use Laraditz\Bayar\Data\PaymentData;

$paymentData = new PaymentData(
    description: 'Purchase',
    currency: 'MYR',
    amount: 1000,
    returnUrl: 'https://returnurl.here',
    customer: [
        'name' => 'Raditz Farhan',
        'phone' => '6012345678',
        'email' => 'raditzfarhan@gmail.com'
    ],
    extra: [
        'shippingAddress' => [
            'countryCode' => 'MY',
            'lines' => [
                'No 1, Taman ABC',
                'Jalan DCEF'
            ],
            'postCode' => '12345'
        ],
        'items' => [
            [
                'itemId' => 'ITEMSKU',
                'name' => 'Item 1',
                'quantity' => 1,
                'price' => 1000,
            ]
        ]    
    ]
);

$bayar = \Bayar::driver('atome')->createPayment($paymentData);

Return example:

[
  "id" => "01h91mbatnwn27y4y5s88b783k"
  "merchant_ref_id" => null
  "expires_at" => "2023-08-29T21:54:13.000000Z"
  "payment_url" => "http://yourappurl.com/bayar/pay/01h91mbatnwn27y4y5s88b783k"
]

Redirect to the payment_url to proceed to payment page. Once done, you will be redirected to the returnUrl.

Callback

Callback event will be managed automatically by this package. Each providers have their own callback event to receives payment update from respective payment gateway provider. You just need to add a listener for the event. Refer to the provider package for more info.

Supported Providers

Currently it has only one provider which is Atome, but the list will grows with time.

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

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

Credits

License

The MIT License (MIT). Please see License File for more information.

Dependencies