定制 sanmai/gmopg 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sanmai/gmopg

最新稳定版本:v1.1.3

Composer 安装命令:

composer require sanmai/gmopg

包简介

GMO Payment Gateway API for simple credit card payments

README 文档

README

Build Status Coverage Status Maintainability Latest Stable Version License

Installation

composer require sanmai/gmopg

Configuration

There are two ways to configure the API:

  1. With global constants. Namely, you need to have defined:

      // ショップ情報
    define('GMO_SHOP_ID', 'tshop0000001'); // ショップID
    define('GMO_SHOP_PASSWORD', 'qwerty'); // ショップ名
    define('GMO_SHOP_NAME', 'My Shop'); // ショップパスワード
    define('GMO_TRIAL_MODE', false);

    Where first three you can get from the management panel or from emails from GMO PG.

    The last constant GMO_TRIAL_MODE should be set to true if you're using a test shop password.

  2. By calling these static methods:

    \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);

Testing payments

Currently there is no other way to enable a test mode other than by defining a constant GMO_TRIAL_MODE set to true.

define('GMO_TRIAL_MODE', true);

Testing payments with directly-entered card numbers with test environment credentials requires you to enable such payments as outlined in the documentation.

Basic usage

// 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.

Array of $errors comes in a form similar to this:

array(1) {
  'E01040010' =>
  string(34) "This order ID was used previously."
}

A list of most known error codes. In a readable form. And another.

A typical $response will look like so:

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"
}

Paying with a token

A payment object can accept a token received from the JavaScript API instead of credit card details:

$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

One should use the above method of payment if they're getting the venerable error E61040001.

Transaction details

Now you naturally want to load transaction details for the current payment.

$searchTrade = new \GMO\API\Call\SearchTrade();
$searchTrade->OrderID = $payment->getResponse()->OrderID;
// Copy credential from the original payment
$payment->setupOther($searchTrade);

$response = $searchTrade->dispatch();

In this $response you would find these fields:

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) ""
}

Futher API Documentation

GMO-PG is very secretive seemingly for no reason at all (that's a complete opposite of Stripe), and typically you can only access their documentation upon signing a non-disclosure agreement.

sanmai/gmopg 适用场景与选型建议

sanmai/gmopg 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.08k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2017 年 11 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 sanmai/gmopg 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sanmai/gmopg 我们能提供哪些服务?
定制开发 / 二次开发

基于 sanmai/gmopg 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-11-28