yanosh-k/epay

一个用于简化与保加利亚支付门户ePay工作的PHP类。

1.2.0 2021-04-22 14:32 UTC

This package is auto-updated.

Last update: 2024-09-22 22:30:38 UTC


README

一个用于简化与保加利亚支付门户ePay工作的PHP类。

关于ePay(来自其网站的摘录)

该公司专注于支付系统的制作、电子贸易以及通过互联网传输信息的安全性。公司负责处理银行卡支付和公开网络中的银行交易。公司的主要活动与操作支付系统ePay.bg®、ePayVoice®(电话支付)、B-pay(自动柜员机支付)有关。

用法

安装

使用composer

  1. 安装包
composer require yanosh-k/epay
  1. 需要composer自动加载器
<?php
    require_once('vendor/autoload.php'):
    $epay = new Yanoshk\Epay(array(/*...*/));

手册

  1. 下载或复制项目中的src/Epay.php
  2. 需要库
<?php
    require_once('your_project/Epay.php'):
    $epay = new Yanoshk\Epay(array(/*...*/));

初始化交易

交易通过向ePay门户发送POST请求来初始化。所有完成交易所需的数据(发票ID、交易总额等)作为POST参数传递。通常使用带有隐藏输入字段的表单来引导用户到支付门户并传递这些信息。

创建用于引导用户到支付门户的表单

  1. 使用在完成商户资料注册后收到的商户信息初始化Epay类
$epay = new Yanoshk\Epay(array(
    // the submit url for the form that will be generated. If not passed this defaults to the demo portal url.
    // After going live, you can change the default inside the class
    'submitURL'                 => 'https://demo.epay.bg/'
    // the client number (CIN) as seen in the merchant profile
    , 'clientNumber'              => 'D468695585'
    // the client secret used to create the HMAC
    , 'clientSecret'              => 'DSY6AJN6XOT7VEMV2H77LXVMC2D4B9X4JSDSCNEQ7WPYYJZ5JF1FR5JZS6P23M99'
    // the client email address - either this or the CIN should be passed
    , 'clientEmail'               => 'me@yanosh.net'
    // the expiration date of the transaction. After it the transaction will be automatically cancelled.
    // You can pass an exact date or a a number of seconds from now until the expiration
    // if you want to pass seconds you should append a plus sing to the passed string
    // 'transactionExpirationDate' => '+604800' - which is one week
    , 'transactionExpirationDate' => '25.05.2015 22:00:00'
));
  1. 添加当前交易信息
 $epay->setTransactionData(array(
    // The url to which the user is redirected after successfully complete the transaction.
    // Redirecting the user to it doesn't mean that any money have been transferred.
    'successURL'  => 'http://example.com/successfull-payment'
    // The url to which the user is redirected if she cancels the payment process
    , 'cancelURL'   => 'http://example.com/canceled-payment'
    // The invoice ID from the merchant`s own store system
    , 'invocieID'   => '1003423'
    // The total amount of the purchase - the amount is in BGN
    , 'totalAmount' => 23.99
    // Optional field containing information about the purchase
    , 'description' => 'On-line ticket/s for live streaming'
    // If not passed this defaults to paylogin which means the user should use hers ePay profile
    // to complete the transaction
    // The possible values are: credit_paydirect, let_pay
    , 'paymentWindow' => 'paylogin'
));
  1. 生成用于引导用户到支付门户的表单。
// This function accepts only one parameter and that is the created form id attribute value
$from = $epay->createForm('epay-form');

此函数捕获的输出应如下所示

<form id="epay-payment-form" method="POST" action="https://demo.epay.bg/"><input type="hidden" value="D468695585" name="MIN">
    <input type="hidden" name="PAGE" value="paylogin">
    <input type="hidden" name="INVOICE" value="1031">
    <input type="hidden" name="AMOUNT" value="15">
    <input type="hidden" name="EXP_TIME" value="29.08.2015 20:56:03">
    <input type="hidden" name="DESCR" value="Online ticket/s for live streaming">
    <input type="hidden" name="CURRENCY" value="BGN">
    <input type="hidden" name="LANG" value="bg">
    <input type="hidden" name="ENCODING" value="utf-8">
    <input type="hidden" name="URL_OK" value="http://example.com/successfull-payment">
    <input type="hidden" name="URL_CANCEL" value="http://example.com/canceled-payment">
    <input type="hidden" name="ENCODED" value="ASDFewfdsfh56134RQAWESFasdgfjFUOHmbvnBSQaSDFASF23434545DSFGGADSAfasdvzxcgdsfg">
    <input type="hidden" name="CHECKSUM" value="afdsf345tsfggjdyfu36443rasd">
</form>
  1. 使用任何希望的方法提交表单并将用户引导到支付门户。

捕获支付

一旦系统确定交易状态,支付门户将通知之前定义的URL(在商户资料中设置)以通知交易状态。对于单一发票的通知会发送,直到从URL收到积极响应,或者直到30天内没有收到积极响应。

ePay目前使用的发送通知的方案如下

 1) 5 tries in an interval less than a minute
 2) 4 tries on every 15 minutes
 3) 5 tries on every hour
 4) 6 tries on every 3 hours
 5) 4 tries on every 6 hours
 6) 1 try a day
  1. 解析通知
// Only the client secret is needed for this operation
$epay = new Yanoshk\Epay(array('clientSecret' => 'DSY6AJN6XOT7VEMV2H77LXVMC2D4B9X4JSDSCNEQ7WPYYJZ5JF1FR5JZS6P23M99'));


// Will return an empty array if the passed that was incorrect
$data            = $epay->getNotificationData($_POST);


// Contained data (show for example only)
// This is the first of many (most times will be just one) transaction items
$transactionInfoFirst = isset($data[0]) ? $data[0] : array();

$transactionInfo变量应包含以下格式的信息

array(
    'INVOICE'  => '1234000234'
    'STATUS'   => 'PAID'
    'PAY_TIME' => '20150821113940'
    'STAN'     => '031173'
    'BCODE'    => '031173'
)
  1. 生成适当的响应
// One ore more transaction items might be present
$response = [];
foreach ($data as $transactionInfo) {
    $response[]   = Yanoshk\Epay::generateNotificationResponse([
            'error'     => empty($transactionInfo) ? 'Not valid CHECKSUM' : null,
            'status'    => $existsOrder ? 'OK' : 'ERR',
            'invoiceID' => $transactionInfo['INVOICE']
    ]);
}

echo implode('', $response);

一个示例响应可能如下所示

INVOICE=1027:STATUS=OK
INVOICE=5029:STATUS=OK