定制 khidirdotid/xendit-laravel 二次开发

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

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

khidirdotid/xendit-laravel

最新稳定版本:v1.0.1

Composer 安装命令:

composer require khidirdotid/xendit-laravel

包简介

A Xendit Wrapper for Laravel

README 文档

README

A Xendit Wrapper for Laravel

Installation

  1. Install the package

    composer require khidirdotid/xendit-laravel
  2. Publish the config file

    php artisan vendor:publish --provider="KhidirDotID\Xendit\Providers\XenditServiceProvider"
  3. Add the Facade to your config/app.php into aliases section

    'Xendit' => KhidirDotID\Xendit\Facades\Xendit::class,
  4. Add ENV data

    XENDIT_API_KEY=

    or you can set it through the controller

    \Xendit::setXenditKey('XENDIT_API_KEY');

Usage

Invoice

  1. Get Redirection URL of a Payment Page
    $data = [
        'external_id' => 'invoice-' . time(),
        'amount' => 10000
    ];
    
    try {
        // Get Payment Page URL
        $paymentUrl = \Xendit::createInvoice($data);
    
        // Redirect to Payment Page
        return redirect()->away($paymentUrl['invoice_url']);
    } catch (\Throwable $th) {
        throw $th;
    }

Handle HTTP Notification

  1. Create route to handle notifications
    Route::match(['GET', 'POST'], 'xendit.ipn', [PaymentController::class, 'xenditIpn'])->name('xendit.ipn');
  2. Create method in controller
    public function xenditIpn(Request $request)
    {
        try {
            $response = \Xendit::getInvoiceById($request->invoice_id);
    
            if (in_array(strtolower($response['status']), ['paid', 'settled'])) {
                // TODO: Set payment status in merchant's database to 'success'
            }
        } catch (\Throwable $th) {
            throw $th;
        }
    }
  3. Except verify CSRF token in app/Http/Middleware/VerifyCsrfToken.php
    protected $except = [
        'xendit/ipn'
    ];

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-17