dungla2011/baokim-v2

Bảo Kim Payment Gateway SDK - Compatible with Guzzle 7+ and firebase/php-jwt 6+

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/dungla2011/baokim-v2

v1.0.0 2025-12-27 13:51 UTC

This package is auto-updated.

Last update: 2025-12-27 14:00:12 UTC


README

Latest Version License Total Downloads

SDK thanh toán Bảo Kim cho PHP, tương thích với Guzzle 7+ và firebase/php-jwt 6+

✨ Tính năng

  • ✅ Tương thích với Guzzle 7+ (thay vì Guzzle 6)
  • ✅ Tương thích với firebase/php-jwt 6+ (thay vì v5)
  • ✅ Hỗ trợ PHP 7.4+ và PHP 8+
  • ✅ PSR-4 autoloading
  • ✅ Dễ dàng tích hợp
  • ✅ Xử lý lỗi chi tiết

📦 Cài đặt

composer require yourname/baokim-v2

🚀 Sử dụng nhanh

Tạo phiên thanh toán

<?php
require_once 'vendor/autoload.php';

use BaoKimV2\BaoKim;
use BaoKimV2\Session;
use BaoKimV2\Exceptions\BaoKimException;

// Cấu hình
BaoKim::setUrl('https://api.baokim.vn');
BaoKim::setKey('YOUR_API_KEY', 'YOUR_API_SECRET');

// Tạo đơn hàng
$data = [
    'payment_method_types' => [1, 2, 3], // 1: Bank, 2: E-wallet, 3: ATM, 4: Credit
    'mrc_order_id' => 'ORDER_' . time(),
    'line_items' => [
        [
            'name' => 'Sản phẩm A',
            'description' => 'Mô tả sản phẩm',
            'amount' => 500000, // VNĐ
            'currency' => 'vnd',
            'quantity' => 1,
        ]
    ],
    'success_url' => 'https://yoursite.com/payment-success',
    'cancel_url' => 'https://yoursite.com/payment-cancel',
    'webhook_url' => 'https://yoursite.com/webhook',
    'customer_email' => 'customer@example.com',
    'customer_phone' => '0901234567',
];

try {
    $result = Session::create($data);
    
    // Redirect khách hàng đến trang thanh toán
    header('Location: ' . $result->redirect_url);
    exit;
    
} catch (BaoKimException $e) {
    echo "Lỗi: " . $e->getMessage();
}

Xử lý Webhook

<?php
require_once 'vendor/autoload.php';

use BaoKimV2\BaoKim;

// Cấu hình
BaoKim::setKey('YOUR_API_KEY', 'YOUR_API_SECRET');

// Lấy dữ liệu webhook
$payload = file_get_contents('php://input');
$data = json_decode($payload, true);

$orderId = $data['mrc_order_id'];
$status = $data['stat']; // c: completed, p: pending, d: declined

if ($status === 'c') {
    // Thanh toán thành công - Cập nhật database
    // ...
}

// Trả về HTTP 200
http_response_code(200);
echo json_encode(['status' => 'success']);

📖 Documentation

Cấu hình môi trường

Development (Test)

BaoKim::setUrl('https://dev-api.baokim.vn');

Production

BaoKim::setUrl('https://api.baokim.vn');

Phương thức thanh toán

Phương thức
1 Chuyển khoản ngân hàng
2 Ví điện tử
3 Thẻ ATM
4 Thẻ tín dụng/ghi nợ

Trạng thái thanh toán

  • c (completed): Thanh toán thành công
  • p (pending): Đang chờ xử lý
  • d (declined): Thanh toán thất bại

🆚 So sánh với SDK gốc

Tính năng baokim/baokim-sdk yourname/baokim-v2
Guzzle ~6.5 ^7.0
firebase/php-jwt ^5.0 ^6.0+
PHP ^7.0 ^7.4|^8.0
PSR-4 Autoload ❌ PSR-0 ✅ PSR-4
Namespace BaoKimSDK BaoKimV2

🔑 Lấy API Key

  1. Đăng ký tài khoản merchant tại Bảo Kim
  2. Đăng nhập vào merchant portal
  3. Vào phần Cài đặt API để lấy API Key và Secret

⚠️ Yêu cầu

  • PHP 7.4 hoặc cao hơn
  • Guzzle HTTP Client 7.0 hoặc cao hơn
  • Firebase PHP-JWT 6.0 hoặc cao hơn

🤝 Đóng góp

Mọi đóng góp đều được chào đón! Vui lòng tạo Pull Request hoặc mở Issue.

📝 License

MIT License. Xem file LICENSE để biết thêm chi tiết.

🔗 Liên kết

📞 Hỗ trợ

Made with ❤️ for Vietnamese developers