forci / epay
epay.bg 的库
v0.1.0
2017-12-14 20:33 UTC
Requires
- php: ~5.5|~7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.8
- wucdbm/php-cs-fixers: ~0.1
This package is auto-updated.
Last update: 2024-09-16 08:36:23 UTC
README
待办事项
- 测试
用法
- 创建一个
Forci\Component\Epay\Client\ClientOptions
实例,该实例负责提供所有Forci\Component\Epay\Client\Client
需要的选项。其构造函数需要 epay.bg 提供的商户 ID 和密钥。请记住根据您是否在测试中设置第三个构造函数参数为 true 或 false。 - 创建一个实现了
Forci\Component\Epay\Client\PaymentHandlerInterface
接口的处理程序。此接口具有客户端调用的方法 - 创建一个
Forci\Component\Epay\Client\Client
的实例,传递上述两个 - 要创建一个支付表单,请调用
$client->getEpayForm($id, $amount, $description, $expiry, $formId, $okUrl, $cancelUrl)
- 要创建一个 EasyPay 支付 ID,请调用
$response = $this->client->getEasyPayIdn($id, $amount, $description, $expiry)
。这将返回一个Forci\Component\Epay\Response\EasyPayResponse
响应。调用$response->getIdn()
获取 ID。请注意,此方法会抛出Forci\Component\Epay\Exception\EasyPayGetIdnError
异常。
WucdbmEpayBundle https://packagist.org.cn/packages/wucdbm/epay-bundle 使用此库,前往该链接以获取更多示例。
$options = new \Forci\Component\Epay\Client\ClientOptions($merchantId, $merchantSecret, $isDebug);
// $options->set... to alter any options
$handler = new \My\Project\Payments\Epay\PaymentHandler(LogManager $some, PaymentManager $dependencies);
$client = new \Forci\Component\Epay\Client\Client($options, $handler);
获取支付表单的方法如下
$uniqId = uniqid(); // this is to make autosubmitting easy - $('#formId').submit();
$expiry = new \DateTime('today + 2 days');
// ... other parameters
$form = $client->getEpayForm($id, $amount, $description, $expiry, $formId, $okUrl, $cancelUrl);
// Display the form and optionally auto submit it. Another option is to alter the submit button through the options and let the user do that
获取 EasyPay IDN
$id = $payment->getId();
$amount = $payment->getAmount();
$description = 'Payment #' . $payment->getId();
$expiry = $payment->getExpiryDate();
try {
$response = $this->client->getEasyPayIdn($id, $amount, $description, $expiry);
$idn = $response->getIdn();
// display idn to the user, do some logging.
// the response body is available at $response->getBody();
return $idn;
} catch (\Forci\Component\Epay\Exception\EasyPayGetIdnError $ex) {
$this->logEasyPayRequest($payment, $ex->getBody(), true);
throw $ex;
}
接收支付
$response = $client->receiveResponse($post);
// the client will call your handler, which must deal with the payments received
// $response is an \Forci\Component\Epay\Response\ReceiveResponseInterface instance
// exceptions are caught internally and transformed into responses, the no data exception and checksum mismatch exceptions in particular generate a global error response for epay
echo $response->toString();
exit();
// alternatively, if you use Symfony's HttpFoundation component
$response = \Symfony\Component\HttpFoundation\Response($response->toString());