sanmai / gmopg
此包已被废弃且不再维护。未建议替代包。
GMO支付网关API,用于简单的信用卡支付
v1.1.3
2019-05-21 05:21 UTC
Requires
- php: ^7.0
- guzzlehttp/guzzle: ^6
- sanmai/pipeline: ^0.3.2|^2.0|^3.0.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.6
- php-coveralls/php-coveralls: >=1.0
- phpunit/phpunit: ^6
README
安装
composer require sanmai/gmopg
配置
配置API有两种方式
-
使用全局常量。也就是说,你需要定义以下内容
// ショップ情報 define('GMO_SHOP_ID', 'tshop0000001'); // ショップID define('GMO_SHOP_PASSWORD', 'qwerty'); // ショップ名 define('GMO_SHOP_NAME', 'My Shop'); // ショップパスワード define('GMO_TRIAL_MODE', false);
前三个可以从管理面板或从GMO PG的电子邮件中获取。
最后一个常量
GMO_TRIAL_MODE
应该设置为true
,如果你使用的是测试商店密码。 -
通过调用这些静态方法
\GMO\API\Defaults::setShopID($shopId); \GMO\API\Defaults::setShopName($shopName); \GMO\API\Defaults::setPassword($shopPassword); // When using a test password, this constant is mandatory //define('GMO_TRIAL_MODE', true);
测试支付
目前除了定义常量 GMO_TRIAL_MODE
并将其设置为 true
以外,没有其他方法可以启用测试模式。
define('GMO_TRIAL_MODE', true);
使用测试环境凭据直接输入的卡号进行测试支付需要你按照文档中概述的方式启用此类支付。
基本用法
// A wrapper object that does everything for you. $payment = new \GMO\ImmediatePayment(); // Unique ID for every payment; probably should be taken from an auto-increment field from the database. $payment->paymentId = 123; $payment->amount = 1000; // This card number can be used for tests. $payment->cardNumber = '4111111111111111'; // A date in the future. $payment->cardYear = '2020'; $payment->cardMonth = '7'; $payment->cardCode = '123'; // Returns false on an error. if (!$payment->execute()) { $errors = $payment->getErrors(); foreach ($errors as $errorCode => $errorDescription) { // Show an error code and a description to the customer? Your choice. // Probably you want to log the error too. } return; } // Success! $response = $payment->getResponse(); /** @var \GMO\API\Response\ExecTranResponse $response */ // You would probably want to save the response in the database for future reference. // The response can be used to query details about a transaction, make refunds and so on.
$errors
数组的形式类似于以下内容
array(1) {
'E01040010' =>
string(34) "This order ID was used previously."
}
典型的$response
将看起来像这样
class GMO\API\Response\ExecTranResponse#1 (9) {
public $ACS =>
string(1) "0"
public $OrderID =>
string(10) "1517000000"
public $Forward =>
string(7) "0afd1200"
public $Method =>
string(1) "1"
public $PayTimes =>
string(0) ""
public $Approve =>
string(7) "0112234"
public $TranID =>
string(28) "180111111111111111111344439"
public $TranDate =>
string(14) "20221222213141"
public $CheckString =>
string(32) "68b329da9893e34099c7d8ad5cb9c940"
}
使用令牌支付
支付对象可以接受从JavaScript API接收到的令牌,而不是信用卡详情
$payment = new \GMO\ImmediatePayment(); $payment->paymentId = 123; // Unique ID for every payment; see above $payment->amount = 1000; // Card details are unnecessary in this case $payment->token = $_POST['token']; if (!$payment->execute()) { // ... same as above } // ... same as above
如果遇到尊敬的错误 E61040001,应使用上述支付方法。
交易详情
现在你自然会想加载当前支付的交易详情。
$searchTrade = new \GMO\API\Call\SearchTrade(); $searchTrade->OrderID = $payment->getResponse()->OrderID; // Copy credential from the original payment $payment->setupOther($searchTrade); $response = $searchTrade->dispatch();
在这$response
中,你会找到这些字段
class GMO\API\Response\SearchTradeResponse#4950 (21) {
public $AccessID =>
string(32) "b026324c6904b2a9cb4b88d6d61c81d1"
public $AccessPass =>
string(32) "26ab0db90d72e28ad0ba1e22ee510510"
public $OrderID =>
string(10) "1517000000"
public $Status =>
string(5) "SALES"
public $ProcessDate =>
string(14) "20221222213141"
public $JobCd =>
string(5) "SALES"
public $ItemCode =>
string(7) "0000000"
public $Amount =>
string(4) "4999"
public $Tax =>
string(1) "0"
public $SiteID =>
string(0) ""
public $MemberID =>
string(0) ""
public $CardNo =>
string(16) "************1111"
public $Expire =>
string(4) "2307"
public $Method =>
string(1) "1"
public $PayTimes =>
string(0) ""
public $Forward =>
string(7) "0afd1200"
public $TranID =>
string(28) "180111111111111111111344439"
public $Approve =>
string(7) "0112234"
public $ClientField1 =>
string(0) ""
public $ClientField2 =>
string(0) ""
public $ClientField3 =>
string(0) ""
}
更多API文档
GMO-PG非常神秘,似乎没有任何原因(这与Stripe完全相反),通常只有在你签署了保密协议后才能访问他们的文档。