maree / hyperpay-split

这是一个使用 hyper split 进行支付的包,我们使用这个包将银行账户中的钱转换到客户银行账户

dev-main 2023-12-19 10:31 UTC

This package is auto-updated.

Last update: 2024-09-19 11:57:34 UTC


README

安装

您可以通过 Composer 安装此包。

composer require maree/hyperpay-split

使用

php artisan vendor:publish --provider="maree\hyperpaySplit\HyperpaySplitServiceProvider" --tag="hyperpaySplit"

然后,将 config/hyperpaySplit.php 文件中的 hyperpaySplit 配置更改

    "mode"              => "test" , //or live
    "email"             => "",
    "password"          => "",
    "config_id"         => "",
    "configuration_key" => "",

用法

use maree\hyperpaySplit\HyperpaySplit;
//$type => iban || bank_account
//if type == iban must insert $swift_code
//in live mode  must insert $bank_iban_number
//$customerInfo = ['id' => '1' , 'name' => 'mohamed maree' ,'address1' => 'mehalla','address2'=>'cairo' ,'address3' => 'egypt' ]
//$amount = 1.0
//authorization => accessToken can be empty else if you created one and passed in that function
HyperpaySplit::sendTransferRequest($customerInfo = [],$amount = 1.00,$type = 'bank_account',$swift_code ='',$bank_iban_number = '',$authorization = '');  

注意

  • 定义(回调)使用 hyperpay split 团队的 checkout 返回响应 URL 路由:例如:https://mysite.com/paymentresponse
  • 为响应 URL 'paymentresponse' 创建路由:例如:Route::get('paymentresponse', 'PaymentsController@paymentresponse')->name('paymentresponse');
  • 为 checkout 响应创建 'paymentresponse' 函数
  • 使用该函数检查支付是否失败或成功

在 'paymentresponse' 函数内部使用

use maree\hyperpaySplit\HyperpaySplit;
$response = HyperpaySplit::receiveTransferResponse();  

返回如下响应

[ 'key' => 'success' ,'transaction_id' => $uniqueId ,'responseData' => $result]

[ 'key' => 'fail' ,'transaction_id' => $uniqueId ,'responseData' => $result]
  • 注意:您可以使用来自数据的响应将交易保存到数据库或更新交易状态为成功或失败。

注意

  • 如果只想创建一次 'authorization' 并将其传递给该函数,请使用以下代码
    $split_mode = config('hyperpaySplit.mode');
    if($split_mode == 'live'){
        $url       = config('hyperpaySplit.live_login_url');
    }else{
        $url       = config('hyperpaySplit.test_login_url');
    }
    $response =  Http::asForm()->post($url ,
                            [
                                'email'    => config('hyperpaySplit.email'),
                                'password' => config('hyperpaySplit.password')
                            ]);
    $array = json_decode($response->getBody()->getContents(), true);
    $authorization = $array['data']['accessToken']; 
  • 注意:在测试模式下不要插入 $bank_iban_number