lzaplata/thepay

ThePay 2.0 对 Nette 框架的包装器

v1.0.0 2022-02-23 13:23 UTC

This package is auto-updated.

Last update: 2024-09-23 19:45:52 UTC


README

这是一个用于 ThePay 2.0 支付网关的小型 Nette 框架包装器。

安装

安装库的最简单方法是使用 Composer。

$ composer require lzaplata/thepay: dev-master

或者编辑项目中 composer.json 文件

"require": {
        "lzaplata/thepay": "dev-master"
}

您需要在 config.neon 文件中将库注册为扩展。

extensions:
        thepay: LZaplata\ThePay\DI\Extension

现在您可以设置参数...

thepay:
        demo            : true|false
        merchantId      : *
        projectId       : *
        apiPassword     : *

...并将库自动注入到表示器中

use LZaplata\ThePay\Service;

/** @var Service @inject */
public $thepay;

用法

创建支付参数,设置返回或通知 URL,就像在原始 API 客户端示例中一样。

https://packagist.org.cn/packages/thepay/api-client

$paymentParams = new CreatePaymentParams($amount, $currencyCode, $uid);
$paymentParams->setReturnUrl("some return URL");

创建支付。

$payment = $this->thepay->createPayment($paymentParams);

重定向到支付网关。

$this->sendResponse(new RedirectResponse($payment->getPayUrl()));