tatogi/bog-payment-laravel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tatogi/bog-payment-laravel

Composer 安装命令:

composer require tatogi/bog-payment-laravel

包简介

Laravel package for BOG (Bank of Georgia) payment gateway integration with card management and payment tracking

README 文档

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.

License Latest Version Total Downloads

🚀 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.

  1. Verifies status directly with BOG API (Source of Truth).
  2. Updates bog_payments table.
  3. Saves the card (if requested).
  4. 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.

  1. 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"
}
  1. Create routes/mock-bog.php in 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);
});
  1. Load this route file in your application:
  • Laravel 11/12: add require base_path('routes/mock-bog.php'); inside the routes callback in bootstrap/app.php.
  • Laravel 9/10: load it in RouteServiceProvider (or require it from routes/web.php).
  1. 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
  1. Manual mock flow:
  • Call POST /bog/orders and confirm it returns redirect_url.
  • Simulate callback by calling POST /bog/callback with { "order_id": "mock_order_123" }.
  • Check bog_payments table for status=completed.

This validates checkout/callback integration before switching to real BOG credentials.

👤 Author

Tato

📄 License

This package is open-sourced software licensed under the MIT license.

Made with ❤️ for the Laravel community.

tatogi/bog-payment-laravel 适用场景与选型建议

tatogi/bog-payment-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「payment」 「gateway」 「laravel」 「bog」 「payment-integration」 「payment-processing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 tatogi/bog-payment-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tatogi/bog-payment-laravel 我们能提供哪些服务?
定制开发 / 二次开发

基于 tatogi/bog-payment-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 33
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-09