定制 bagene/ph-payments 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

bagene/ph-payments

最新稳定版本:0.2.1

Composer 安装命令:

composer require bagene/ph-payments

包简介

A Package container for different PH compatible payment providers

README 文档

README

composer require "bagene/ph-payments"

Configuration

php artisan vendor:publish --tag="ph-payments-config"

Usage

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());

Methods

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
}

Alternatively, you can use the xendit-webhook route and Controller to handle the webhook.

php artisan vendor:publish --tag=ph-payments-routes
php artisan vendor:publish --tag=ph-payments-services

After publishing the routes, you can add the route to your routes/payments.php file and the Service folder. You can then use the Services/WebhookService.php to handle the 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');

You can change the endpoint to you liking and register the route.

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'
        ]);
    }
}

Supported Gateways

  • Xendit
    • Supported Features:
      • invoice (create, get)
      • qr (create)
  • Maya
    • Supported Features:
      • invoice (create, get)
      • token (create, get)
      • payment (create, get)

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-27