Home

Awesome

BOG Payment integration for Laravel

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

ParamMeaning
merch_idMerchant ID of your shop (length 32)
trx_idTransaction ID of current payment (length 32)
lang_codeISO 639 language codes (EN/KA/RU)
o.*Additional parameters provided by you on redirect
tsPayment creation time (yyyyMMdd HH:mm:ss)

Parameters of register request

ParamMeaning
merch_idMerchant ID of your shop (length 32)
trx_idTransaction ID of current payment (length 32)
merchant_trxTransaction ID, if it is provided by shop
result_codeResult code of the payment (1 - Success, 2 - Fail)
amountInteger value of payment amount
p.rrnRRN of payment
p.transmissionDateTimeAuthorization request date and time (MMddHHmmss)
o.*Additional parameters provided by you on redirect
m.*Parameters provided on first phase of payment process
tsPayment creation time (yyyyMMdd HH:mm:ss)
signatureBase64 encoded signature to compare with certificate
p.cardholderCardholder name
p.authcodeAuthentication code from processing (ISO 8583 Field 38)
p.maskedPanMasked card number
p.isFullyAuthenticatedResult of 3D authentication (Y - Success, N - Fail)
p.storage.card.refParameters of the card
p.storage.card.expDtExpiration date of card (YYMM)
p.storage.card.recurrentAuthorization status of recurring process (Y - Recurring is possible, N - Reucrring is not possive)
p.storage.card.registeredCard registration status (Y - Card has been registered, N - Card was not registered)
ext_result_codeAdditional information about result code

Refund result

KeyMeaning
codeNumeric value for result code
descDescription of payment result

Extended result codes

CodeNumberKeyDescription
OK0SUCCESSThe payment was completed successfully, the result was successfully communicated to the store
PREAUTHORIZE_OK3SUCCESSThe blocking of the amount was completed successfully, the result was successfully reported to the store
ONLINE_RP_FAILED1SEMI-SUCCESSFULThe payment was completed successfully, but the result was not successfully delivered to the store in Online mode
CPA_REJECTED2FAILEDThe store refused to process the payment in the first phase
CPA_NONE21FAILEDIn-store payment verification was not performed. Perhaps the store or billing has been blocked
CPA_FAILED4FAILEDAn error occurred while interacting with the store during the first phase
CLIENT_LOST53FAILEDThe transaction timed out because the user refused to continue the payment for some reason
USER_CANCEL54FAILEDThe user deliberately chose to cancel the payment
PAYMENT_REJECTED-2FAILEDRefusal to process payment
PAYMENT_FAILED-3FAILEDError during payment
PAYMENT_REVERSED-4FAILEDA successful payment was canceled on the initiative of the store at the registerPayment stage. The use of this code is for the future
CS_NOTSUPPORTED11FAILEDThe option of saving cards is not available for this store, payment for previously saved cards, recurring payments or currency is not supported for recurrent checks
CS_LIMITEXCEEDED12FAILEDThe amount in the response of the merchant PaymentAvail Response exceeds maxCardRegAmount
CS_CARDNOTFOUND13FAILEDPaymentAvail Response received card details expired, card is not registered (received cardId is not available for this store) or card does not support recurring payments

Environment Variables

KeyMeaningTypeDefault
BOG_PAYMENT_DEBUGThis value decides to log or not to log requestsboolfalse
BOG_PAYMENT_URLPayment url from Bank of Georgiastringhttps://3dacq.georgiancard.ge/payment/start.wsm
BOG_PAYMENT_MERCHANT_IDMerchant ID from Bank of Georgiastring
BOG_PAYMENT_PAGE_IDPage ID from Bank of Georgiastring
BOG_PAYMENT_ACCOUNT_IDAccount ID from Bank of Georgiastring
BOG_PAYMENT_SHOP_NAMEShop Name for Bank of Georgia paymentstringAPP_NAME
BOG_PAYMENT_SUCCESS_URLSuccess callback url for Bank of Georgiastring/payments/success
BOG_PAYMENT_FAIL_URLFail callback url for Bank of Georgiastring/payments/fail
BOG_PAYMENT_CURRENCYDefault currency for Bank of Georgia paymentint981
BOG_PAYMENT_LANGUAGEDefault language for Bank of Georgia paymentstringKA
BOG_PAYMENT_HTTP_AUTH_USERHTTP Authentication username for Bank of Georgia paymentstring
BOG_PAYMENT_HTTP_AUTH_PASSHTTP Authentication password for Bank of Georgia paymentstring
BOG_PAYMENT_ALLOWED_IPSComma separated list of allowed ips to access your system from Bank of Georgiastring213.131.36.62
BOG_PAYMENT_CERTIFICATE_PATHBank of Georgia certificate path from storagestringapp/bog.cer
BOG_PAYMENT_REFUND_API_PASSBank of Georgia api password for refund operationstring

License

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