ifcon/laravel-payment-gateway
最新稳定版本:v1.0.0
Composer 安装命令:
composer require ifcon/laravel-payment-gateway
包简介
Laravel payment gateway drivers for SenangPay, ToyyibPay, CHIP, DOKU, KiplePay, and PayPal
README 文档
README
Laravel payment gateway package supporting SenangPay, ToyyibPay, CHIP, DOKU, KiplePay, and PayPal.
Requirements
- PHP ^8.0
- Laravel 9, 10, 11, 12, or 13
Installation
composer require ifcon/laravel-payment-gateway
The service provider is auto-discovered. Publish the config:
php artisan vendor:publish --tag=payment-gateway-config
Configuration
Set PAYMENT_DRIVER in your .env to select the active gateway:
PAYMENT_DRIVER=senangpay
SenangPay
PAYMENT_DRIVER=senangpay
SENANGPAY_MERCHANT_ID=your-merchant-id
SENANGPAY_SECRET_KEY=your-secret-key
SENANGPAY_SANDBOX=true
SENANGPAY_HASH_TYPE=sha256
Supported SENANGPAY_HASH_TYPE values: md5, sha256 (or any algorithm accepted by hash_hmac).
ToyyibPay
PAYMENT_DRIVER=toyyibpay
TOYYIBPAY_USER_SECRET_KEY=your-user-secret-key
TOYYIBPAY_CATEGORY_CODE=your-category-code
TOYYIBPAY_RETURN_URL=https://yourapp.com/payment/return/toyyibpay
TOYYIBPAY_CALLBACK_URL=https://yourapp.com/payment/callback/toyyibpay
TOYYIBPAY_SANDBOX=true
CHIP
PAYMENT_DRIVER=chip
CHIP_BRAND_ID=your-brand-id
CHIP_API_KEY=your-api-key
CHIP_ENDPOINT=https://gate.chip-in.asia
CHIP_SUCCESS_REDIRECT=https://yourapp.com/payment/return/chip
CHIP_SUCCESS_CALLBACK=https://yourapp.com/payment/callback/chip
CHIP_FAILURE_REDIRECT=https://yourapp.com/payment/failed
DOKU
PAYMENT_DRIVER=doku
DOKU_SANDBOX=false
DOKU_CLIENT_ID=your-client-id
DOKU_API_KEY=your-api-key
DOKU_EXPIRED_HOURS=24
DOKU_BACK_TO_MERCHANT_URL=https://yourapp.com/payment/return/doku
DOKU_BACK_TO_MERCHANT_CANCEL_URL=https://yourapp.com/payment/cancel/doku
DOKU_BACK_TO_MERCHANT_RESULT_URL=https://yourapp.com/payment/result/doku
KiplePay
PAYMENT_DRIVER=kiplepay
KIPLEPAY_SANDBOX=true
KIPLEPAY_MERCHANT_ID=your-merchant-id
KIPLEPAY_SECRET_KEY=your-secret-key
KIPLEPAY_RETURN_URL=https://yourapp.com/payment/return/kiplepay
KIPLEPAY_CALLBACK_URL=https://yourapp.com/payment/callback/kiplepay
PayPal
PAYMENT_DRIVER=paypal
PAYPAL_CLIENT_ID=your-client-id
PAYPAL_SECRET=your-secret
PAYPAL_MODE=sandbox
PAYPAL_RETURN_URL=https://yourapp.com/payment/return/paypal
PAYPAL_CANCEL_URL=https://yourapp.com/payment/cancel/paypal
Basic Usage
Initiating a payment
use Ifcon\PaymentGateway\PaymentGatewayService;
$gateway = new PaymentGatewayService(config('payment_gateway.driver'));
$result = $gateway->driver
->setSendPaymentDetails(
description: 'Order #1234',
amount: 99.90,
orderId: 'ORD-1234',
to: 'Ahmad bin Ali',
email: 'ahmad@example.com',
phone: '0123456789'
)
->processPayment();
// Redirect the user
return redirect($result['redirect_url']);
processPayment() returns:
| Key | Type | Description |
|---|---|---|
redirect_url | string\|null | URL to redirect the user to the gateway |
billcode | string\|null | Gateway reference (ToyyibPay bill code, CHIP purchase ID, etc.) |
payment_form | string\|null | Raw HTML form (KiplePay only — render and auto-submit) |
Handling the return / callback
public function handleReturn(Request $request)
{
$gateway = new PaymentGatewayService(config('payment_gateway.driver'));
$result = $gateway->driver->payment_return($request);
if ($result['status'] === 1) {
// Payment successful
// $result['txn_ref'] contains the gateway transaction reference
} else {
// Payment failed — $result['message'] explains why
}
}
Checking payment status by order ID
$result = $gateway->driver->payment_check($orderId);
if ($result['status'] === 1) {
$transactionRef = $result['txn_ref'];
}
payment_check() / payment_return() always return:
| Key | Type | Description |
|---|---|---|
status | int | 1 = success, 0 = failed |
txn_ref | string | Gateway transaction reference (on success) |
message | string | Human-readable result message |
Dependency Injection
The service is bound in the container. You can inject it directly:
use Ifcon\PaymentGateway\PaymentGatewayService;
public function __construct(private PaymentGatewayService $gateway) {}
This resolves the driver from payment_gateway.driver config automatically.
Custom Drivers
Register a custom driver before instantiating the service:
use Ifcon\PaymentGateway\PaymentGatewayService;
use App\Payments\MyCustomDriver;
PaymentGatewayService::extend('mycustom', MyCustomDriver::class);
$gateway = new PaymentGatewayService('mycustom');
The custom driver must implement Ifcon\PaymentGateway\Contracts\DriverContract:
use Ifcon\PaymentGateway\Contracts\DriverContract;
use Illuminate\Http\Request;
class MyCustomDriver implements DriverContract
{
public function setSendPaymentDetails(
$description, $amount, $orderId, $to, $email, $phone,
$billName = null, $billCode = null
) {
// store payment details, return $this
}
public function processPayment(): array
{
// return ['redirect_url' => '...', 'billcode' => '...']
}
public function payment_return(Request $request): array
{
// return ['status' => 1, 'txn_ref' => '...', 'message' => '...']
}
public function payment_check($order_id): array
{
// return ['status' => 1, 'txn_ref' => '...']
}
}
Driver Notes
ToyyibPay — pre-created bills
If you created a bill externally and already have a bill code, skip bill creation:
$gateway->driver
->setSendPaymentDetails(...)
->setBillCode('ABC123')
->processPayment();
SenangPay — hash verification
Verify the return signature before trusting the response:
if (! $gateway->driver->checkIfReturnHashCorrect($request)) {
abort(400, 'Invalid signature');
}
KiplePay — HTML form response
KiplePay returns a self-submitting HTML form instead of a redirect URL:
$result = $gateway->driver->setSendPaymentDetails(...)->processPayment();
return response($result['payment_form']); // render directly
DOKU / SenangPay — debug mode
Pass true to payment_check to dump the raw gateway response during development:
$gateway->driver->payment_check($orderId, debug: true);
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-11