restoore / systempay-webservice
该库提供了一种简单快捷的系统支付Web服务包。Web服务用于将一个或多个支付功能集成到CMS中。
Requires
- php: >=5.3.3
- ext-soap: *
- laravel/framework: ~5.0
- phpunit/phpunit: ~5.0
- wsdltophp/packagebase: ~1.0
This package is not auto-updated.
Last update: 2024-09-14 19:58:51 UTC
README
这是要做什么?
该库提供了一种简单快捷的系统支付Web服务包。Web服务用于将一个或多个支付功能集成到CMS中。
常见交易操作
- 创建支付(无3D Secure身份验证)。
- 自动化交易操作(退款、取消等)。
要启用此选项,商家必须订阅通过Web服务的支付选项。
Web服务是根据SOAP协议(简单对象访问协议)的1.2版开发的,并由以下wsdl文件描述:https://paiement.systempay.fr/vads-ws/v5?wsdl
别忘了阅读:Systempay Webservice v5文档
安装
首先您需要将组件添加到您的composer.json中
composer require restoore/systempay-webservice
使用composer update或安装composer install更新您的包。
更新composer后,将ServiceProvider添加到config/app.php中的providers数组
对于Laravel >= 5.1
'providers' => [ ... Restoore\SystempayWebservice\SystempayWebserviceServiceProvider::class, ]
对于Laravel 5.0
'providers' => [ ... Restoore\SystempayWebservice\SystempayWebserviceServiceProvider, ]
外观
'SystempayWebservice' => Restoore\SystempayWebservice\Facades\SystempayWebservice::class
配置
您可以从laravel项目根目录执行此命令,将配置文件复制到您的配置目录
php artisan vendor:publish --provider="Restoore\SystempayWebservice\SystempayWebserviceServiceProvider" --tag="config"
默认情况下,该包附带一个示例配置文件:config/systempay_webservice.php
return [ 'shopid' => 'YOUR_SHOPID' 'certificate' => 'YOUR_KEY', 'mode' => 'PRODUCTION', //Systempay's url 'url_wsdl' => 'https://paiement.systempay.fr/vads-ws/v5?wsdl', 'ns' => 'http://v5.ws.vads.lyra.com/Header/' ];
在此文件中,您必须输入由Systempay提供的key和shopid参数。
测试环境
如果您正在测试环境中运行应用程序,您可以使用.env文件覆盖key、shopid和env参数。
使用以下常量名称:SYSTEMPAYWEBSERVICE_SHOPID、SYSTEMPAYWEBSERVICE_CERTIFICATE和SYSTEMPAYWEBSERVICE_MODE
单元测试
您可以从laravel项目根目录执行此命令,将测试文件复制到您的测试目录
php artisan vendor:publish --provider="Restoore\SystempayWebservice\SystempayWebserviceServiceProvider" --tag="tests"
之后,只需执行phpunit命令即可运行单元测试。请确保已安装最新的phpunit版本。目前,最新版本是5.7.14。
flo@ubuntu:/var/www/systempayws$ phpunit tests/SystempayWebserviceTest.php
PHPUnit 5.7.14 by Sebastian Bergmann and contributors.
..... 5 / 5 (100%)
Time: 4.9 seconds, Memory: 15.50MB
OK (5 tests, 8 assertions)
测试将创建一个交易,获取uuid,返回所有交易详情,更新和取消交易。
创建支付请求
现在我们终于可以使用这个包了!以下是一段代码示例,说明它是如何工作的
$commonRequest = [ 'paymentSource' => 'CC', 'submissionDate' => $submissionDate ]; $threeDSRequest = [ 'mode' => "DISABLED" ]; $paymentRequest = [ 'amount' => "2990", 'currency' => "978", 'manualValidation' => '0' ]; $orderRequest = [ 'orderId' => "TEST004", 'extInfo' => [ 'key' => 'Numéro adhérent', 'value' => '00000001' ] ]; $cardRequest = [ 'number' => "4970100000000000", 'scheme' => "VISA", 'expiryMonth' => "12", 'expiryYear' => "2023", 'cardSecurityCode' => "123", //'cardHolderBirthDay' => "2008-12-31" => require to complete paymentOptionCode if you want to update the transaction ]; //create a transaction if(SystempayWebservice::createPayment($commonRequest, $threeDSRequest, $paymentRequest, $orderRequest, $cardRequest) === true) SystempayWebservice::getResult(); // get last result } else { SystempayWebservice::getLastError(); // get last error }
您需要了解关于此代码的以下内容
- CreatePayment函数可以接受许多参数,因此我为此函数使用了数组
- 此函数返回一个布尔值
- 如果为真,您可以获取完整的结果,否则您可以看到错误信息
可用函数列表
###重要事项 对于每个函数,您都可以调用Systempay::getResult()或Systempay::getLastError()。因此,您可以从systempay webservice获取完整的返回对象。请参阅文档以获取完整的结构。
getPaymentUuid
通过transactionId、creationDate和sequenceNumber获取一个交易的uuid(通用唯一标识符)
参数
- string transactionId
- string creationDate
- int sequenceNumber, 默认值:1
返回
- uuid字符串
示例
$uuid = SystempayWebservice::getPaymentUuid($transactionId, $submissionDate);
findPayments
findPayments操作允许搜索支付。findPayments允许根据搜索条件获取支付列表。目前,paymentToken、subscriptionId和uuid属性在此操作中不考虑。
参数
- string orderId
返回
- boolean - 如果操作成功完成,则为true,否则为false
示例
if(SystempayWebservice::findPayments('PHPUnitTest') === true){ foreach(SystempayWebservice::getResult()->transactionItem as $transaction){ //do something smart } } ...
获取支付详情
getPaymentDetails操作允许请求支付结果的详细信息,以便查看其属性。
参数
- string uuid
返回
- boolean - 如果操作成功完成,则为true,否则为false
示例
if(SystempayWebservice::getPaymentDetails('589f5c2b0b954e3aa802aaa8a22fb17d') === true){ echo "the transaction amout is " . SystempayWebservice::getResult()->paymentResponse->amount; } ...
更新支付
updatePayment允许
- 编辑交易金额(向下),
- 编辑期望的捕获日期,
- 要更新,交易必须具有以下状态之一
- 待验证
- 待验证并授权
等待授权
- 等待捕获。
注意:如果没有任何详情被编辑,将出现错误代码,并且查询将被拒绝。
参数
- string uuid
- string 金额
- string 期望捕获日期
- int 货币
- int 手动验证 - 0|1
- string 备注
- int 支付选项代码
返回
- boolean - 如果操作成功完成,则为true,否则为false
示例
$result = SystempayWebservice::updatePayment($uuid, '2590',date('Y-m-d\TH:i:s\Z', time() + 3600 * 24) ,978,0,'Here is my comment !'); if($result === true){ echo "the new transaction amout is " . SystempayWebservice::getResult()->paymentResponse->amount; } ...
验证支付
validatePayment操作允许在原始支付指定的日期在银行授权交易捕获。要验证,交易必须具有以下状态之一
- 待验证
- 待验证并授权
参数
- string uuid
- string 备注
返回
- boolean - 如果操作成功完成,则为true,否则为false
示例
if(SystempayWebservice::validatePayment('589f5c2b0b954e3aa802aaa8a22fb17d') === true){ echo "the transaction is validated"; } ...
创建支付
对createPayment操作的调用允许初始化支付交易。
根据查询中的属性值,可以执行
- 即时付款,
- 延迟付款,
- 无需3D Secure认证的付款,
- 使用现有令牌的付款。注意:3DS尚未在此包中实现
参数
- array commonRequestParams
- array threeDSRequestParams
- array paymentRequestParams
- array orderRequestParams
- array cardRequestParams
- array customerRequestParams
- array techRequestParams
- array shoppingCartRequestParams
有关所有参数的详细信息,您可以参考手册:Systempay Webservice v5文档
返回
- boolean - 如果操作成功完成,则为true,否则为false
退款支付
refundPayment操作允许退款给买家。受退款影响的交易具有已捕获状态。
参数
- string uuid
- string 金额
- string 期望捕获日期
- int 货币
- int 手动验证 - 0|1
- string 备注
返回
- boolean - 如果操作成功完成,则为true,否则为false
示例
SystempayWebservice::refundPayment('0de9251b645e42bda30f1397a9ad6e32', 1500, null, 978, 0, 'Here my refund comment !'); ...
取消支付
cancelPayment操作允许取消支付交易。cancelPayment允许最终取消具有以下状态的尚未捕获的交易
- 待验证
- 待验证并授权
- 等待授权。
- 等待捕获。
参数
- string uuid
- string 备注
返回
- boolean - 如果操作成功完成,则为true,否则为false
示例
SystempayWebservice::cancelPayment($uuid, 'Here my cancel comment !'); ...