ihatehandles / paynow
Paynow 的 PHP SDK
v1.0.0
2018-09-27 18:38 UTC
Requires
- rmccue/requests: ^1.7.0
This package is not auto-updated.
Last update: 2024-09-15 11:59:33 UTC
README
composer require ihatehandles/paynow
发起交易
发起交易非常简单,只需使用您的 Paynow 集成详情实例化库。
initiatePayment()
调用将返回 Paynow 返回的响应,但您最感兴趣的是 browserurl
,您应该将其呈现给用户。
<?php require 'vendor/autoload.php'; $paynowIntegrationId = 123456; $paynowIntegrationKey = 'abcdef'; $p = new Paynow\Paynow($paynowIntegrationId, $paynowIntegrationKey); $reference = '123'; $amount = 10.00; $additionalInfo = 'Payment for order '.$reference; $returnUrl = 'http://example.com/thankyou'; $resultUrl = 'http://example.com/result'; $res = $p->initiatePayment( $reference, $amount, $additionalInfo, $returnUrl, $resultUrl ); echo "<a href='".$res->browserurl."'>Make payment</a>";
验证和处理状态更新
我建议使用 resultUrl
来接收类似 webhook 的交易更新。返回 URL 是可以接受的,但对于后台操作,您最好选择更可靠的方案,因为没有保证客户会回到您的 'returnUrl'
。
库有一个非常实用的 processStatusUpdate()
方法,它将根据 Paynow 文档处理 POST 的有效负载。如果有什么问题,它将抛出异常,否则它将返回交易详情。这里最有趣的属性是 status
,我们希望它显示为 Paid
。
<?php require 'vendor/autoload.php'; $paynowIntegrationId = 123456; $paynowIntegrationKey = 'abcdef'; $p = new Paynow\Paynow($paynowIntegrationId, $paynowIntegrationKey); //Method verifies status update hash, and polls Paynow to make sure $transactionDetails = $p->processStatusUpdate($_POST); if ($transactionDetails->status !== 'Paid') return; //ToDo: Code to finish customer purchase, and maybe check if the transaction hasn't already been processed
源代码非常易于阅读,您可以自由地查看 并探索您可以使用的额外选项。