tatogi / bog-payment-laravel
Laravel package for BOG (Bank of Georgia) payment gateway integration with card management and payment tracking
Requires
- php: ^8.0|^8.1|^8.2|^8.3
- illuminate/database: ^9.0|^10.0|^11.0|^12.0
- illuminate/http: ^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^7.0|^8.0|^9.0|^10.0
- phpunit/phpunit: ^9.6|^10.5|^11.0
README
A robust and clean Laravel package for integrating Bank of Georgia (BOG) payment gateway into your application. Optimized for security, race-condition prevention, and ease of use.
๐ Key Features
- โ Race-Condition Prevention: Atomic locking mechanism for payment callbacks.
- โ Clean Architecture: Thin controllers with dedicated Form Requests and Service layer logic.
- โ Full BOG API integration: OAuth2, Order creation, Status tracking.
- โ Card Management: Securely save cards for 1-click future payments.
- โ Automated Workflows: Automatic product status updates upon successful payment.
- โ Developer Friendly: Highly configurable models and comprehensive logging.
๐ Requirements
- PHP >= 8.1
- Laravel >= 9.0 (Supports Laravel 10, 11, and 12)
- BOG Payment API Credentials
๐ฆ Installation
Install the package via Composer:
composer require tatogi/bog-payment-laravel
Publish the configuration and migrations:
php artisan vendor:publish --provider="Bog\Payment\BogPaymentServiceProvider"
Run the database migrations:
php artisan migrate
โ๏ธ Configuration
Add your BOG credentials to your .env file:
BOG_CLIENT_ID=your_client_id BOG_CLIENT_SECRET=your_client_secret BOG_CALLBACK_URL=https://your-domain.com/bog/callback # Optional - Customize your models # The package will automatically update these models on successful payments BOG_USER_MODEL=App\Models\User BOG_PRODUCT_MODEL=App\Models\Product
๐ Usage
Creating a Payment Order
The package handles all the heavy lifting, including database records and product linking.
use Bog\Payment\Services\BogPaymentService; use Bog\Payment\Services\BogAuthService; $auth = app(BogAuthService::class); $paymentService = app(BogPaymentService::class); $token = $auth->getAccessToken()['access_token']; $payload = [ 'callback_url' => 'https://example.com/callback', 'purchase_units' => [ 'total_amount' => 100.00, 'currency' => 'GEL', 'basket' => [ [ 'product_id' => 'prod-123', 'name' => 'Premium Item', 'quantity' => 1, 'unit_price' => 100.00, ] ] ], 'redirect_urls' => [ 'success' => 'https://example.com/success', 'fail' => 'https://example.com/fail', ], 'save_card' => true, // Optional: request card saving 'user_id' => auth()->id(), ]; $response = $paymentService->createOrder($token, $payload); return redirect($response['_links']['redirect']['href']);
Callback Handling (Automated)
The package includes a built-in callback handler that uses Atomic Locks to prevent duplicate processing if BOG sends multiple hit requests.
- Verifies status directly with BOG API (Source of Truth).
- Updates
bog_paymentstable. - Saves the card (if requested).
- Marks products as "ordered" in your database.
๐ฃ๏ธ API Endpoints
| Method | Endpoint | Description |
|---|---|---|
| POST | /bog/callback |
BOG Webhook handler |
| POST | /bog/orders |
Create a new payment order |
| GET | /bog/orders/{id} |
Get real-time status from BOG |
| POST | /bog/cards |
List/Add saved cards |
| DELETE | /bog/cards/{id} |
Remove a saved card |
๐๏ธ Architecture
BogPaymentService: The core logic engine. Handles API communication and DB transactions.Form Requests: Validation is isolated for cleaner controllers.Atomic Locking: Uses Cache-based locks to ensure callbacks are processed exactly once.
๐งช Testing
The package is fully tested with PHPUnit.
composer test
Test Without BOG Keys (Mock Files)
If you do not have real BOG credentials yet, you can test the full package flow with local mock files.
- Create mock JSON files in your Laravel app:
storage/app/mock-bog/oauth-token.json
{
"access_token": "mock_access_token",
"token_type": "Bearer",
"expires_in": 3600
}
storage/app/mock-bog/order-created.json
{
"id": "mock_order_123",
"status": "created",
"_links": {
"redirect": {
"href": "https://example.test/fake-bog-checkout"
}
}
}
storage/app/mock-bog/payment-details.json
{
"id": "mock_order_123",
"status": "completed",
"payment_method": "card",
"amount": 100,
"currency": "GEL"
}
- Create
routes/mock-bog.phpin your app:
<?php use Illuminate\Support\Facades\Route; Route::post('/mock/bog/oauth/token', function () { return response()->json(json_decode(file_get_contents(storage_path('app/mock-bog/oauth-token.json')), true)); }); Route::post('/mock/bog/checkout/orders', function () { return response()->json(json_decode(file_get_contents(storage_path('app/mock-bog/order-created.json')), true)); }); Route::get('/mock/bog/checkout/payment/{orderId}', function (string $orderId) { $payload = json_decode(file_get_contents(storage_path('app/mock-bog/payment-details.json')), true); $payload['id'] = $orderId; return response()->json($payload); });
- Load this route file in your application:
- Laravel 11/12: add
require base_path('routes/mock-bog.php');inside theroutescallback inbootstrap/app.php. - Laravel 9/10: load it in
RouteServiceProvider(or require it fromroutes/web.php).
- Point package URLs to mocks in
.env:
BOG_CLIENT_ID=mock_client BOG_CLIENT_SECRET=mock_secret BOG_AUTH_URL=http://127.0.0.1:8000/mock/bog/oauth/token BOG_ORDERS_URL=http://127.0.0.1:8000/mock/bog/checkout/orders BOG_PAYMENT_DETAILS_URL=http://127.0.0.1:8000/mock/bog/checkout/payment BOG_CALLBACK_URL=http://127.0.0.1:8000/bog/callback
- Manual mock flow:
- Call
POST /bog/ordersand confirm it returnsredirect_url. - Simulate callback by calling
POST /bog/callbackwith{ "order_id": "mock_order_123" }. - Check
bog_paymentstable forstatus=completed.
This validates checkout/callback integration before switching to real BOG credentials.
๐ค Author
Tato
- GitHub: @TatoGi
- Email: tato.laperashvili95@gmail.com
๐ License
This package is open-sourced software licensed under the MIT license.
Made with โค๏ธ for the Laravel community.