omni-psp/omni-pay

Omnipay PHP 客户端库

v1.0.8 2022-02-14 07:00 UTC

This package is auto-updated.

Last update: 2024-09-18 18:43:51 UTC


README

先决条件

  • 需要至少 PHP 5.3

安装

  • 如果你的项目使用 composer,运行以下命令
composer require omni-psp/omni-pay
  • 如果你不使用 composer,从 发布部分 下载最新版本。 你应该下载 omnipay-php.zip 文件。然后,在你的应用程序中包含 Omnipay.php,你就可以像往常一样使用 API 了。

##注意:此 PHP 库遵循以下实践

  • Omnipay\Api 下命名空间
  • API 抛出异常而不是返回错误
  • 尽可能以数组形式传递选项而不是多个参数
  • 所有请求和响应都通过 JSON 通信

基本用法

使用 user_namepassword 和 secret_key(测试和实时将不同)实例化 Omnipay PHP 实例。您可以从仪表板应用程序(https://psp.digitalworld.com.sa/user-api-keys)获取密钥

use Omnipay\Api\Api;

$secret_key = 'dCtLbk5FYVFGMVYrbFNGZTdEdzVpbSt3TFlYOC9NczNLaDZ0ZFo1WHcwVT0=';
$api_user_name = 'psp_test.eaohcfml.ZWFvaGNmbWw=';
$api_password = 'L1VPcklHbnh6T3RyWkdEVWZhci9HR1hSaHlrb0MwVEN5R0VtcUxkWHMwWT0=';
$apiMode = 0; // 0=Test, 1=Live
$api = new Api($api_user_name, $api_password, $apiMode); 

可以通过 $api 对象访问资源。所有方法调用遵循以下模式

    //$api->class->function() to access the API
    //Example
    //This is for encrypt decrypt before call API
    //Create Payment
    $paymentParm = array('customer' =>array('name'=>'Raj', 'email'=>'raj2022@example.com') ,'order'=>array('amount'=>'1', 'currency' => 'SAR'),'sourceOfFunds' => array('provided'=>array('card'=>array('number'=>'5123450000000008','expiry'=>array('month'=>'12','year'=>'2023'), 'cvv'=>'999')), 'cardType' => 'C'), 'remark'=>array('description'=>'This payment is done by card'));
    $api->encryptdecrypt->create($paymentParm, $secret_key, 'encrypt');
    // Payment API
    //Alwase send $param['trandata'] in encrypted string
    $param['trandata'] = $encripted_result['content']['apiResponse'];
    $result = $api->payment->createPayment($param);
    
    //Refund Transaction
    $refundParm = array('transaction' =>array('id'=>'nt8my581z620365207292e','amount'=>'1', 'currency' => 'SAR'), 'remark'=>array('description'=>'Refund transaction'));
    $encripted_result = $api->encryptdecrypt->create($refundParm, $secret_key, 'encrypt');
    $param['trandata'] = $encripted_result['content']['apiResponse'];
    $result = $api->payment->refund($param);
    
    //Retrive Transaction
    $result = $api->payment->retriveTransaction($transactionId);
    
    //Transaction List between two date range
    $AllTransParm = array('transaction' =>array('startdate'=>'2022-01-15','enddate'=>'2022-02-09'));
    $result = $api->payment->transactionList($AllTransParm);

    //subscription
    $parms = array('customer' =>array('name'=>'Raj','email'=>'raj2022@example.com', 'interval'=>'1','interval_type'=>'3','interval_count'=>''),'order'=>array('amount'=>'1','currency' => 'SAR'),'sourceOfFunds' => array('provided'=>array('card'=>array('number'=>'5123450000000008','expiry'=>array('month'=>'12','year'=>'2023'), 'cvv'=>'999')),'cardType' => 'C'));
    $encripted_result = $api->encryptdecrypt->create($parms, $secret_key, 'encrypt');
    $param['trandata'] = $encripted_result['content']['apiResponse'];
    if(!empty($encripted_result['content']['apiResponse']) && $encripted_result['code'] == 200){
        $result = $api->payment->subscription($param);
    }

    //subscription detail
    $customer_id = "202130020209387";
    $result = $api->payment->subscriptionDetail($customer_id);

    //subscription cancel
    $customer_id = "202130294267467";
    $result = $api->payment->cancelSubscription($customer_id);

许可证

Omnipay PHP SDK 在 MIT 许可下发布。有关详细信息,请参阅 LICENSE 文件。