notchpay / notchpay-php
Notch Pay PHP 封装器。
Requires
- php: ^7.4|^8.0|^8.1|^8.2
- ext-json: *
- guzzlehttp/guzzle: ^7.2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- mockery/mockery: ^1.4
- php-coveralls/php-coveralls: ^2.2
- phpunit/phpunit: ^9.0
- scrutinizer/ocular: ^1.7
- vimeo/psalm: ^3.11
README
Notch Pay API 封装器。
安装
您可以通过 composer 安装此包。
composer require notchpay/notchpay-php
使用
将重定向到从 payments/initialize 端点接收的授权 URL。此 URL 仅限一次使用,因此请确保每次支付都生成新的 URL。
当支付成功时,我们将调用您的回调 URL(在您的仪表板中设置或在初始化交易时设置),并将第一步发送的参考作为查询参数返回。
如果您使用测试公钥,我们将调用您的测试回调 URL,否则将调用您的实时回调 URL。
0. 前提条件
确认您的服务器可以与 Notch Pay 服务器建立 TLSv1.2 连接。大多数最新软件都有此功能。如果您遇到任何 SSL 错误,请联系您的服务提供商以获取指导。不要禁用 SSL 伙伴验证!
1. 准备参数
email
、amount
和 currency
是最常用的必填参数。请为每位客户发送唯一的电子邮件。金额接受数值。货币接受 ISO 3166 货币代码。例如,要接受 美元
,请发送 USD
作为货币。
2. 初始化一次性支付
通过调用我们的 API 初始化支付。
use NotchPay\NotchPay; use NotchPay\Payment; NotchPay::setApiKey('sk_1234abcd'); try { $tranx = Payment::initialize([ 'amount'=>$amount, // according to currency format 'email'=>$email, // unique to customers 'currency'=>$currency, // currency iso code 'callback'=>$callback, // optional callback url 'reference'=>$reference, // unique to transactions ]); } catch(\NotchPay\Exceptions\ApiException $e){ print_r($e->errors); die($e->getMessage()); } // redirect to page so User can pay header('Location: ' . $tranx->authorization_url);
当用户输入他们的付款详细信息时,NotchPay 将验证并扣款。它将执行以下所有操作
将支付完成事件发送到您在: https://business.notchpay.co/settings/developer 设置的 Webhook URL
如果未关闭收据,则将 HTML 收据发送到客户的电子邮件。
3. 验证交易
在我们回调到您之后,请在给予价值之前验证交易。
$reference = isset($_GET['reference']) ? $_GET['reference'] : ''; if(!$reference){ die('No reference supplied'); } // initiate the Library's NotchPay Object NotchPay::setApiKey('sk_1234abcd'); try { $tranx = Payment::verify($reference); if ($tranx->transaction->status === 'complete') { // transaction was successful... // please check other things like whether you already gave value for this ref // if the email matches the customer who owns the product etc // Give value } } catch(\NotchPay\Exceptions\ApiException $e){ print_r($e->errors); die($e->getMessage()); }
变更日志
请参阅 CHANGELOG 了解最近更改的详细信息。
贡献
请参阅 CONTRIBUTING 了解详细信息。
安全
如果您发现任何与安全相关的问题,请通过电子邮件 hello@notchpay.co 联系我们,而不是使用问题跟踪器。
许可
MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。