yogigr / payment-gateway
一个简单且通用的Laravel包,用于集成多个支付服务提供商。通过统一的API轻松管理和处理来自各种网关的支付。
1.0.0
2024-08-23 09:37 UTC
Requires
- duitkupg/duitku-php: dev-master
- guzzlehttp/guzzle: ^7.2
Requires (Dev)
- mockery/mockery: ^1.6
- orchestra/testbench: ^8.25
- phpunit/phpunit: ^10.5
README
一个简单且通用的Laravel包,用于集成多个支付服务提供商。通过统一的API轻松管理和处理来自各种网关的支付。
安装
要安装 PaymentGateway
包,请按照以下步骤操作
-
通过Composer要求包
在您的Laravel项目目录中运行以下命令
composer require yogigr/payment-gateway
-
发布配置文件
使用以下命令发布配置文件
php artisan vendor:publish --provider="yogigr\PaymentGateway\PaymentGatewayServiceProvider" --tag="config"
-
设置环境变量
您的 .env 文件
PAYMENT_GATEWAY=duitku PAYMENT_CALLBACK_DOMAIN=https://example.app PAYMENT_RETURN_DOMAIN=https://example.app DUITKU_MERCHANT_CODE=duitku-merchant-code DUITKU_MERCHANT_KEY=duitku-merchant-key DUITKU_SANDBOX_MODE=true DUITKU_SANITIZED_MODE=false DUITKU_LOGS=true DUITKU_PAYMENT_URL=https://sandbox.duitku.com/TopUp/v2/DuitkuNotification.aspx FINPAY_MERCHANT_CODE=finpay-merchant-id FINPAY_MERCHANT_KEY=finpay-merchant-key FINPAY_PAYMENT_URL=https://devo.finnet.co.id
用法
安装后,您可以通过提供的Facade使用该包。以下是如何获取类别和项目的示例。
显示支付方式
use yogigr\PaymentGateway\Facades\PaymentGateway; $methods = PaymentGateway::getPaymentMethodOptions();
创建发票
use yogigr\PaymentGateway\Facades\PaymentGateway; $data = [ 'amount' => 100000, 'email' => 'customer@email.com', 'phone' => '628100000000', 'product_details' => 'Product details', 'merchant_order_id' => 'order id / kode', 'invoice_id' => 'Invoice id', 'merchant_user_info' => 'Customer info / user id', // (opsional) 'customer_name' => 'Customer name', 'callback_path' => '/payment/callback', 'return_path' => '/invoices', 'success_path' => '/invoices?status=success', 'expiry_period' => 60, 'address' => 'Customer address', 'city' => 'Customer city', 'postal_code' => 'Postal code', 'country_code' => 'ID' ]; $paymentMethod = 'credit_card'; $response = PaymentGateway::createInvoice($data, $paymentMethod); if ($response->statusCode == '00') { redirect($response->paymentUrl); }
回调
use yogigr\PaymentGateway\Facades\PaymentGateway; use Illuminate\Http\Request; class CallbackController extends Controller { public function callback(Request $request) { $result = PaymentGateway::callback($request); if ($result['resultCode'] === '00') { // success // actions if success } } }
检查交易
use yogigr\PaymentGateway\Facades\PaymentGateway; $transaction = PaymentGateway::checkTransaction($merchantOrderId); dd($transaction);