dshovchko / php_easypay
实现easypay.ua支付网关的库
1.1.5
2020-06-30 13:07 UTC
Requires
- php: >=5.5.27
- dshovchko/debulog: ^1.1
Requires (Dev)
- php-coveralls/php-coveralls: 2.2.x-dev
- phpunit/phpunit: ^4.8
README
php_EasyPay
用于组织EasyPay.ua接收支付网关的库,基于EasySoft-Provider v3.1交互协议(详细信息请参考EasySoft-Gate规范)。
安装
composer require dshovchko/php_easypay
使用
首先需要编写一个类,该类实现了EasyPay\Callback接口。
interface Callback
{
public function check($account);
public function payment($account, $orderid, $amount);
public function confirm($paymentid);
public function cancel($paymentid);
}
这是您的Check、Payment、Confirm和Cancel命令的处理程序(详细信息请参考EasySoft-Gate规范)。
check()方法在成功时应该返回EasyPay\Provider31\AccountInfo类的实例。
payment()方法在成功时应该返回唯一的支付代码。
confirm()方法在成功时应该返回支付日期和时间。
cancel()方法在成功时应该返回取消支付日期和时间。
在发生任何错误时,应生成异常。代码和消息将传递给EasyPay.ua网关。
use EasyPay\Provider31\AccountInfo as AccountInfo;
class My_EasyPay_Callback implements EasyPay\Callback
{
....
public function check($account)
{
$cl = $this->find_account($account);
return new AccountInfo(array(
'Account' => $account,
'Fio' => $cl['fio'],
'Address' => $cl['adress'],
));
}
public function payment($account, $orderid, $amount)
{
$paymentid = $this->insert_payment($account, $orderid, $amount);
return $paymentid;
}
public function confirm($paymentid)
{
$orderdate = $this->confirm_payment($paymentid)
return $orderdate;
}
public function cancel($paymentid)
{
$canceldate = $this->cancel_payment($paymentid)
return $canceldate;
}
...
}
然后创建一个文件,例如request.easypay.php。
<?php
$options = include('../etc/config.php');
require_once('../vendor/autoload.php');
require_once('../class/My_EasyPay_Callback.php');
$log = new EasyPay\Logger(
realpath('../log').DIRECTORY_SEPARATOR, // log path
$options['log_prefix'], // prefix for log files (default 'my')
$options['log_debug'] // enable/disable debug (default false)
);
$cb = new My_EasyPay_Callback($options);
$p = new EasyPay\Provider31($options['easypay'], $cb, $log);
$p->process();
还需要创建一个配置文件,例如/your_path/etc/config.php。
return array(
// logger setings
'log_prefix' => 'easypay',
'log_debug' => true,
// EasyPay settings
'easypay' => array(
'ServiceId' => 'myserviceid', // service id
'UseSign' => true, // use sign? (true/false)
'EasySoftPKey' => '/your_path/etc/EasyPay/EasySoftPublicKey2.pem', // path for EasyPay public key
'ProviderPKey' => '/your_path/etc/EasyPay/My.ppk', // path for yours private key
),
);
最后,需要配置Web服务器,以便可以从easypay.ua的IP地址访问request.easypay.php。