tuks128 / g2a-pay-php5-api
此包已被废弃,不再维护。没有建议的替代包。
G2A PAY - PHP API,复杂的PHP5 CURL库
v1.0
2018-07-30 09:35 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2020-01-19 05:42:13 UTC
README
复杂的PHP5 CURL库。另请参阅官方文档:https://pay.g2a.com/documentation#introduction
库的出色功能:
- 获取支付详情
- 设置折扣
- 轻松添加商品到订单
- 验证IPN哈希
安装(Composer)
composer require tuks128/g2a-pay-php5-api
初始化
<?php
use Tuxxx128\G2aPay\G2aPayApi;
use Tuxxx128\G2aPay\G2aPayItem;
$g2aPayApi = new G2aPayApi('API HASH', 'SECRET KEY', true, 'EMAIL OF STORE');
构造函数中的布尔类型确定环境的生产模式(true)或开发模式(false)。
添加新商品到订单列表
<?php
$item = (new G2aPayItem)->itemTemplate();
$item->name = "My item";
$item->url = "http://...";
$item->price = 10; // default currency is 'EUR'
$g2aPayApi->addItem($item);
设置折扣(百分比或固定金额)
<?php
$item = (new G2aPayItem)->itemTemplate();
$item->name = "Discount";
$item->url = "http://...";
设置超过百分比
$g2aPayApi->addPercentDiscountItem($item, 25); // 25% from total amount
或者您可以直接设置固定金额
$g2aPayApi->addAmountDiscountItem($item, 5); // 5 EUR
更改默认货币
此功能未计算...
<?php
$g2aPayApi->setCurrency("USD"); // from default currency 'EUR' to 'USD'
创建新支付
<?php
$g2aPayApi->setUrlFail("http://..");
$g2aPayApi->setUrlSuccess("http://..");
$g2aPayApi->setOrderId(ORDER ID);
// $g2aPayApi->setEmail('user@server.tld');
header('Location: '.$g2aPayApi->getRedirectUrlOnGateway());
获取完整交易详情
<?php
$transactionDetail = $g2aPayApi->getPaymentDetailById($transactionId);
var_dump($transactionDetail);
检测当前环境
也许您需要在您的应用程序中检测环境。
<?php
if($g2aPayApi->checkIsProductionEnvironment()) {
// ...
}
else {
// ...
}
验证IPN哈希
<?php
if($_POST['hash'] == $g2aPayApi->calculateIpnHash($transactionId, $orderId, $amount)) {
// ...
}
else {
// ...
}
后续方法
<?php
echo $g2aPayApi->getTotalPrice();
echo ' ';
echo $g2aPayApi->getCurrency();