zgabievi/laravel-bogpayment

Bank of Georgia payment integration for Laravel

0.3.1 2021-05-26 10:37 UTC

This package is auto-updated.

Last update: 2024-12-26 18:23:01 UTC


README

Packagist Packagist license

laravel-bogpayment

Table of Contents

Installation

To get started, you need to install package:

composer require zgabievi/laravel-bogpayment

If your Laravel version is older than 5.5, then add this to your service providers in config/app.php:

'providers' => [
    ...
    Zorb\BOGPayment\BOGPaymentServiceProvider::class,
    ...
];

You can publish config file using this command:

php artisan vendor:publish --provider="Zorb\BOGPayment\BOGPaymentServiceProvider"

This command will copy config file for you.

Usage

Payment

Default process has several to be completed:

  1. Redirect to card details page
  2. Bank will check payment details on your route
  3. Bank will register payment details on your route

Step #1

On this step you should redirect user to card details page

use Zorb\BOGPayment\Facades\BOGPayment;

class PaymentController extends Controller
{
    //
    public function __invoke()
    {
        return BOGPayment::redirect([
            'order_id' => 1,
        ], false);
    }
}

Pass any parameter you want to recieve on check and register step as a first value. (default: [])

Second value is boolean and defines if you want to pre-authorize payment, block amount. (default: false)

Step #2

On this step bank will check that you are ready to accept payment.

This process is called PaymentAvail.

use Zorb\BOGPayment\Facades\BOGPayment;

class PaymentCheckController extends Controller
{
    //
    public function __invoke()
    {
        // chek that http authentication is correct
        BOGPayment::checkAuth();

        // check if you are getting request from allowed ip
        BOGPayment::checkIpAllowed();

        // check if you can find order with provided id
        $order_id = BOGPayment::getParam('o.order_id');
        $order = Order::find($order_id);
    
        if (!$order) {
            BOGPayment::sendError('check', 'Order couldn\'t be found with provided id');
        }

        $trx_id = BOGPayment::getParam('trx_id');

        // send success response
        BOGPayment::sendSuccess('check', [
            'amount' => $order->amount,
            'short_desc' => $order->short_desc,
            'long_desc' => $order->long_desc,
            'trx_id' => $trx_id,
            'account_id' => config('bogpayment.account_id'),
            'currency' => config('bogpayment.currency'),
        ]);
    }
}

Check request parameters here

Step #3

On this step bank will provide details of the payment.

This process is called RegisterPayment.

use Zorb\BOGPayment\Facades\BOGPayment;

class PaymentRegisterController extends Controller
{
    //
    public function __invoke()
    {
        // chek that http authentication is correct
        BOGPayment::checkAuth();

        // check if you are getting request from allowed ip
        BOGPayment::checkIpAllowed();

        // check if provided signature matches certificate
        BOGPayment::checkSignature('register');

        // check if you can find order with provided id
        $order_id = BOGPayment::getParam('o.order_id');
        $order = Order::find($order_id);
    
        if (!$order) {
            BOGPayment::sendError('check', 'Order couldn\'t be found with provided id');
        }

        $trx_id = BOGPayment::getParam('trx_id');
        $result_code = BOGPayment::getParam('result_code');

        if (empty($result_code)) {
            BOGPayment::sendError('register', 'Result code has not been provided');
        }
    
        if ((int)$result_code === 1) {
            // payment has been succeeded
        } else {
            // payment has been failed
        }

        // send success response
        BOGPayment::sendSuccess('register');
    }
}

Check request parameters here

Recurring

Recurring process is the same as default process. Difference is that user doesn't have to fill card details again.

  1. Request will be sent to bank to start recurring process
  2. Bank will check payment details on your route
  3. Bank will register payment details on your route
use Zorb\BOGPayment\Facades\BOGPayment;

class PaymentRecurringController extends Controller
{
    //
    public function __invoke(string $trx_id)
    {
        return BOGPayment::repeat($trx_id, [
            'recurring' => true,
        ]);
    }
}

In your check and register controllers you can catch BOGPayment::getParam('o.recurring') parameter and now you will know that this process is from recurring request.

Refund

In order to refund money you need to have trx_id of payment and rrn.

use Zorb\BOGPayment\Facades\BOGPayment;

class PaymentRefundController extends Controller
{
    //
    public function __invoke(string $trx_id, string $rrn)
    {
        $result = BOGPayment::refund($trx_id, $rrn);

        if ((int)$result->code === 1) {
            // refund process succeeded
        } else {
            // refund process failed
        }
    }
}

Check result parameters here

Additional Information

Parameters of check request

Parameters of register request

Refund result

Extended result codes

Environment Variables

License

zgabievi/laravel-bogpayment is licensed under a MIT License.