ihatehandles / gava-php-client
用于 Gava API 的 PHP 客户端
v0.0.2
2016-09-20 03:27 UTC
Requires
- rmccue/requests: ^1.6
This package is not auto-updated.
Last update: 2024-09-20 21:57:46 UTC
README
您的 Gava 安装的 PHP 客户端
composer require ihatehandles/gava-php-client
创建检查点
<?php require 'vendor/autoload.php'; $g = new Gava\Gava('http://gava.dev', '12345678'); $checkoutUrl = $g->createCheckout(1, 1.00, 'http://example.com/thankyou', 'http://example.com.cart'); echo "<a href='" . $checkoutUrl . "'>Make payment</a>";
技巧:正如以下 处理 ZIPIT 支付 示例代码所示,您也可以将电话号码和其他几个细节传递给 createCheckout
方法。您可以充分利用这一点。例如,当与商户行合作时,您可以在您的应用程序中收集客户的电话号码,并创建一个检查点,如上所示。然后,您可以在您的应用程序中提供转账说明,每当客户完成转账时,Gava 将通知您的 webhook URL,而客户永远不会离开您的应用程序/网站。
接收、验证和处理 webhook 通知
PHP 客户端为您完成所有工作,因此您可以简单地
<?php require 'vendor/autoload.php'; $g = new Gava\Gava('http://gava.dev', '12345678'); try { $checkout = $g->processWebhook(); } catch(Gava\Exceptions\WebhookException $e) { //Handle how you want. Or simply ignore, because Gava will resend another notification later } //We get here, the checkout is valid and paid, and you can fetch its details $order = $checkout->reference;
查找检查点的状态
您还可以查找检查点。只需记住在 createCheckout
方法中存储返回的检查点哈希值,以便在后续查找中检索它。
例如,像类中的其他方法一样,fetchCheckout
返回检查点的所有详细信息作为对象
例如
<?php require 'vendor/autoload.php'; $gava = new Gava\Gava('http://gava.dev', '12345678'); $checkout = $gava->fetchCheckout('abcdefg'); if (!$checkout->paid) { //Do stuff }
处理 ZIPIT 支付
Gava 能够处理来自 Zipit 转账平台的支付通知。请在为您的银行启用之前咨询我们。
如果您的银行受支持,只需在您的网站或应用程序中指示客户进行转账,然后要求他们提供参考号。收集到参考号后,您现在可以处理他们的支付。即使由于任何原因支付尚未反映,当它通过时,Gava 将完成它并通知您的网站,只要提供的参考号有效且正确。
<?php require 'vendor/autoload.php'; $g = new Gava\Gava('http://gava.dev', '12345678'); //Let's assume the user submits the reference number for their transfer in a form $refNo = $_POST['refNo']; $checkoutUrl = $g->createCheckout( $reference = 1, $amount = 1.00, $returnUrl = 'http://example.com/thankyou', $cancelUrl = 'http://example.com.cart', //We don't need the phone $phone = null, //We pass the reference number to Gava $transactionCode = $refNo, //And let Gava know this is a ZIPIT payment $method = 'ZIPIT' ); //We can drop off processing at this point since Gava will notify your webhook URL. But for fun we can: $checkoutHash = $g->hashFromURL($checkoutUrl); $checkout = $g->fetchCheckout($checkoutHash); if ($checkout->paid) { echo "Thank you for you payment"; }