lesterchan / gp-php-sdk
PHP 的 GP SDK 提供了对 GP API 的原生接口。
dev-master
2019-08-16 04:01 UTC
Requires
- php: ^7.2
- ext-json: ^1.7
- guzzlehttp/guzzle: ^6.3@dev
This package is auto-updated.
Last update: 2024-09-16 14:59:21 UTC
README
PHP 的 GP SDK 提供了对 GP API 的原生接口。这是一个仍在进行中的(WIP)项目,因此它将位于 master 分支。
安装
composer require lesterchan/gp-php-sdk
使用
OAuth
生成一个提供 OAuth 认证界面的 Web URL。
这有助于最终用户登录或注册 GP。
/** * @param string $codeVerifier Code verifier * @param string $requestToken Request token * @param string $redirectUri Redirect URI * @param string $scope Scope (payment.one_time_charge or payment.recurring_charge) */ $gp->getOauthAuthorizeUrl($codeVerifier, $requestToken, $redirectUri, $scope);
通过传递从 GP 返回 URL 收到的 code 生成 oauth token。
/** * @param string $code Code * @param string $redirectUri Redirect URI * @param string $codeVerifier Code verifier */ $gp->getAccessToken($code, $redirectUri, $codeVerifier);
一次性费用
初始化。
/** * @param string $partnerId Partner ID * @param string $partnerSecret Partner Secret * @param string $clientId Client ID * @param string $clientSecret Client Secret * @param string $merchantId Merchant ID */ $gp = new GP\OneTimeCharge($partnerId, $partnerSecret, $clientId, $clientSecret, $merchantId);
设置启动一次性付款所需的信息。
/** * @param string $txId order ID * @param string $groupTxId partner transaction ID * @param int $amount Transaction amount as integer * @param string $description description of the charge (optional) */ $gp->initCharge($txId, $groupTxId, $amount, $description);
完成用户授权的付款。
/** * @param string $accessToken OAuth access token * @param string $partnerTxId partner transaction ID */ $gp->completeCharge($accessToken, $partnerTxId);
令牌化
初始化。
/** * @param string $partnerId Partner ID * @param string $partnerSecret Partner Secret * @param string $clientId Client ID * @param string $clientSecret Client Secret * @param string $merchantId Merchant ID */ $gp = new GP\Tokenization($partnerId, $partnerSecret, $clientId, $clientSecret, $merchantId);
通过客户信用启动绑定过程。
/** * @param string $txId order ID */ $gp->bind($txId);
对已完成 GP 绑定过程的客户进行收费。
/** * @param string $accessToken OAuth access token * @param string $txId order ID * @param string $groupTxId partner transaction ID * @param int $amount Transaction amount as integer * @param string $description description of the charge (optional) */ $gp->charge($accessToken, $txId, $groupTxId, $amount, $description);
取消绑定过程中生成的令牌。
/** * @param string $accessToken OAuth access token * @param string $txId order ID */ $gp->unbind($accessToken, $txId);
查看绑定用户的钱包余额。
/** * @param string $accessToken OAuth access token */ $gp->getWalletInfo($accessToken);
状态/退款
检查交易状态。
/** * @param string $accessToken OAuth access token * @param string $txId order ID */ $gp->checkChargeStatus($accessToken, $txId);
对特定交易进行全额或部分退款。
/** * @param string $accessToken OAuth access token * @param string $txId order ID * @param string $groupTxId partner transaction ID * @param string $originTxID original partner transaction ID * @param int $amount Transaction amount as integer * @param string $description description of the charge (optional) */ $gp->refund($accessToken, $txId, $groupTxId, $originTxID, $amount, $description);
检查退款交易的状态。
/** * @param string $accessToken OAuth access token * @param string $txId order ID */ $gp->checkRefundStatus($accessToken, $txId);
POS
初始化。
/** * @param string $partnerId Partner ID * @param string $partnerSecret Partner Secret * @param string $merchantId Merchant ID * @param string $terminalId Terminal ID */ $gp = new GP\Pos($partnerId, $partnerSecret, $merchantId, $terminalId);
创建付款订单并返回一个二维码。
/** * @param string $txId order ID * @param int $amount Transaction amount as integer */ $gp->createMerchantPresentQrCode($txId, $amount);
执行从请求二维码关联的钱包中收费的付款交易。
/** * @param string $txId order ID * @param int $amount Transaction amount as integer * @param string $qrCode QR code being scanned */ $gp->performConsumerPresentQrCode($txId, $amount, $qrCode);
返回付款交易或退款交易的详细信息。
/** * @param string $txId order ID */ $gp->qrCodeInquiry($txId);
取消挂起的付款。
/** * @param string $origTxID Original order ID */ $gp->cancelTransaction($origTxID);
退款之前的成功付款。
/** * @param string $txID order ID * @param string $origTxID Original order ID * @param int $amount Transaction amount as integer */ $gp->refundTransaction($txID, $origTxID, $amount);
其他
默认情况下,SDK 将使用测试 URL。要切换到生产 URL,使用
$gp->useProduction();
默认为 SG。接受的值是 SG、MY、VN、PH 和 TH。
/** * @param string $countryCode Country code (alpha-2) */ $gp->setCountryCode($countryCode);
默认为 SGD。接受的值是 SGD、MYR、VND、PHP 和 THB。
/** * @param string $currency Currency */ $gp->setCurrency($currency);
生成 nonce。
/** * @param int $length Length */ $gp->generateNonce($length);
请参阅 GP PHP SDK 示例代码仓库 获取一些示例代码。