bagene / ph-payments
适用于不同PH兼容支付提供商的包容器
0.2.1
2024-02-24 14:24 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- orchestra/testbench: ^8.21
- phpstan/phpstan: ^1.10
README
composer require "bagene/ph-payments"
配置
php artisan vendor:publish --tag="ph-payments-config"
使用
use Bagene\PhPayments\Helpers\PaymentBuilder; PaymentBuilder::xendit(); $response = PaymentBuilder::xendit() ->invoice() ->create([ 'external_id' => 'invoice-123', 'amount' => 100000, 'payer_email' => 'test@example.org', 'description' => 'Invoice #123', 'success_redirect_url' => 'https://example.org/success', 'failure_redirect_url' => 'https://example.org/failure', ]); dump($response->getId()); dump($response->getExternalId()); return redirect()->away($response->getInvoiceUrl());
方法
invoice() ['create', 'get'] qr() ['create'] - If supported
Webhooks
use Bagene\PhPayments\Helpers\PaymentBuilder; public function xenditWebhook(Request $request) { $gateway = PaymentBuilder::getXendidGateway(); $response = $gateway->parseWebhookPayload($request); // Do something with the response }
您还可以使用xendit-webhook
路由和控制器来处理webhook。
php artisan vendor:publish --tag=ph-payments-routes
php artisan vendor:publish --tag=ph-payments-services
发布路由后,您可以将路由添加到您的routes/payments.php
文件和服务文件夹中。然后,您可以使用Services/WebhookService.php
来处理webhook。
routes/payments
<?php use Bagene\PhPayments\Controllers\XenditWebhookController; use Illuminate\Support\Facades\Route; Route::post( '/webhooks/{provider}/invoice', [XenditWebhookController::class, 'parse'] )->name('xendit.invoice.create');
您可以更改端点并注册路由。
Services/WebhookService.php
<?php namespace App\Services; use Bagene\PhPayments\Xendit\XenditWebhook; use Bagene\PhPayments\Xendit\XenditWebhookInterface; use Illuminate\Http\JsonResponse; use App\Models\TestOrder; class XenditWebhookService extends XenditWebhook implements XenditWebhookInterface { public function handle(array $payload): JsonResponse { TestOrder::query() ->where('reference', $payload['external_id']) ->update([ 'status' => strtolower($payload['status']) ]); return response()->json([ 'status' => 'ok' ]); } }
支持的网关
- Xendit
- 支持的功能
- 发票(创建,获取)
- 二维码(创建)
- 支持的功能
- Maya
- 支持的功能
- 发票(创建,获取)
- 令牌(创建,获取)
- 支付(创建,获取)
- 支持的功能
许可证
本软件包是开源软件,许可协议为MIT许可证。