img
AboutContactBlogGet in touch

8 min read

BOG Payment Gateway: Bringing Seamless Bank of Georgia Payments to Laravel

Have a project in mind? Let us show you how easily your Laravel app can come together.

bog payment gateway in laravel appsThe BOG Payment Gateway is an open-source package that simplifies integrating the Bank of Georgia's payment gateway into Laravel applications. It allows developers to easily set up secure payment processing by configuring just a few environment variables. By reducing dependencies, the package eliminates much of the complexity often associated with handling different payment methods and offers a clean and straightforward solution. Whether you're initiating transactions, checking payment statuses, or ensuring secure communication with the gateway, this package simplifies the entire process and makes it an essential resource for developers working with the Bank of Georgia’s payment system.

The Idea Behind the Package

Existing packages tend to be overly opinionated and introduce unnecessary complexity, often forcing developers to adopt a specific approach rather than allowing them the flexibility to integrate the package in a way that best suits their needs.

When the Bank of Georgia updated its payment gateway and introduced a new aggregation system, it created a challenge: the new system wasn’t compatible with the old one, meaning we had to migrate all our payments to this updated platform. As we worked through the transition, we realized there wasn’t any package available to simplify the process. So, we decided to build our own payment provider and turn it into an open-source package to help other developers who might face the same need.

To simplify the development process, we used Spatie’s Skeleton repository as a foundation for the package. This provided a solid starting point and allowed me to focus on building the functionality rather than worrying about setting up a new package from scratch.

How To Set It Up?

Getting started with the BOG Payment package is straightforward. You should just follow these steps to set up your environment and enable BOG payments in your Laravel application.

Installation

To get started, install the package via Composer:

composer require redberryproducts/laravel-bog-payment

Next, publish the configuration file with the following command:

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

After running the command, you’ll find the configuration file located at:

config/bog-payment.php

This is where you can customize the package settings as needed.

Environment Variables

To configure the BOG Payment Package, add the following variables to your .envfile:

BOG_SECRET=[your_client_secret]
BOG_CLIENT_ID=[your_client_id]
BOG_PUBLIC_KEY=[your_public_key] # Can be found at https://api.bog.ge/docs/payments/standard-process/callback

Make sure to replace the placeholders with your actual credentials. You can always find the latest BOG_PUBLIC_KEY in the Bank of Georgia API documentation.

These three are the minimum required to get things running smoothly, but you can also add more environment variables if needed.

Usage

Usage Example: Simple Payment Processing

To initiate a payment, use the `Pay` facade to set the order details and process the transaction:

use RedberryProducts\LaravelBogPayment\Facades\Pay;
use App\Models\Transaction;

// Step 1: Create a transaction record
$transaction = Transaction::create([
    'user_id'    => auth()->id(),
    'amount'     => $data['total_amount'],
    'status'     => 'pending', // Initial status
]);

// Step 2: Process the payment
$paymentDetails = Pay::orderId($transaction->id)
    ->redirectUrl(route('bog.v1.transaction.status', ['transaction_id' => $transaction->id]))
    ->amount($transaction->amount)
    ->process();

// Step 3: Update the transaction with payment details
$transaction->update([
    'transaction_id'   => $paymentDetails['id'],
]);

// Step 4: Redirect user to the payment gateway
return redirect($paymentDetails['redirect_url']);

here's an example of the response:

$paymentDetails = [
    'id' => 'test-id',
    'redirect_url' => 'https://example.com/redirect',
    'details_url' => 'https://example.com/details',
]

Save Card

The BOG Payment Package allows you to easily save card details during the payment process, making future transactions smoother and quicker. This is done using the saveCard() method, which notifies the bank to store the card information securely.

Saving a Card During Payment

To save the card details, follow these steps:

use RedberryProducts\LaravelBogPayment\Facades\Pay;

// SaveCard method will initiate another request that notifies bank to save card details
$response = Pay::orderId($external_order_id)
    ->redirectUrl(route('bog.v1.transaction.status', ['transaction_id' => $transaction->id]))
    ->amount($amount)
    ->saveCard()
    ->process();

Example Response

$response = [
    'id' => 'test-id',
    'redirect_url' => 'https://example.com/redirect',
    'details_url' => 'https://example.com/details',
];

The id field represents the saved card (parent transaction) ID, which you can store in your database for future payments.

Paying with a Saved Card

Once you've saved the payment method ID in your database, you can easily initiate payments on that saved card without requiring user interaction. Here’s how:

use RedberryProducts\LaravelBogPayment\Facades\Card;

$response = Pay::orderId($external_order_id)
    ->amount($amount)
    ->chargeCard("test-id");

// Example response
$response = [
    'id' => 'test-id',
    'redirect_url' => 'https://example.com/redirect',
    'details_url' => 'https://example.com/details',
];

With this setup, you can seamlessly charge the saved card whenever needed, eliminating the need for repetitive user input.

Subscriptions

The BOG Payment Package makes it easy to set up and manage subscription payments seamlessly. Using the Pay facade, you can register a subscription and process transactions without additional user interaction.

Registering a Subscription

To register a subscription payment, configure the order details and initiate the subscription with the subscribe() method:

use RedberryProducts\LaravelBogPayment\Facades\Pay;

// SaveCard method will initiate another request that notifies bank to save card details
$response = Pay::orderId($external_order_id)
    ->redirectUrl(route('bog.v1.transaction.status', ['transaction_id' => $transaction->id]))
    ->amount($amount)
    ->subscribe();

When the subscription is successfully created, the response will include an ID that represents the parent transaction. Be sure to save this parentTransactionId in your database for future charges:

$parentTransactionId = $response['id']; 

Charging a Subscription

When it’s time to charge the subscription, simply use the chargeSubscription() method with the saved transaction ID:

$response = Pay::orderId($external_order_id)

    ->chargeSubscription($parentTransactionId);

This will process the payment for the saved subscription without requiring user interaction.

For more details and advanced configurations, visit the GitHub documentation.

Possible Use Cases & Future Development Plans

This package is perfect for developers integrating Bank of Georgia payments into their Laravel applications. It’s built to handle a variety of use cases, including:

  • Subscription Models: Easily manage recurring payments.

  • Money Blocking: Temporarily hold funds from a user and charge them later when needed.

  • Saved Cards: Enable users to securely store their payment details for future transactions.

  • Post-Dated Payments: Schedule payments to be processed at a later date.

  • Single Payments: Simplify one-time transactions.

These features make the package highly adaptable for projects requiring flexible and secure payment solutions.

Looking ahead, I plan to integrate all features provided by the BOG aggregator, including refunds, authorizations, Google Pay, Apple Pay, and enhanced money-blocking capabilities. The goal is to create a comprehensive, developer-friendly solution. I also aim to involve more contributors from the Laravel community, particularly within the Georgian tech scene, to help refine and expand the package’s capabilities through collaboration.

img

Meet the authors

We are a 200+ people agency and provide product design, software development, and creative growth marketing services to companies ranging from fresh startups to established enterprises. Our work has earned us 100+ international awards, partnerships with Laravel, Vue, Meta, and Google, and the title of Georgia’s agency of the year in 2019 and 2021.

img
Contact us