omnipay-psp/omnipay-php-library

Omnipay PHP 客户端库

v1.0.3 2022-02-14 05:34 UTC

This package is auto-updated.

Last update: 2024-09-15 11:14:08 UTC


README

先决条件

  • 需要至少 PHP 5.3

安装

  • 发布部分 下载最新版本。 你应该下载 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 = '89eb5f3beb06a663a81c0c5a392fdb97';
$api_user_name = 'psp_test.paasy3u5.cGFhc3kzdTU2NGViZA==';
$api_password = 'OVNHR3dHaDd5ZnpGN0ExcnByUmdPQVprNzliZUhMbmR3bVJCSUp3alFyUT0=';
$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'=>'Dharmraj Kumhar', 'email'=>'dharmraj.kumhar@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
    $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);

许可证

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