chapdel / notchpay-php
Notch Pay PHP 包装器。
1.1
2024-01-18 03:35 UTC
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的PHP 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()); }
更新日志
有关最近更改的更多信息,请参阅更新日志。
贡献
有关详细信息,请参阅贡献指南。
安全
如果您发现任何安全相关的问题,请通过电子邮件hello@notchpay.co联系,而不是使用问题跟踪器。
许可协议
MIT许可(MIT)。有关更多信息,请参阅许可文件。