psp-sdk / psp-sdk-php
PSP PHP 支付 SDK
v0.1.2
2022-02-22 05:56 UTC
Requires
- php: >=5.3.0
- ext-json: *
- rmccue/requests: v1.8.0
Requires (Dev)
- phpunit/phpunit: ~4.8|~5.0
- raveren/kint: 1.*
This package is auto-updated.
Last update: 2024-09-21 18:04:36 UTC
README
先决条件
- 至少需要 PHP 5.3
安装
- 如果你的项目使用 composer,运行以下命令
composer require psp-sdk/psp-sdk-php
- 如果你没有使用 composer,请从发行版部分下载最新版本。 你应该下载
psp-sdk-php-master.zip
文件。之后,将Omnipay.php
包含到你的应用程序中,你就可以像通常一样使用 API。
##注意:此 PHP 库遵循以下实践
- 在
Omnipay\Api
下命名空间 - API 通过抛出异常而不是返回错误
- 尽可能以数组形式传递选项而不是多个参数
- 所有请求和响应都通过 JSON 通信
基本用法
使用 user_name
、password
和 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); //STC Pay Create Payment $stcParm = array('Customer' =>array('Name'=>'Dharmraj Kumhar', 'Email'=>'developers.wdp@gmail.com'),'DirectPaymentAuthorizeV4RequestMessage' =>array('MobileNo'=>'966557877988','Amount'=>'11','MerchantNote'=>'STC Payment')); $encripted_result = $api->encryptDecrypt->create($stcParm, $secret_key, 'encrypt'); // Payment API //Alwase send $param['trandata'] in encrypted string $param['trandata'] = $encripted_result['content']['apiResponse']; $result = $api->payment->stcPay($param); //If you want to use our checkout page please follow these instructions //Create Payment $paymentParm = array('customer_name'=>'Raj', 'customer_email'=>'raj2022@example.com', 'amount'=>'100', 'currency'=>'SAR', 'remark'=>'This payment is done by card'); $checkout = $api->payment->checkout($paymentParm); //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 文件。