nicholasmt/switchappgo-library

这是一个用于 switchApp Api 的 Laravel 库包

dev-main 2023-06-06 11:07 UTC

This package is auto-updated.

Last update: 2024-09-06 13:40:44 UTC


README

Laravel 包

这是一个为 SwitchApp Api 支付引擎提供的 Laravel 库包。

要开始使用,请运行

composer require nicholasmt/switchappgo-library

注意:如果您遇到此错误或其他错误,则表示您正在使用该包的旧版本

Your requirements could not be resolved to an installable set of packages.

要解决,只需运行


 composer update
 

在成功执行 composer update 后,再次使用 composer require nicholasmt/zoom_library 安装包

注意:如果您在更新 composer 时遇到任何基于网络不佳的错误

只需备份 vender 文件,删除,然后再次使用 composer update 运行 composer update

按以下方式配置 .env 文件

SWITCHAPP_SECRET_KEY = "your switchapp secret key"

创建控制器

php artisan make:controller SwitchAppController

使用以下方式引入包

use Nicholasmt\Switchappgo\Switchappgo;

要使用 API 回调验证交易,请使用以下代码

     
        $tx_ref = $request->query('tx_ref');
        $switchapp = new Switchappgo();
        $transaction_response = $switchapp->SwitchappAPI('GET', 'https://api.switchappgo.com/v1/transactions/verify/'.$tx_ref, false);
        $response = json_decode($transaction_response);
       
        if($response->status == 'success')
        {
             //code here
              
         }
        else
        {
           //code here
        }
           

然后最终设置回调路由

Route::get('switchapp', [App\Http\Controllers\SwitchAppController::class, 'switchappCallback'])->name('switchappgo');

控制器将如何看起来

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Nicholasmt\Switchappgo\Switchappgo;

class SwitchAppController extends Controller
{
    
    public function switchappCallback(Request $request)
    {
    
        $tx_ref = $request->query('tx_ref');
        $switchapp = new Switchappgo();
        $transaction_response = $switchapp->SwitchappAPI('GET', 'https://api.switchappgo.com/v1/transactions/verify/'.$tx_ref, false);
         $response = json_decode($transaction_response);
        
        if($response->status == 'success')
        {
             //code here
             
         }
        else
        {
          //code here
        }
    }

}

别忘了点赞。