genome-eu / hpp
Genome PHP 库
2.0.3
2021-12-21 14:33 UTC
Requires
- php: >=7.1
- ext-curl: *
- ext-iconv: *
- ext-json: *
- ext-mbstring: *
- psr/log: ~1.0
Requires (Dev)
- phpstan/phpstan: 0.8.5
- squizlabs/php_codesniffer: 1.5.3
- dev-master / 2.0.x-dev
- 2.0.3
- 2.0.1
- 2.0
- 1.0.1
- dev-dependabot/composer/squizlabs/php_codesniffer-3.6.2
- dev-dev-20211203-cherniy-updates-related-to-back-url
- dev-dev-dolya-20200810-change-logic-of-signature-generation
- dev-dev-2020-07-20-chumachenko-hpp-client-update-v2
- dev-dev-2020-06-10-dolya-fix-package-namming
This package is auto-updated.
Last update: 2024-09-26 06:30:25 UTC
README
您可以在https://merchant.genome.eu/注册genome账户
需求
PHP 7.1 及更高版本。
Composer
您可以通过Composer安装绑定。运行以下命令
composer require genome-eu/hpp
要使用绑定,请使用Composer的自动加载
require_once('vendor/autoload.php');
入门
简单的支付表单
$scriney = new \Genome\Scriney('publicKey', 'privateKey'); echo $scriney->buildButton('userId')->buildPopup();
预选产品的支付表单
$scriney = new \Genome\Scriney('publicKey', 'privateKey'); echo $scriney->buildButton('userId')->setProductId('productIdInMportal')->buildPopup();
填写用户信息的支付表单
$scriney = new \Genome\Scriney('publicKey', 'privateKey'); echo $scriney->buildButton('userId')->setUserInfo( new \Genome\Lib\Model\UserInfo( 'example@example.com', 'John', 'Anderson', 'USA', 'Los angeles', '90217', '2896 Providence Lane', '6267746913' ) )->buildPopup();
自定义返回URL的支付表单
$scriney = new \Genome\Scriney('publicKey', 'privateKey'); echo $scriney->buildButton('userId')->setSuccessReturnUrl( "https://example.com/success" )->setDeclineReturnUrl( "https://example.com/decline" )->setBackUrl( "https://example.com/back" )->buildPopup();
自定义参数的支付表单,参数将在回调中返回
$scriney = new \Genome\Scriney('publicKey', 'privateKey'); echo $scriney->buildButton('userId')->setCustomParams( [ 'custom_param1' => 'param value 1', 'custom_param2' => 'param value 2' ] )->buildPopup();
动态产品的支付表单
$scriney = new \Genome\Scriney('publicKey', 'privateKey'); echo $scriney->buildButton('userId')->setCustomProducts( [ new \Genome\Lib\Model\FixedProduct( 'myProducId1', 'Garden Table', 198.98, 'USD', null, null, 'Magic Garden Table & Set of 2 Chairs' ), new \Genome\Lib\Model\FixedProduct( 'myProducId2', 'Chair', 110.50, 'USD', null, null, 'Magic Garden Rocking Chair' ) ] )->buildPopup();
验证回调数据
$data - 从'php://input'读取的回调响应数据的json字符串;$headers - 回调响应头部的数组
$scriney = new \Genome\Scriney('publicKey', 'privateKey'); if ($scriney->validateCallback($data, $headers)) { echo 'callback data is valid'; } else { echo 'invalid callback data'; }
API
重新计费API
通过现有产品创建简单的重新计费请求
$scriney = new \Genome\Scriney('publicKey', 'privateKey'); try { $result = $scriney->createRebillRequest( '569ded06-c1c0-4ecb-9b9c-59c1630f6969', 'userId' )->setProductId( 'p_3ba675d110' )->setUserInfo( new \Genome\Lib\Model\UserInfo( 'example@example.com', 'John', 'Anderson', 'USA', 'Los angeles', '90217', '2896 Providence Lane', '6267746913' ) )->send(); } catch (\Genome\Lib\Exception\GeneralGenomeException $e) { // } if ($scriney->validateApiResult($result)) { //Api result is valid }
使用自定义产品和自定义参数创建重新计费请求
$scriney = new \Genome\Scriney('publicKey', 'privateKey'); try { $result = $scriney->createRebillRequest( '569ded06-c1c0-4ecb-9b9c-59c1630f6969', 'userId' )->setUserInfo( new \Genome\Lib\Model\UserInfo( 'example@example.com', 'John', 'Anderson', 'USA', 'Los angeles', '90217', '2896 Providence Lane', '6267746913' ) )->setCustomProduct( new \Genome\Lib\Model\FixedProduct( 'myProducId1', 'Garden Table', 198.98, 'USD', null, null, 'Magic Garden Table & Set of 2 Chairs' ) )->setCustomParams( [ 'custom_param_name1' => 'value 1', 'custom_param_name2' => 'value 2' ] )->send(); } catch (\Genome\Lib\Exception\GeneralGenomeException $e) { // } if ($scriney->validateApiResult($result)) { //Api result is valid //Api result example: /* Array ( [transactionId] => hppR1463555724.2658mId548aId9 [uniqueUserId] => userId [totalAmount] => 198.98 [currency] => USD [transactionType] => SALE [status] => success [message] => Transaction processed successfully [code] => 0 [productList] => Array ( [0] => Array ( [productId] => myProducId1 [name] => Garden Table [amount] => 198.98 [currency] => USD ) ) [customParameters] => Array ( [custom_param_name1] => value 1 [custom_param_name2] => value 2 ) [checkSum] => 285e7c239dd8945b49157e36c0000692932e3dca04e8581ffa43abecef260beb ) */ }
取消订阅API
$scriney = new \Genome\Scriney('publicKey', 'privateKey'); $result = $scriney->stopSubscription('hppR1463555724.2658mId548aId9', 'userId'); if ($scriney->validateApiResult($result)) { //Api result is valid }
取消试用期产品API
$scriney = new \Genome\Scriney('publicKey', 'privateKey'); $result = $scriney->cancelPostTrial('hppR1463555724.2658mId548aId9'); if ($scriney->validateApiResult($result)) { //Api result is valid }
全额/部分退款API
$scriney = new \Genome\Scriney('publicKey', 'privateKey'); $result = $scriney->refund('hppR1463555724.2658mId548aId9', 123.24, 'USD'); if ($scriney->validateApiResult($result)) { //Api result is valid } //Api result example /* Array ( [message] => Refund processed successfully, but all subscriptions already stopped. [status] => Success [transactionId] => hppAR1468587714.1807mId548aId9 [checkSum] => ee7ecd3b401735c40c5da4c3dcaf38952df5721d9626402cbbc1ccadd65b5616 ) */
开发
安装依赖项
composer install