客户端 PHP

8.21 2024-08-12 18:36 UTC

README

rocketgate-php-sdk

Rocketgate Gateway PHP SDK

此库与 PHP 8.0 或更高版本兼容(请参阅 PHP 支持版本 此处)。

此库支持 Composer 和命名空间,因此与我们的旧(遗留)PHP SDK 不兼容: https://github.com/rocketgate/rocketgate-php-legacy-sdk

项目结构

/examples - 包含各种购买场景的 Gateway SDK 示例用法,以帮助您进行集成

/src - 包含 Gateway SDK 的核心实现

/tests - 包含与 Rocketgate Gateway 的集成示例,可以作为集成测试套件运行

使用 composer 安装

使用 composer 安装(可在 packagist.org 上找到)

composer require --update-no-dev rocketgate/sdk

不使用 composer 安装

创建一个 vendor 文件夹(或使用您的项目外部依赖项文件夹)

mkdir -p vendor/rocketgate

将代码克隆到该文件夹

git clone https://github.com/rocketgate/rocketgate-php-sdk.git vendor/rocketgate

将类添加到您的项目自动加载器或手动添加(如下所示)。

<?php

require "vendor/rocketgate/src/GatewayChecksum.php";
require "vendor/rocketgate/src/GatewayCodes.php";
require "vendor/rocketgate/src/GatewayParameterList.php";
require "vendor/rocketgate/src/GatewayRequest.php";
require "vendor/rocketgate/src/GatewayResponse.php";
require "vendor/rocketgate/src/GatewayService.php";

use RocketGate\Sdk\GatewayRequest;
use RocketGate\Sdk\GatewayResponse;
use RocketGate\Sdk\GatewayService;

$request  = new GatewayRequest();
$response = new GatewayResponse();
$service  = new GatewayService();

$request->Set(GatewayRequest::MERCHANT_ID(), "1");
$request->Set(GatewayRequest::MERCHANT_PASSWORD(), "testpassword");

// [...]

用法

Rocketgate Gateway 的集成示例位于 /tests 文件夹中。

运行完整测试套件(不使用 RG docker 容器)

从 Bash shell

$ sh vendor/rocketgate/sdk/startup.sh

从 sdk 文件夹(/vendor/rocketgate/sdk)手动运行

$ ./vendor/bin/phpunit

运行单个测试

从 sdk 文件夹(/vendor/rocketgate/sdk)运行

$ ./vendor/bin/phpunit ./tests/AuthOnlyTest.php

运行单个示例脚本

从 examples 文件夹(需要在系统 $PATH 上有 php 可执行文件)运行

$ php ./Purchase.php

运行完整测试套件(使用 RG docker 容器)

我们建议使用 Docker 和 Docker Compose 以运行完整测试套件。

  1. 启动 docker 容器。
docker-compose up -d

上述命令首次执行可能需要较长时间,因为所有 PHP Docker 容器依赖项都将下载并安装。

  1. 运行 startup.sh 脚本。
docker exec -it $(docker-compose ps -q --filter name=cli_php) bash startup.sh

重要说明

  • 运行测试需要 PHP >=8.0。
  • 启动脚本 startup.sh 安装 composer PHP 依赖项并运行完整测试套件。
  • 输出应如下所示
    Do not run Composer as root/super user! See https://getcomposer.org.cn/root for details
    Loading composer repositories with package information
    Installing dependencies (including require-dev) from lock file
    Nothing to install or update
    Generating autoload files
    PHPUnit 8.5.28 by Sebastian Bergmann and contributors.
    
    Runtime:       PHP 8.1.9 with Xdebug 3.1.5
    Configuration: /var/client/phpunit.xml
    
    ..........................                                        26 / 26 (100%)
    
    Time: 14.12 seconds, Memory: 6.00MB
    
    OK (26 tests, 46 assertions)
    
  • 成功的测试用例表示一个点("。")。
  • 失败的测试用例将打印 Rocketgate 请求数据以及 "F" 字符。例如
//////////////////////////////////////////////////////////////////////
// ACHTest HAS FAILED
// GUID: 100016C8BAE1717
// Response Code: 0
// Reason Code: 0
// Exception: 
// Auth No: 247218
// AVS: 
// Cancel Date: 
// Card Hash: m77xlHZiPKVsF9p1/VdzTb+CUwaGBDpuSRxtcb7+j24=
// Card Issuer: JPMORGAN CHASE BANK, N.A.
// CVV2: 
// Rebill Date: 
// Scrub: NEGDB=0,PROFILE=0,ACTIVITY=0
//////////////////////////////////////////////////////////////////////F
  • 对源代码 SDK 中的任何不符合 Rocketgate 的修改都将在 ::testComplianceModifications 失败,如下所示
1) RocketGate\Sdk\Tests\GatewayChecksumTest::testComplianceModifications
Modified version. Current checksum 0646c7f28688c3f2ad0c37499e7113d6 does not match base 4b086e326a9d6cb310079994896792c1.
Failed asserting that 'P7.1m' does not contain "m".

/var/client/tests/GatewayChecksumTest.php:17