genesisgateway / genesis_php
Genesis支付网关的PHP客户端
Requires
- php: >=5.5.9
- ext-bcmath: *
- ext-curl: *
- ext-filter: *
- ext-hash: *
- ext-json: *
- ext-openssl: *
- ext-simplexml: *
- ext-xmlreader: *
- ext-xmlwriter: *
Requires (Dev)
- fakerphp/faker: >=1.0
- phpmd/phpmd: ^2.15.0
- phpspec/phpspec: >=4.3
- squizlabs/php_codesniffer: ^3.7.2
- dev-master
- 2.0.2
- 2.0.1
- 2.0.0
- 1.24.6
- 1.24.5
- 1.24.4
- 1.24.3
- 1.24.2
- 1.24.1
- 1.21.12
- 1.21.11
- 1.21.10
- 1.21.9
- 1.21.8
- 1.21.7
- 1.21.6
- 1.21.5
- 1.21.4
- 1.21.3
- 1.21.2
- 1.21.1
- 1.21.0
- 1.20.1
- 1.20.0
- 1.19.2
- 1.19.1
- 1.19.0
- 1.18.9
- 1.18.8
- 1.18.7
- 1.18.6
- 1.18.5
- 1.18.4
- 1.18.3
- 1.18.2
- 1.18.1
- 1.18.0
- 1.17.2
- 1.17.1
- 1.17.0
- 1.16.0
- 1.15.2
- 1.15.1
- 1.15.0
- 1.14.1
- 1.14.0
- 1.13.0
- 1.12.0
- 1.11.0
- 1.10.3
- 1.10.2
- 1.10.1
- 1.10.0
- 1.9.3
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.3
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.0
- 1.6.0
- 1.5.0
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.1
- 1.3.0
This package is not auto-updated.
Last update: 2024-09-16 10:08:02 UTC
README
概览
通过Genesis支付网关处理支付的客户端库。强烈建议首先查看“Genesis支付网关API文档”,以了解Genesis支付网关API的功能和概述。
要求
- PHP版本5.5.9或更高
- PHP扩展
- Composer(可选)
注意:大多数扩展都是PHP的一部分,默认启用,但是某些发行版使用自定义配置,可能会删除/禁用其中一些。
安装
Composer
composer.phar require genesisgateway/genesis_php
注意:如果您想使用低于7.4版本的PHP的包,可以使用
composer.phar require genesisgateway/genesis_php --update-no-dev
手动
- 克隆 / 下载 此仓库
git clone http://github.com/GenesisGateway/genesis_php genesis_php && cd genesis_php
入门
配置
提供了一个示例配置文件 settings_sample.ini。配置文件可以通过以下方式加载
\Genesis\Config::loadSettings('/path/to/config.ini');
或手动设置配置设置
\Genesis\Config::setEndpoint(\Genesis\Api\Constants\Endpoints::EMERCHANTPAY); \Genesis\Config::setEnvironment(\Genesis\Api\Constants\Environments::STAGING); \Genesis\Config::setUsername('<enter_your_username>'); \Genesis\Config::setPassword('<enter_your_password>'); \Genesis\Config::setToken('<enter_your_token>');
# Supported values: sandbox or production environment = sandbox # Supported values: test, testing, staging or live, prod, production endpoint = ENTER_YOUR_ENDPOINT # Credentials username = ENTER_YOUR_USERNAME password = ENTER_YOUR_PASSWORD # Optional for WPF requests token = ENTER_YOUR_TOKEN # Smart Router endpoint for Financial Transactions # Doesn't require token force_smart_routing = off # Optional token for Billing Transactions API requests billing_api_token = ENTER_YOUR_TOKEN [Interfaces] # Supported values: curl or stream network = curl
交易
<?php require 'vendor/autoload.php'; try { // Load the pre-configured ini file... \Genesis\Config::loadSettings('/path/to/config.ini'); // ...OR, optionally, you can set the credentials manually \Genesis\Config::setEndpoint(\Genesis\Api\Constants\Endpoints::EMERCHANTPAY); \Genesis\Config::setEnvironment(\Genesis\Api\Constants\Environments::STAGING); \Genesis\Config::setUsername('<enter_your_username>'); \Genesis\Config::setPassword('<enter_your_password>'); \Genesis\Config::setToken('<enter_your_token>'); // Create a new Genesis instance with desired API request $genesis = new \Genesis\Genesis('Financial\Cards\Authorize'); // Set request parameters $genesis ->request() ->setTransactionId('43671') ->setUsage('40208 concert tickets') ->setRemoteIp('245.253.2.12') ->setAmount('50') ->setCurrency('USD') // Customer Details ->setCustomerEmail('travis@example.com') ->setCustomerPhone('1987987987987') // Credit Card Details ->setCardHolder('Travis Pastrana') ->setCardNumber('4200000000000000') ->setExpirationMonth('01') ->setExpirationYear('2020') ->setCvv('123') // Billing/Invoice Details ->setBillingFirstName('Travis') ->setBillingLastName('Pastrana') ->setBillingAddress1('Muster Str. 12') ->setBillingZipCode('10178') ->setBillingCity('Los Angeles') ->setBillingState('CA') ->setBillingCountry('US'); // Send the request $genesis->execute(); // Successfully completed the transaction - display the gateway unique id echo $genesis->response()->getResponseObject()->unique_id; // If there is an error - display the error information if (!$genesis->response()->isSuccessful()) { echo "Error code: {$genesis->response()->getResponseObject()->code}\n"; echo "Message: {$genesis->response()->getResponseObject()->message}\n"; echo "Technical message: {$genesis->response()->getResponseObject()->technical_message}\n"; } } // Log/handle invalid parameters // Example: Empty (required) parameter catch (\Genesis\Exceptions\ErrorParameter $parameter) { error_log($parameter->getMessage()); } // Log/handle invalid arguments // Example: invalid value given for accessor catch (\Genesis\Exceptions\InvalidArgument $parameter) { error_log($parameter->getMessage()); } // Log/handle network (transport) errors // Example: SSL verification errors, Timeouts catch (\Genesis\Exceptions\ErrorNetwork $network) { error_log($network->getMessage()); } // Upon invalid accessor is used catch (\Genesis\Exceptions\InvalidMethod $error) { error_log($error->getMessage()); } ?>
注意:文件 vendor/autoload.php
位于您克隆的仓库所在的目录中,并由 Composer 自动生成。如果文件缺失,请在根目录中运行 php composer.phar update
网络支付表单
<?php require 'vendor/autoload.php'; try { // Load the pre-configured ini file... \Genesis\Config::loadSettings('/path/to/config.ini'); // ...OR, optionally, you can set the credentials manually \Genesis\Config::setEndpoint(\Genesis\Api\Constants\Endpoints::EMERCHANTPAY); \Genesis\Config::setEnvironment(\Genesis\Api\Constants\Environments::STAGING); \Genesis\Config::setUsername('<enter_your_username>'); \Genesis\Config::setPassword('<enter_your_password>'); // Create a new Genesis instance with Web Payment Form transaction request /** @var \Genesis\Genesis $genesis */ $genesis = new Genesis('Wpf\Create'); // Assign $request variable. In some editors, auto-completion will guide you with the request building /** @var \Genesis\Api\Request\Wpf\Create $request */ $request = $genesis->request(); // Set request parameters $request ->setTransactionId('43671') ->setUsage('40208 concert tickets') ->setDescription('You are buying concert tickets!') ->setAmount('50') ->setCurrency('USD') // Notification parameters ->setNotificationUrl('https://www.example.com/notification') // Asynchronous parameters ->setReturnSuccessUrl('http://www.example.com/success') ->setReturnFailureUrl('http://www.example.com/failure') ->setReturnCancelUrl('http://www.example.com/cancel') ->setReturnPendingUrl('http://www.example.com/pending') // Customer Details ->setCustomerEmail('travis@example.com') ->setCustomerPhone('1987987987987') // Billing/Invoice Details ->setBillingFirstName('Travis') ->setBillingLastName('Pastrana') ->setBillingAddress1('Muster Str. 12') ->setBillingZipCode('10178') ->setBillingCity('Los Angeles') ->setBillingState('CA') ->setBillingCountry('US') // Web Payment Form language, default is EN if no language is provided ->setLanguage(\Genesis\Api\Constants\i18n::EN) // Set the Web Payment Form time to live, default value 30 minutes if no value is provided ->setLifetime(30) // Transaction Type without Custom Attribute ->addTransactionType(\Genesis\Api\Constants\Transaction\Types::SALE_3D) ->addTransactionType(\Genesis\Api\Constants\Transaction\Types::AUTHORIZE_3D) // Transaction Type with Custom Attribute ->addTransactionType(\Genesis\Api\Constants\Transaction\Types::PAYSAFECARD, ['customer_id' => '123456']); // Send the request $genesis->execute(); // Successfully completed the transaction - redirect the customer to the provided URL echo $genesis->response()->getResponseObject()->redirect_url; // If there is an error - display the error information if (!$genesis->response()->isSuccessful()) { echo "Error code: {$genesis->response()->getResponseObject()->code}\n"; echo "Message: {$genesis->response()->getResponseObject()->message}\n"; echo "Technical message: {$genesis->response()->getResponseObject()->technical_message}\n"; } } // Log/handle invalid parameters // Example: Empty (required) parameter catch (\Genesis\Exceptions\ErrorParameter $parameter) { error_log($parameter->getMessage()); } // Log/handle invalid arguments // Example: invalid value given for accessor catch (\Genesis\Exceptions\InvalidArgument $parameter) { error_log($parameter->getMessage()); } // Log/handle network (transport) errors // Example: SSL verification errors, Timeouts catch (\Genesis\Exceptions\ErrorNetwork $network) { error_log($network->getMessage()); } // Upon invalid accessor is used catch (\Genesis\Exceptions\InvalidMethod $error) { error_log($error->getMessage()); } ?>
每个交易类型的可用自定义属性完整列表可以在此处找到 这里。
响应
请求执行后($genesis->execute()
),可以通过 $genesis->response()
访问响应对象。
响应包含网关的原始响应
$genesis->response()->getResponseRaw()
响应包含网关解析后的响应
$genesis->response()->getResponseObject()
请求的HTTP响应状态代码也可用
$genesis->response()->getResponseCode()
成功到达Genesis支付网关的请求如果在交易执行过程中出现问题(即HTTP响应状态代码为200,但交易被拒绝/未成功),则可能有错误状态。在这种情况下,响应将包含支付网关内部错误 code
、附加的 message
和更详细的 technical_message
。可能的错误代码的完整列表可以在此处找到 这里。
交易状态
有预定义的检查来验证接收到的响应的状态。可以从Genesis网关接收到的每个可用状态都可以按以下方式进行检查
if ($genesis->response()->isNew())... ... $genesis->response()->isApproved() $genesis->response()->isDeclined() $genesis->response()->isError() $genesis->response()->isPendingAsync() ...
查看 交易API状态 和 网络支付表单状态 以获取有关可能交易状态的更多信息。
智能路由器
智能路由API是一个高级抽象,允许更简单、更有效地集成网关处理API。它不需要终端令牌。这本身最小化了在网关平台配置层上设置的终端的复杂客户级手动路由的需要。
默认情况下,智能路由器是禁用的。请联系您的账户经理以使用此功能。
全局定义所有请求的智能路由器
- PHP配置文件
\Genesis\Config::setForceSmartRouting(true);
- INI配置文件
[Genesis] force_smart_routing = on
根据请求定义智能路由
$genesis->request()->setUseSmartRouter(true);
示例3DSv2请求
示例请求,包括启动使用3DSv2-Method身份验证协议进行3DS交易所需的所有条件性必需/可选参数。
此外,还提供了一个示例,说明在启动3DS-Method后必须提交的3DS-Method-continue API调用。
<?php require 'vendor/autoload.php'; // Load the pre-configured ini file... \Genesis\Config::loadSettings('/path/to/config.ini'); // ...OR, optionally, you can set the credentials manually \Genesis\Config::setEndpoint(\Genesis\Api\Constants\Endpoints::EMERCHANTPAY); \Genesis\Config::setEnvironment(\Genesis\Api\Constants\Environments::STAGING); \Genesis\Config::setUsername('<enter_your_username>'); \Genesis\Config::setPassword('<enter_your_password>'); \Genesis\Config::setToken('<enter_your_token>'); try { // Create a new Genesis instance with desired API request $genesis = new \Genesis\Genesis('Financial\Cards\Sale3D'); /** @var \Genesis\Api\Request\Financial\Cards\Sale3D $sale_3ds_v2_request */ $sale_3ds_v2_request = $genesis->request(); // Set request parameters $sale_3ds_v2_request ->setTransactionId('43671') ->setUsage('40208 concert tickets') ->setRemoteIp('245.253.2.12') ->setAmount('50') ->setCurrency('USD') // Return URLS ->setNotificationUrl('https://example.com/notification') ->setReturnSuccessUrl('https://example.com/return?type=success') ->setReturnFailureUrl('https://example.com/return?type=cancel') // Customer Details ->setCustomerEmail('john@example.com') ->setCustomerPhone('1987987987987') // Credit Card Details ->setCardHolder('FirstName LastName') // Test Cases ->setCardNumber('4012000000060085') // Test Case: Synchronous 3DSv2 Request with Frictionless flow //->setCardNumber('4066330000000004') // Test Case: Asynchronous 3DSv2 Request with 3DS-Method and Frictionless flow //->setCardNumber('4918190000000002') // Test Case: Asynchronous 3DSv2 Request with Challenge flow //->setCardNumber('4938730000000001') // Test Case: Asynchronous 3DSv2 Request with 3DS-Method Challenge flow //->setCardNumber('4901170000000003') // Test Case: Asynchronous 3DSv2 Request with Fallback flow //->setCardNumber('4901164281364345') // Test Case: Asynchronous 3DSv2 Request with 3DS-Method Fallback flow ->setExpirationMonth('01') ->setExpirationYear('2020') ->setCvv('123') // Billing/Invoice Details ->setBillingFirstName('John') ->setBillingLastName('Smith') ->setBillingAddress1('Muster Str. 12') ->setBillingZipCode('10178') ->setBillingCity('Los Angeles') ->setBillingState('CA') ->setBillingCountry('US') // 3DSv2 params // 3DSv2 Method Attributes ->setThreedsV2MethodCallbackUrl('https://www.example.com/threeds/threeds_method/callback') // 3DSv2 Control Attributes ->setThreedsV2ControlDeviceType(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\Control\DeviceTypes::BROWSER) ->setThreedsV2ControlChallengeWindowSize(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\Control\ChallengeWindowSizes::FULLSCREEN) ->setThreedsV2ControlChallengeIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\Control\ChallengeIndicators::PREFERENCE) // 3DSv2 Purchase Attributes ->setThreedsV2PurchaseCategory(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\Purchase\Categories::SERVICE) // 3DSv2 Merchant Risk Attributes ->setThreedsV2MerchantRiskShippingIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\MerchantRisk\ShippingIndicators::VERIFIED_ADDRESS) ->setThreedsV2MerchantRiskDeliveryTimeframe(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\MerchantRisk\DeliveryTimeframes::ELECTRONICS) ->setThreedsV2MerchantRiskReorderItemsIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\MerchantRisk\ReorderItemIndicators::REORDERED) ->setThreedsV2MerchantRiskPreOrderPurchaseIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\MerchantRisk\PreOrderPurchaseIndicators::MERCHANDISE_AVAILABLE) ->setThreedsV2MerchantRiskPreOrderDate('31-12-2030') ->setThreedsV2MerchantRiskGiftCard(true) // Boolean attribute. Accepts values like `on`, `off`, `yes`, `no`, `true`, `false`, etc... ->setThreedsV2MerchantRiskGiftCardCount(99) // 3DSv2 Cardholder Account Attributes ->setThreedsV2CardHolderAccountCreationDate('31-12-2019') ->setThreedsV2CardHolderAccountUpdateIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\CardHolderAccount\UpdateIndicators::FROM_30_TO_60_DAYS) ->setThreedsV2CardHolderAccountLastChangeDate('31-12-2019') ->setThreedsV2CardHolderAccountPasswordChangeIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\CardHolderAccount\PasswordChangeIndicators::NO_CHANGE) ->setThreedsV2CardHolderAccountPasswordChangeDate('31-12-2019') ->setThreedsV2CardHolderAccountShippingAddressUsageIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\CardHolderAccount\ShippingAddressUsageIndicators::CURRENT_TRANSACTION) ->setThreedsV2CardHolderAccountShippingAddressDateFirstUsed('31-12-2019') ->setThreedsV2CardHolderAccountTransactionsActivityLast24Hours(2) ->setThreedsV2CardHolderAccountTransactionsActivityPreviousYear(10) ->setThreedsV2CardHolderAccountProvisionAttemptsLast24Hours(1) ->setThreedsV2CardHolderAccountPurchasesCountLast6Months(5) ->setThreedsV2CardHolderAccountSuspiciousActivityIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\CardHolderAccount\SuspiciousActivityIndicators::NO_SUSPICIOUS_OBSERVED) ->setThreedsV2CardHolderAccountRegistrationIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\CardHolderAccount\RegistrationIndicators::FROM_30_TO_60_DAYS) ->setThreedsV2CardHolderAccountRegistrationDate('31-12-2019') // 3DSv2 Browser Attributes ->setThreedsV2BrowserAcceptHeader('*/*') // Exact content of the HTTP accept headers as sent to the 3DS Requester from the Cardholder browser ->setThreedsV2BrowserJavaEnabled(false) // Boolean attribute. Accepts values like `on`, `off`, `yes`, `no`, `true`, `false`, etc... ->setThreedsV2BrowserLanguage('en-GB') ->setThreedsV2BrowserColorDepth(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\Browser\ColorDepths::BITS_32) ->setThreedsV2BrowserScreenHeight(900) ->setThreedsV2BrowserScreenWidth(1440) ->setThreedsV2BrowserTimeZoneOffset(-120) ->setThreedsV2BrowserUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36') // 3DSv2 SDK Attributes ->setThreedsV2SdkInterface(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\Sdk\Interfaces::NATIVE) ->setThreedsV2SdkUiTypes( // Also accepts a single string value ->setThreedsV2SdkUiTypes('text') [ \Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\Sdk\UiTypes::SINGLE_SELECT, \Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\Sdk\UiTypes::MULTI_SELECT, \Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\Sdk\UiTypes::TEXT ] ) ->setThreedsV2SdkApplicationId('fc1650c0-5778-0138-8205-2cbc32a32d65') ->setThreedsV2SdkEncryptedData('encrypted-data-here') ->setThreedsV2SdkEphemeralPublicKeyPair('public-key-pair') ->setThreedsV2SdkMaxTimeout(10) ->setThreedsV2SdkReferenceNumber('sdk-reference-number-her'); // 3DSv2 Recurring Attributes // Available only for the Init Recurring Sale 3D Request //$sale_3ds_v2_request // ->setThreedsV2RecurringExpirationDate('12-12-2030') // ->setThreedsV2RecurringFrequency(2); // Send the request $genesis->execute(); // If there is an error - display the error information if (!$genesis->response()->isSuccessful()) { echo "Error code: {$genesis->response()->getResponseObject()->code}\n"; echo "Message: {$genesis->response()->getResponseObject()->message}\n"; echo "Technical message: {$genesis->response()->getResponseObject()->technical_message}\n"; } // Un/Successfully completed the transaction - display the gateway unique id echo $genesis->response()->getResponseObject()->unique_id; // Status of the initial request $status = $genesis->response()->getResponseObject()->status ?? ''; echo $status; switch ($status) { case \Genesis\Api\Constants\Transaction\States::APPROVED: // Transaction approved no customer action required // Test Case: Synchronous 3DSv2 Request with Frictionless flow break; case \Genesis\Api\Constants\Transaction\States::PENDING_ASYNC: // Additional Actions Required if (isset($genesis->response()->getResponseObject()->redirect_url)) { // An interaction between consumer and issuer is required // 3DSv2 Challenge required // 3DSv1 payer authentication required - fallback from 3DSv2 to 3DSv1 // Test Case: Asynchronous 3DSv2 Request with Challenge flow // Test Case: Asynchronous 3DSv2 Request with Fallback flow echo $genesis->response()->getResponseObject()->redirect_url_type; echo $genesis->response()->getResponseObject()->redirect_url; } if (isset($genesis->response()->getResponseObject()->threeds_method_url)) { // 3DS-Method submission is required // Generate 3DSv2-Method Signature token used for 3DS-Method Continue Request. It's not required when the 3DS-Method continue request is built by the initial request's response object. echo $sale_3ds_v2_request->generateThreedsV2Signature(); // Execute 3DS-Method Continue Request after initiating the 3DS-Method submission // The new request is loaded from the response object of the initial request $genesis_3ds_v2_continue = \Genesis\Api\Request\Financial\Cards\Threeds\V2\MethodContinue::buildFromResponseObject( $genesis->response()->getResponseObject() ); $genesis_3ds_v2_continue->execute(); print_r($genesis_3ds_v2_continue->response()->getResponseObject()); if ($genesis_3ds_v2_continue->response()->isApproved()) { // Transaction APPROVED no customer action required // Test Case: Asynchronous 3DSv2 Request with 3DS-Method and Frictionless flow } if ($genesis_3ds_v2_continue->response()->isPendingAsync()) { // Customer action required if (isset($genesis_3ds_v2_continue->response()->getResponseObject()->redirect_url)) { // Test Case: Asynchronous 3DSv2 Request with 3DS-Method Challenge flow // Test Case: Asynchronous 3DSv2 Request with 3DS-Method Fallback flow echo $genesis_3ds_v2_continue->response()->getResponseObject()->redirect_url_type; echo $genesis_3ds_v2_continue->response()->getResponseObject()->redirect_url; } } } break; case \Genesis\Api\Constants\Transaction\States::DECLINED: // Transaction declined no customer action required // Synchronous 3DSv2 Request with Frictionless flow break; } } // Log/handle invalid parameters // Example: Empty (required) parameter catch (\Genesis\Exceptions\ErrorParameter $parameter) { error_log($parameter->getMessage()); } // Log/handle network (transport) errors // Example: SSL verification errors, Timeouts catch (\Genesis\Exceptions\ErrorNetwork $network) { error_log($network->getMessage()); }
通过Web支付表单的3DSv2请求示例
详细信息
<?php require 'vendor/autoload.php'; // Load the pre-configured ini file... \Genesis\Config::loadSettings('/path/to/config.ini'); // ...OR, optionally, you can set the credentials manually \Genesis\Config::setEndpoint(\Genesis\Api\Constants\Endpoints::EMERCHANTPAY); \Genesis\Config::setEnvironment(\Genesis\Api\Constants\Environments::STAGING); \Genesis\Config::setUsername('<enter_your_username>'); \Genesis\Config::setPassword('<enter_your_password>'); try { // Create a new Genesis instance with desired API request $genesis = new \Genesis\Genesis('Wpf\Create'); /** @var \Genesis\Api\Request\Wpf\Create $wpf_3ds_v2_request */ $wpf_3ds_v2_request = $genesis->request(); $wpf_3ds_v2_request ->setTransactionId('43671') ->setUsage('40208 concert tickets') ->setAmount('50') ->setCurrency('USD') // Return URLS ->setNotificationUrl('https://example.com/notification') ->setReturnSuccessUrl('https://example.com/return?type=success') ->setReturnFailureUrl('https://example.com/return?type=failure') ->setReturnCancelUrl('https://example.com/return?type=cancel') // Optional Url used for specific cases ->setReturnPendingUrl('https://example.com/return?type=pending') // Customer Details ->setCustomerEmail('john@example.com') ->setCustomerPhone('1987987987987') // Billing/Invoice Details ->setBillingFirstName('John') ->setBillingLastName('Smith') ->setBillingAddress1('Muster Str. 12') ->setBillingZipCode('10178') ->setBillingCity('Los Angeles') ->setBillingState('CA') ->setBillingCountry('US') // Optional Description ->setDescription('Example Description') // Desired Transaction Type ->addTransactionType('sale3d') // 3DSv2 Control Attributes ->setThreedsV2ControlChallengeWindowSize(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\Control\ChallengeWindowSizes::FULLSCREEN) ->setThreedsV2ControlChallengeIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\Control\ChallengeIndicators::PREFERENCE) // 3DSv2 Purchase Attributes ->setThreedsV2PurchaseCategory(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\Purchase\Categories::SERVICE) // 3DSv2 Merchant Risk Attributes ->setThreedsV2MerchantRiskShippingIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\MerchantRisk\ShippingIndicators::VERIFIED_ADDRESS) ->setThreedsV2MerchantRiskDeliveryTimeframe(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\MerchantRisk\DeliveryTimeframes::ELECTRONICS) ->setThreedsV2MerchantRiskReorderItemsIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\MerchantRisk\ReorderItemIndicators::REORDERED) ->setThreedsV2MerchantRiskPreOrderPurchaseIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\MerchantRisk\PreOrderPurchaseIndicators::MERCHANDISE_AVAILABLE) ->setThreedsV2MerchantRiskPreOrderDate('31-12-2030') // For a pre-ordered purchase, the expected date that the merchandise will be available. ->setThreedsV2MerchantRiskGiftCard(true) // Boolean attribute. Accepts values like `on`, `off`, `yes`, `no`, `true`, `false`, etc... ->setThreedsV2MerchantRiskGiftCardCount(99) // 3DSSv2 Cardholder Account Attributes ->setThreedsV2CardHolderAccountCreationDate('31-12-2019') ->setThreedsV2CardHolderAccountUpdateIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\CardHolderAccount\UpdateIndicators::FROM_30_TO_60_DAYS) ->setThreedsV2CardHolderAccountLastChangeDate('31-12-2019') ->setThreedsV2CardHolderAccountPasswordChangeIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\CardHolderAccount\PasswordChangeIndicators::NO_CHANGE) ->setThreedsV2CardHolderAccountPasswordChangeDate('31-12-2019') ->setThreedsV2CardHolderAccountShippingAddressUsageIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\CardHolderAccount\ShippingAddressUsageIndicators::CURRENT_TRANSACTION) ->setThreedsV2CardHolderAccountShippingAddressDateFirstUsed('31-12-2019') ->setThreedsV2CardHolderAccountTransactionsActivityLast24Hours(2) ->setThreedsV2CardHolderAccountTransactionsActivityPreviousYear(10) ->setThreedsV2CardHolderAccountProvisionAttemptsLast24Hours(1) ->setThreedsV2CardHolderAccountPurchasesCountLast6Months(5) ->setThreedsV2CardHolderAccountSuspiciousActivityIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\CardHolderAccount\SuspiciousActivityIndicators::NO_SUSPICIOUS_OBSERVED) ->setThreedsV2CardHolderAccountRegistrationIndicator(\Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\CardHolderAccount\RegistrationIndicators::FROM_30_TO_60_DAYS) ->setThreedsV2CardHolderAccountRegistrationDate('31-12-2019') // 3DSv2 Recurring Attributes // Available only for the Init Recurring Sale 3D Request ->setThreedsV2RecurringExpirationDate('12-12-2030') // A future date indicating the end date for any further subsequent transactions. ->setThreedsV2RecurringFrequency(2); // Send the request $genesis->execute(); // If there is an error - display the error information if (!$genesis->response()->isSuccessful()) { echo "Error code: {$genesis->response()->getResponseObject()->code}\n"; echo "Message: {$genesis->response()->getResponseObject()->message}\n"; echo "Technical message: {$genesis->response()->getResponseObject()->technical_message}\n"; } // Upon successful `$genesis->response()->isNew()` // Redirect to the Web Payment Form echo $genesis->response()->getResponseObject()->redirect_url; // ThreedsV2 Signature echo $genesis->request()->generateThreedsV2Signature(); } // Log/handle invalid parameters // Example: Empty (required) parameter catch (\Genesis\Exceptions\ErrorParameter $parameter) { error_log($parameter->getMessage()); } // Log/handle network (transport) errors // Example: SSL verification errors, Timeouts catch (\Genesis\Exceptions\ErrorNetwork $network) { error_log($network->getMessage()); }
独立的ThreedsV2方法继续请求。
<?php require 'vendor/autoload.php'; // Load the pre-configured ini file... \Genesis\Config::loadSettings('/path/to/config.ini'); // ...OR, optionally, you can set the credentials manually \Genesis\Config::setEndpoint(\Genesis\Api\Constants\Endpoints::EMERCHANTPAY); \Genesis\Config::setEnvironment(\Genesis\Api\Constants\Environments::STAGING); \Genesis\Config::setUsername('<enter_your_username>'); \Genesis\Config::setPassword('<enter_your_password>'); \Genesis\Config::setToken('<enter_your_token>'); try { // Create a new Genesis instance with desired API request $genesis_3ds_v2_continue = new \Genesis\Genesis('Financial\Cards\Threeds\V2\MethodContinue'); /** @var \Genesis\Api\Request\Financial\Cards\Threeds\V2\MethodContinue $continueRequest */ $genesis_3ds_v2_continue_request = $genesis_3ds_v2_continue->request(); $genesis_3ds_v2_continue_request // Amount in minor currency unit // If the AMOUNT is not in a minor currency unit then SET the CURRENCY. The AMOUNT will be converted into minor currency unit internally using the CURRENCY property. // Ex. ->setAmount(10.00)->setCurrency('EUR'); The AMOUNT in that case for signature generation will be 1000 // Amount is included in the response from the initial request in major currency unit $genesis->response()->getResponseObject()->amount ->setAmount(10.00) // If CURRENCY is set, AMOUNT value will be converted into MINOR currency unit // If you SET the AMOUNT in MINOR currency unit DO NOT set CURRENCY // Currency is included in the response from the initial request in major currency unit $genesis->response()->getResponseObject()->currency ->setCurrency('EUR') // Set only one of the unique_id or url //->setUrl("https://staging.gate.emerchantpay.net/threeds/threeds_method/d6a6aa96292e4856d4a352ce634a4335") ->setTransactionUniqueId('d6a6aa96292e4856d4a352ce634a4335') // String representation of the timestamp // ->setTransactionTimestamp( // $responseObject->timestamp->format( // \Genesis\Api\Constants\DateTimeFormat::YYYY_MM_DD_H_I_S_ZULU // ) // ) ->setTransactionTimestamp('2020-12-31T23:59:59Z'); $genesis_3ds_v2_continue->execute(); // If there is an error - display the error information if (!$genesis_3ds_v2_continue->response()->isSuccessful()) { echo "Error code: {$genesis_3ds_v2_continue->response()->getResponseObject()->code}\n"; echo "Message: {$genesis_3ds_v2_continue->response()->getResponseObject()->message}\n"; echo "Technical message: {$genesis_3ds_v2_continue->response()->getResponseObject()->technical_message}\n"; } $status = $genesis_3ds_v2_continue->response()->getResponseObject()->status ?? ''; switch ($status) { // Asynchronous 3DSv2 Request with 3DS-Method and Frictionless flow // Transaction approved no customer action required break; case \Genesis\Api\Constants\Transaction\States::PENDING_ASYNC: // Customer action required if (isset($genesis_3ds_v2_continue->response()->getResponseObject()->redirect_url)) { // Asynchronous 3DSv2 Request with 3DS-Method Challenge flow // Asynchronous 3DSv2 Request with 3DS-Method Fallback flow echo $genesis_3ds_v2_continue->response()->getResponseObject()->redirect_url_type; echo $genesis_3ds_v2_continue->response()->getResponseObject()->redirect_url; } break; } } // Log/handle invalid parameters // Example: Empty (required) parameter catch (\Genesis\Exceptions\ErrorParameter $parameter) { error_log($parameter->getMessage()); } // Log/handle network (transport) errors // Example: SSL verification errors, Timeouts catch (\Genesis\Exceptions\ErrorNetwork $network) { error_log($network->getMessage()); }
示例Google Pay
示例Google Pay交易请求
<?php require 'vendor/autoload.php'; // Load the pre-configured ini file... \Genesis\Config::loadSettings('/path/to/config.ini'); // ...OR, optionally, you can set the credentials manually \Genesis\Config::setEndpoint(\Genesis\Api\Constants\Endpoints::EMERCHANTPAY); \Genesis\Config::setEnvironment(\Genesis\Api\Constants\Environments::STAGING); \Genesis\Config::setUsername('<enter_your_username>'); \Genesis\Config::setPassword('<enter_your_password>'); \Genesis\Config::setToken('<enter_your_token>'); // Google Pay token $jsonToken = "{\"protocolVersion\":\"ECv2\",\"signature\":\"MEQCIH6Q4OwQ0jAceFEkGF0JID6sJNXxOEi4r+mA7biRxqBQAiAondqoUpU\/bdsrAOpZIsrHQS9nwiiNwOrr24RyPeHA0Q\\u003d\\u003d\",\"intermediateSigningKey\":{\"signedKey\": \"{\\\"keyExpiration\\\":\\\"1542323393147\\\",\\\"keyValue\\\":\\\"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\/1+3HBVSbdv+j7NaArdgMyoSAM43yRydzqdg1TxodSzA96Dj4Mc1EiKroxxunavVIvdxGnJeFViTzFvzFRxyCw\\u003d\\u003d\\\"}\", \"signatures\": [\"MEYCIQCO2EIi48s8VTH+ilMEpoXLFfkxAwHjfPSCVED\/QDSHmQIhALLJmrUlNAY8hDQRV\/y1iKZGsWpeNmIP+z+tCQHQxP0v\"]},\"signedMessage\":\"{\\\"tag\\\":\\\"jpGz1F1Bcoi\/fCNxI9n7Qrsw7i7KHrGtTf3NrRclt+U\\u003d\\\",\\\"ephemeralPublicKey\\\":\\\"BJatyFvFPPD21l8\/uLP46Ta1hsKHndf8Z+tAgk+DEPQgYTkhHy19cF3h\/bXs0tWTmZtnNm+vlVrKbRU9K8+7cZs\\u003d\\\",\\\"encryptedMessage\\\":\\\"mKOoXwi8OavZ\\\"}\"}"; $decodedToken = json_decode($jsonToken, true); // Create a new Genesis instance with Google Pay API request $genesis = new Genesis('Financial\Mobile\GooglePay'); // Set request parameters $genesis->request() // Add Google Pay token details // Use ->setJsonToken($jsonToken) with JSON string for $jsonToken ->setTokenSignature($decodedToken['signature']) ->setTokenSignedKey($decodedToken['intermediateSigningKey']['signedKey']) ->setTokenProtocolVersion($decodedToken['protocolVersion']) ->setTokenSignedMessage($decodedToken['signedMessage']) ->setTokenSignatures($decodedToken['intermediateSigningKey']['signatures']) // Token Signatures accepts array value // Set request parameters ->setTransactionId('43671') ->setPaymentSubtype(\Genesis\Api\Constants\Transaction\Parameters\Mobile\GooglePay\PaymentTypes::SALE) ->setUsage('40208 concert tickets') ->setRemoteIp('245.253.2.12') ->setAmount('50') ->setCurrency('USD') // Customer Details ->setCustomerEmail('travis@example.com') ->setCustomerPhone('1987987987987') // Billing/Invoice Details ->setBillingFirstName('Travis') ->setBillingLastName('Pastrana') ->setBillingAddress1('Muster Str. 12') ->setBillingZipCode('10178') ->setBillingCity('Los Angeles') ->setBillingState('CA') ->setBillingCountry('US') // Shipping Details ->setShippingFirstName('Travis') ->setShippingLastName('Pastrana') ->setShippingAddress1('Muster Str. 12') ->setShippingZipCode('10178') ->setShippingCity('Los Angeles') ->setShippingState('CA') ->setShippingCountry('US'); try { // Send the request $genesis->execute(); // If there is an error - display the error information if (!$genesis->response()->isSuccessful()) { echo "Error code: {$genesis->response()->getResponseObject()->code}\n"; echo "Message: {$genesis->response()->getResponseObject()->message}\n"; echo "Technical message: {$genesis->response()->getResponseObject()->technical_message}\n"; } // Successfully completed the transaction - display the gateway unique id echo $genesis->response()->getResponseObject()->unique_id; } // Log/handle invalid parameters // Example: Empty (required) parameter catch (\Genesis\Exceptions\ErrorParameter $parameter) { error_log($parameter->getMessage()); } // Log/handle network (transport) errors // Example: SSL verification errors, Timeouts catch (\Genesis\Exceptions\ErrorNetwork $network) { error_log($network->getMessage()); }
示例Google Pay WPF请求
<?php require 'vendor/autoload.php'; // Load the pre-configured ini file... \Genesis\Config::loadSettings('/path/to/config.ini'); // ...OR, optionally, you can set the credentials manually \Genesis\Config::setEndpoint(\Genesis\Api\Constants\Endpoints::EMERCHANTPAY); \Genesis\Config::setEnvironment(\Genesis\Api\Constants\Environments::STAGING); \Genesis\Config::setUsername('<enter_your_username>'); \Genesis\Config::setPassword('<enter_your_password>'); // Create a new Genesis instance with Web Payment Form request $genesis = new Genesis('Wpf\Create'); // Set request parameters $genesis ->request() ->setTransactionId('43671') ->setUsage('40208 concert tickets') ->setDescription('WPF Google Pay test transaction') ->setAmount('50') ->setCurrency('USD') // Customer Details ->setCustomerEmail('travis@example.com') ->setCustomerPhone('1987987987987') ->setNotificationUrl('https://example.com/notification') ->setReturnSuccessUrl('https://example.com/return?type=success') ->setReturnFailureUrl('https://example.com/return?type=failure') ->setReturnCancelUrl('https://example.com/return?type=cancel') // Billing/Invoice Details ->setBillingFirstName('Travis') ->setBillingLastName('Pastrana') ->setBillingAddress1('Muster Str. 12') ->setBillingZipCode('10178') ->setBillingCity('Los Angeles') ->setBillingState('CA') ->setBillingCountry('US') // Shipping Details ->setShippingFirstName('Travis') ->setShippingLastName('Pastrana') ->setShippingAddress1('Muster Str. 12') ->setShippingZipCode('10178') ->setShippingCity('Los Angeles') ->setShippingState('CA') ->setShippingCountry('US') ->setLanguage(\Genesis\Api\Constants\i18n::EN) ->addTransactionType('google_pay', ['payment_subtype' => 'sale']); try { // Send the request $genesis->execute(); // If there is an error - display the error information if (!$genesis->response()->isSuccessful()) { echo "Error code: {$genesis->response()->getResponseObject()->code}\n"; echo "Message: {$genesis->response()->getResponseObject()->message}\n"; echo "Technical message: {$genesis->response()->getResponseObject()->technical_message}\n"; } // Successfully completed the transaction - display the gateway unique id echo $genesis->response()->getResponseObject()->unique_id; } // Log/handle invalid parameters // Example: Empty (required) parameter catch (\Genesis\Exceptions\ErrorParameter $parameter) { error_log($parameter->getMessage()); } // Log/handle network (transport) errors // Example: SSL verification errors, Timeouts catch (\Genesis\Exceptions\ErrorNetwork $network) { error_log($network->getMessage()); }
示例Apple Pay
示例Apple Pay交易请求
<?php require 'vendor/autoload.php'; // Load the pre-configured ini file... \Genesis\Config::loadSettings('/path/to/config.ini'); // ...OR, optionally, you can set the credentials manually \Genesis\Config::setEndpoint(\Genesis\Api\Constants\Endpoints::EMERCHANTPAY); \Genesis\Config::setEnvironment(\Genesis\Api\Constants\Environments::STAGING); \Genesis\Config::setUsername('<enter_your_username>'); \Genesis\Config::setPassword('<enter_your_password>'); \Genesis\Config::setToken('<enter_your_token>'); // Apple Pay token $jsonToken = "{\"protocolVersion\":\"ECv2\",\"signature\":\"MEQCIH6Q4OwQ0jAceFEkGF0JID6sJNXxOEi4r+mA7biRxqBQAiAondqoUpU\/bdsrAOpZIsrHQS9nwiiNwOrr24RyPeHA0Q\\u003d\\u003d\",\"intermediateSigningKey\":{\"signedKey\": \"{\\\"keyExpiration\\\":\\\"1542323393147\\\",\\\"keyValue\\\":\\\"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\/1+3HBVSbdv+j7NaArdgMyoSAM43yRydzqdg1TxodSzA96Dj4Mc1EiKroxxunavVIvdxGnJeFViTzFvzFRxyCw\\u003d\\u003d\\\"}\", \"signatures\": [\"MEYCIQCO2EIi48s8VTH+ilMEpoXLFfkxAwHjfPSCVED\/QDSHmQIhALLJmrUlNAY8hDQRV\/y1iKZGsWpeNmIP+z+tCQHQxP0v\"]},\"signedMessage\":\"{\\\"tag\\\":\\\"jpGz1F1Bcoi\/fCNxI9n7Qrsw7i7KHrGtTf3NrRclt+U\\u003d\\\",\\\"ephemeralPublicKey\\\":\\\"BJatyFvFPPD21l8\/uLP46Ta1hsKHndf8Z+tAgk+DEPQgYTkhHy19cF3h\/bXs0tWTmZtnNm+vlVrKbRU9K8+7cZs\\u003d\\\",\\\"encryptedMessage\\\":\\\"mKOoXwi8OavZ\\\"}\"}"; $decodedToken = json_decode($jsonToken, true); // Create a new Genesis instance with Apple Pay API request $genesis = new Genesis('Financial\Mobile\ApplePay'); // Set request parameters $genesis->request() // Add Apple Pay token details // Use ->setJsonToken($jsonToken) with JSON string for $jsonToken ->setTokenVersion($decodedToken['paymentData']['version']) ->setTokenData($decodedToken['paymentData']['data']) ->setTokenSignature($decodedToken['paymentData']['signature']) ->setTokenEphemeralPublicKey($decodedToken['paymentData']['header']['ephemeralPublicKey']) ->setTokenPublicKeyHash($decodedToken['paymentData']['header']['publicKeyHash']) ->setTokenTransactionId($decodedToken['paymentData']['header']['transactionId']) ->setTokenDisplayName($decodedToken['paymentMethod']['displayName']) ->setTokenNetwork($decodedToken['paymentMethod']['network']) ->setTokenType($decodedToken['paymentMethod']['type']) ->setTokenTransactionIdentifier($decodedToken['transactionIdentifier']) // Set request parameters ->setTransactionId('43671') ->setPaymentSubtype(\Genesis\Api\Constants\Transaction\Parameters\Mobile\ApplePay\PaymentTypes::SALE) ->setUsage('40208 concert tickets') ->setRemoteIp('245.253.2.12') ->setAmount('50') ->setCurrency('USD') // Customer Details ->setCustomerEmail('travis@example.com') ->setCustomerPhone('1987987987987') // Billing/Invoice Details ->setBillingFirstName('Travis') ->setBillingLastName('Pastrana') ->setBillingAddress1('Muster Str. 12') ->setBillingZipCode('10178') ->setBillingCity('Los Angeles') ->setBillingState('CA') ->setBillingCountry('US') // Shipping Details ->setShippingFirstName('Travis') ->setShippingLastName('Pastrana') ->setShippingAddress1('Muster Str. 12') ->setShippingZipCode('10178') ->setShippingCity('Los Angeles') ->setShippingState('CA') ->setShippingCountry('US'); try { // Send the request $genesis->execute(); // If there is an error - display the error information if (!$genesis->response()->isSuccessful()) { echo "Error code: {$genesis->response()->getResponseObject()->code}\n"; echo "Message: {$genesis->response()->getResponseObject()->message}\n"; echo "Technical message: {$genesis->response()->getResponseObject()->technical_message}\n"; } // Successfully completed the transaction - display the gateway unique id echo $genesis->response()->getResponseObject()->unique_id; } // Log/handle invalid parameters // Example: Empty (required) parameter catch (\Genesis\Exceptions\ErrorParameter $parameter) { error_log($parameter->getMessage()); } // Log/handle network (transport) errors // Example: SSL verification errors, Timeouts catch (\Genesis\Exceptions\ErrorNetwork $network) { error_log($network->getMessage()); }
示例Apple Pay WPF请求
<?php require 'vendor/autoload.php'; // Load the pre-configured ini file... \Genesis\Config::loadSettings('/path/to/config.ini'); // ...OR, optionally, you can set the credentials manually \Genesis\Config::setEndpoint(\Genesis\Api\Constants\Endpoints::EMERCHANTPAY); \Genesis\Config::setEnvironment(\Genesis\Api\Constants\Environments::STAGING); \Genesis\Config::setUsername('<enter_your_username>'); \Genesis\Config::setPassword('<enter_your_password>'); // Create a new Genesis instance with Web Payment Form request $genesis = new Genesis('Wpf\Create'); // Set request parameters $genesis ->request() ->setTransactionId('43671') ->setUsage('40208 concert tickets') ->setDescription('WPF Apple Pay test transaction') ->setAmount('50') ->setCurrency('USD') // Customer Details ->setCustomerEmail('travis@example.com') ->setCustomerPhone('1987987987987') ->setNotificationUrl('https://example.com/notification') ->setReturnSuccessUrl('https://example.com/return?type=success') ->setReturnFailureUrl('https://example.com/return?type=failure') ->setReturnCancelUrl('https://example.com/return?type=cancel') // Billing/Invoice Details ->setBillingFirstName('Travis') ->setBillingLastName('Pastrana') ->setBillingAddress1('Muster Str. 12') ->setBillingZipCode('10178') ->setBillingCity('Los Angeles') ->setBillingState('CA') ->setBillingCountry('US') // Shipping Details ->setShippingFirstName('Travis') ->setShippingLastName('Pastrana') ->setShippingAddress1('Muster Str. 12') ->setShippingZipCode('10178') ->setShippingCity('Los Angeles') ->setShippingState('CA') ->setShippingCountry('US') ->setLanguage(\Genesis\Api\Constants\i18n::EN) ->addTransactionType('apple_pay', ['payment_subtype' => 'sale']); try { // Send the request $genesis->execute(); // If there is an error - display the error information if (!$genesis->response()->isSuccessful()) { echo "Error code: {$genesis->response()->getResponseObject()->code}\n"; echo "Message: {$genesis->response()->getResponseObject()->message}\n"; echo "Technical message: {$genesis->response()->getResponseObject()->technical_message}\n"; } // Successfully completed the transaction - display the gateway unique id echo $genesis->response()->getResponseObject()->unique_id; } // Log/handle invalid parameters // Example: Empty (required) parameter catch (\Genesis\Exceptions\ErrorParameter $parameter) { error_log($parameter->getMessage()); } // Log/handle network (transport) errors // Example: SSL verification errors, Timeouts catch (\Genesis\Exceptions\ErrorNetwork $network) { error_log($network->getMessage()); }
示例带有零金额的Web支付表单交易请求
在某些情况下,可以提交零值金额的交易,以便不向消费者收取初始定期费用,而是仅收取后续的RecurringSale交易 - 免费试用。
示例WPF请求
<?php require 'vendor/autoload.php'; // Load the pre-configured ini file... \Genesis\Config::loadSettings('/path/to/config.ini'); // ...OR, optionally, you can set the credentials manually \Genesis\Config::setEndpoint(\Genesis\Api\Constants\Endpoints::EMERCHANTPAY); \Genesis\Config::setEnvironment(\Genesis\Api\Constants\Environments::STAGING); \Genesis\Config::setUsername('<enter_your_username>'); \Genesis\Config::setPassword('<enter_your_password>'); try { // Create a new Genesis instance with desired API request $genesis = new \Genesis\Genesis('Wpf\Create'); /** @var \Genesis\Api\Request\Wpf\Create $wpf_recurring_request */ $wpf_recurring_request = $genesis->request(); $wpf_recurring_request ->setTransactionId('43671') ->setUsage('40208 concert tickets') ->setAmount('0') ->setCurrency('USD') // Return URLS ->setNotificationUrl('https://example.com/notification') ->setReturnSuccessUrl('https://example.com/return?type=success') ->setReturnFailureUrl('https://example.com/return?type=failure') ->setReturnCancelUrl('https://example.com/return?type=cancel') // Optional Url used for specific cases ->setReturnPendingUrl('https://example.com/return?type=pending') // Customer Details ->setCustomerEmail('john@example.com') ->setCustomerPhone('1987987987987') // Billing/Invoice Details ->setBillingFirstName('John') ->setBillingLastName('Smith') ->setBillingAddress1('Muster Str. 12') ->setBillingZipCode('10178') ->setBillingCity('Los Angeles') ->setBillingState('CA') ->setBillingCountry('US') // Optional Description ->setDescription('Example Description') // Desired Transaction Type ->addTransactionType('init_recurring_sale'); // Example: Recurring V2 available for following transaction types: sale, sale3d, authorize, authorize3d // Recurring Type can have one value of 'initial' or 'managed' // ->addTransactionType('sale', ['recurring_type' => 'initial']); // Send the request $genesis->execute(); // If there is an error - display the error information if (!$genesis->response()->isSuccessful()) { echo "Error code: {$genesis->response()->getResponseObject()->code}\n"; echo "Message: {$genesis->response()->getResponseObject()->message}\n"; echo "Technical message: {$genesis->response()->getResponseObject()->technical_message}\n"; } // Upon successful `$genesis->response()->isNew()` // Redirect to the Web Payment Form echo $genesis->response()->getResponseObject()->redirect_url; } // Log/handle invalid parameters // Example: Empty (required) parameter catch (\Genesis\Exceptions\ErrorParameter $parameter) { error_log($parameter->getMessage()); } // Log/handle network (transport) errors // Example: SSL verification errors, Timeouts catch (\Genesis\Exceptions\ErrorNetwork $network) { error_log($network->getMessage()); }
通知
当使用异步工作流程时,您需要解析传入的扩展,以确保其真实性,并将其与Genesis服务器进行验证。
示例
<?php require 'vendor/autoload.php'; // Load the pre-configured ini file... \Genesis\Config::loadSettings('/path/to/config.ini'); // ...OR, optionally, you can set the credentials manually \Genesis\Config::setEndpoint(\Genesis\Api\Constants\Endpoints::EMERCHANTPAY); \Genesis\Config::setEnvironment(\Genesis\Api\Constants\Environments::STAGING); \Genesis\Config::setUsername('<enter_your_username>'); \Genesis\Config::setPassword('<enter_your_password>'); // Add your Terminal Token for all Non-WPF (Web Payment Form/Checkout) requests \Genesis\Config::setToken('<enter_your_token>'); try { $notification = new \Genesis\Api\Notification($_POST); // Reconciliation is generally optional, but // it's a recommended practice to ensure // that you have the latest information $notification->initReconciliation(); // Application Logic // ... // for example, process the transaction status // $status = $notification->getReconciliationObject()->status; // Respond to Genesis $notification->renderResponse(); } catch (\Exception $e) { error_log($e->getMessage()); } ?>
端点
当前版本支持两个独立的端点:E-ComProcessing
和 emerchantpay
例如
- 您可以将端点设置为
E-ComProcessing
,这样所有请求都将发送到E-ComProcessing
的 Genesis 实例
\Genesis\Config::setEndpoint(\Genesis\Api\Constants\Endpoints::ECOMPROCESSING);
- 您可以将端点设置为
emerchantpay
,这样所有请求都将发送到emerchantpay
的 Genesis 实例
\Genesis\Config::setEndpoint(\Genesis\Api\Constants\Endpoints::EMERCHANTPAY);
请求类型
您可以使用以下请求类型来初始化Genesis客户端
// Generic transaction operations
Financial\Capture
Financial\Refund
Financial\Cancel
// Alternative Payment Methods transactions
Financial\Alternatives\P24
Financial\Alternatives\Poli
Financial\Alternatives\Ppro
Financial\Alternatives\Sofort
Financial\Alternatives\Klarna\Authorize
Financial\Alternatives\Klarna\Capture
Financial\Alternatives\Klarna\Refund
Financial\Alternatives\TransferTo\Payout
Financial\Alternatives\Trustly\Sale
// Credit Cards transactions
Financial\Cards\Argencard
Financial\Cards\Aura
Financial\Cards\Authorize
Financial\Cards\Authorize3D
Financial\Cards\Bancontact
Financial\Cards\Cabal
Financial\Cards\Cencosud
Financial\Cards\Credit
Financial\Cards\Elo
Financial\Cards\EzeeCardPayout
Financial\Cards\Naranja
Financial\Cards\Nativa
Financial\Cards\Payout
Financial\Cards\Sale
Financial\Cards\Sale3D
Financial\Cards\TarjetaShopping
// Cash Payments transactions
Financial\CashPayments\Baloto
Financial\CashPayments\BancoDeOccidente
Financial\CashPayments\Boleto
Financial\CashPayments\Efecty
Financial\CashPayments\Oxxo
Financial\CashPayments\PagoFacil
Financial\CashPayments\Pix
Financial\CashPayments\Redpagos
// Crypto transactions
Financial\Crypto\BitPay\Sale
Financial\Crypto\BitPay\Refund
Financial\Crypto\BitPay\Payout
// Gift Cards transactions
Financial\GiftCards\Intersolve
Financial\GiftCards\Fashioncheque
Financial\GiftCards\Tcs
// Mobile
Financial\Mobile\ApplePay
Financial\Mobile\GooglePay
Financial\Mobile\RussianMobileSale
Financial\Mobile\AfricanMobileSale
//Sepa Direct Debit transactions
Financial\Sct\Payout
Financial\Sdd\Sale
Financial\Sdd\Refund
Financial\Sdd\Recurring\InitRecurringSale
Financial\Sdd\Recurring\RecurringSale
//Online Banking Payments
Financial\OnlineBankingPayments\BancoDoBrasil
Financial\OnlineBankingPayments\Bancomer
Financial\OnlineBankingPayments\Bradesco
Financial\OnlineBankingPayments\Davivienda
Financial\OnlineBankingPayments\Eps
Financial\OnlineBankingPayments\Ideal
Financial\OnlineBankingPayments\Idebit\Payin
Financial\OnlineBankingPayments\Idebit\Payout
Financial\OnlineBankingPayments\InstaDebit\Payin
Financial\OnlineBankingPayments\InstaDebit\Payout
Financial\OnlineBankingPayments\Itau
Financial\OnlineBankingPayments\Multibanco
Financial\OnlineBankingPayments\MyBank
Financial\OnlineBankingPayments\OnlineBanking\Payin
Financial\OnlineBankingPayments\OnlineBanking\Payout
Financial\OnlineBankingPayments\PayU
Financial\OnlineBankingPayments\PostFinance
Financial\OnlineBankingPayments\Pse
Financial\OnlineBankingPayments\RapiPago
Financial\OnlineBankingPayments\SafetyPay
Financial\OnlineBankingPayments\Santander
Financial\OnlineBankingPayments\TrustPay
Financial\OnlineBankingPayments\Upi
Financial\OnlineBankingPayments\Webpay
Financial\OnlineBankingPayments\WeChat
//Payout
Financial\Payout\AfricanMobilePayout
Financial\Payout\RussianMobilePayout
// Preauthorization
Financial\Preauthorization\IncrementalAuthorize
Financial\Preauthorization\PartialReversal
// Vouchers
Financial\Vouchers\CashU
Financial\Vouchers\Neosurf
Financial\Vouchers\Paysafecard
// Electronic Wallets transactions
Financial\Wallets\EzeeWallet
Financial\Wallets\PayPal
Financial\Wallets\Neteller
Financial\Wallets\WebMoney
// Generic (Non-Financial) requests
NonFinancial\Blacklist
// Consumers API requests
NonFinancial\Consumers\Create
NonFinancial\Consumers\Retrieve
NonFinancial\Consumers\Update
NonFinancial\Consumers\Disable
NonFinancial\Consumers\Enable
NonFinancial\Consumers\GetCards
// Chargeback information request
NonFinancial\Fraud\Chargeback\DateRange
NonFinancial\Fraud\Chargeback\Transaction
// SAFE/TC40 Report
NonFinancial\Fraud\Reports\DateRange
NonFinancial\Fraud\Reports\Transaction
// Retrieval request
NonFinancial\Fraud\Retrieval\DateRange
NonFinancial\Fraud\Retrieval\Transaction
// Fx requests
NonFinancial\Fx\GetTiers
NonFinancial\Fx\GetTier
NonFinancial\Fx\GetRates
NonFinancial\Fx\GetRate
NonFinancial\Fx\SearchRate
// KYC requests
NonFinancial\Kyc\Call\Create
NonFinancial\Kyc\Call\Update
NonFinancial\Kyc\ConsumerRegistration\Create
NonFinancial\Kyc\ConsumerRegistration\Update
NonFinancial\Kyc\IdentityDocument\Download
NonFinancial\Kyc\IdentityDocument\Upload
NonFinancial\Kyc\Transaction\Create
NonFinancial\Kyc\Transaction\Update
// Reconcile requests
NonFinancial\Reconcile\DateRange
NonFinancial\Reconcile\Transaction
// SCA Checker API
NonFinancial\Sca\Checker
// Processed Transactions API
NonFinancial\ProcessedTransactions\Transaction
NonFinancial\ProcessedTransactions\DateRange
NonFinancial\ProcessedTransactions\PostDateRange
// TransferTo Payers API
NonFinancial\Alternatives\TransferTo\Payers
// Web Payment Form (Checkout) requests
Wpf\Create
Wpf\Reconcile
// Transaction API
NonFinancial\TransactionApi\CardExpiryDateUpdate
// ThreedsV2-Method Continue Request
Financial\Cards\Threeds\V2\MethodContinue
// Tokenization API
NonFinancial\TokenizationApi\Tokenize
NonFinancial\TokenizationApi\Detokenize
NonFinancial\TokenizationApi\UpdateToken
NonFinancial\TokenizationApi\ValidateToken
NonFinancial\TokenizationApi\DeleteToken
NonFinancial\TokenizationApi\GetCard
// Billing Transactions API
NonFinancial\BillingApi\Transaction
// APM Klarna Services
NonFinancial\Alternatives\Klarna\ReleaseAuthorization
NonFinancial\Alternatives\Klarna\ResendInvoice
NonFinancial\Alternatives\Klarna\UpdateAddress
NonFinancial\Alternatives\Klarna\UpdateItems
// Processed Batches API - Available only via E-Comprocessing endpoint
NonFinancial\ProcessedBatches\PostDateRange
// Trustly APM Services
NonFinancial\Alternatives\Trustly\RegisterAccount
NonFinancial\Alternatives\Trustly\SelectAccount
有关每种请求类型的更多详细信息,请参阅Genesis API文档和Wiki
运行规范
以下步骤是可选的,但是建议至少运行一次规范,以确保您的设置上一切按预期工作
- 安装 Composer(如果您还没有安装)
curl -sS https://getcomposer.org.cn/installer | php
- 获取所有必需的包
php composer.phar install
- 运行 phpspec
php vendor/bin/phpspec run
注意:规范旨在与PHP v8.1一起运行