placetopay / kount
用于连接 Kount 安全服务的 SDK
2.0.3
2023-05-08 22:11 UTC
Requires
- php: ^7.4|^8.0
- ext-json: *
- guzzlehttp/guzzle: ^7.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.6
- phpunit/phpunit: ^9.5
- symfony/var-dumper: ^5.4
README
安装
此 SDK 可以通过 composer 轻松安装
composer require placetopay/kount
使用方法
$service = new \PlacetoPay\Kount\KountService([ 'merchant' => 'YOUR_MERCHANT', 'apiKey' => 'THE_API_KEY_PROVIDED', 'website' => 'THE_AWC_SITE_NAME', ]);
数据收集器
在将收集信用卡信息的页面中,您需要放置数据收集器的 iframe,确保用您的网页 URL、您的商户和 THE_SESSION 替换支付
注意:它必须是 HTTPS,并且不必在 URL 的根目录上,您可以使用 https://YOUR_WEBPAGE_URL/kount/something/logo.htm,我不太确定是否需要调用 logo.htm 和 logo.gif,但我仍然使用这些名称
<iframe width=1 height=1 frameborder=0 scrolling=no src="https://YOUR_WEBPAGE_URL/logo.htm?m=YOUR_MERCHANT&s=THE_SESSION"> <img width=1 height=1 src="https://YOUR_WEBPAGE_URL/logo.gif?m=YOUR_MERCHANT&s=THE_SESSION"> </iframe>
然后确保您的应用程序响应 HTTP 状态码 302 以重定向到 Kount 的 URL
Route::get('/kount/{slug?}', function($slug = null) { $s = Request::get('s'); return redirect($service->dataCollectorUrl($s, $slug)); });
此示例是用 Laravel 制作的,但原理相同,slug 是 logo.htm 或 logo.gif 部分,会话是通过 GET 变量捕获的,商户不需要,因为已在服务的初始化中设置
一旦完成,数据收集器将正常运行。
RIS 询问
一旦捕获了卡信息、付款人数据、商品等信息,并且您已经将这些信息存储在您的服务器上,只需创建一个包含要发送给 Kount 的信息的数组即可
$data = [ 'payment' => [ 'reference' => '1234', 'amount' => [ 'currency' => 'COP', 'total' => '12300', ], 'items' => [ [ 'sku' => '111', 'name' => 'TV Sony 32', 'category' => 'physical', 'qty' => '1', 'price' => '2340', 'tax' => '300', ], [ 'sku' => '234', 'name' => 'Wireless Mouse', 'category' => 'physical', 'qty' => '2', 'price' => '543', 'tax' => '56', ] ], 'shipping' => [ 'name' => 'Diego', 'surname' => 'Calle', 'email' => 'fake@email.com', 'address' => [ 'street' => 'Fake street 321', 'city' => 'Sabaneta', 'state' => 'Antioquia', 'postalCode' => '050013', 'country' => 'CO', 'phone' => '4442310', ], ], ], // Merchant Acknowledgement 'mack' => 'Y', // Card Related 'cardNumber' => '4111111111111111', // M match, N Not match, X unavailable 'cvvStatus' => 'X', // MM/YY format 'cardExpiration' => '12/20', // Person related 'payer' => [ 'name' => 'Diego', 'surname' => 'Calle', 'email' => 'dnetix@gmail.com', 'document' => '1040035000', 'documentType' => 'CC', 'address' => [ 'street' => 'Fake street 123', 'city' => 'Medellin', 'state' => 'Antioquia', 'postalCode' => '050012', 'country' => 'CO', 'phone' => '4442310', ], ], 'gender' => 'M', // Additional 'additional' => [ 'key_1' => 'Some Value 1', ], 'ipAddress' => '127.0.0.1', 'userAgent' => 'Chrome XYZ', // To organize 'shipmentType' => \PlacetoPay\Kount\Messages\Request::SHIP_SAME, ];
请尽量提供尽可能多的信息,但不需要提供运输、性别、运输类型、超过 1 件商品(至少要有一件),付款人信息的地址
try { $response = $service->inquiry(THE_SESSION, $data); // For trace purposes if you want $kountCode = $response->transaction->id(); // For trace purposes if you want $score = $response->score(); if ($response->decision->shouldApprove()) { // Approve the transaction } if ($response->decision->shouldDecline()) { // Guess what } if ($response->decision->shouldReview()) { // The decision it's to review } } catch (KountServiceException $e) { // Handle the error message }
可用的响应信息
响应对象提供了一个方便的结构和方法,允许您获取 Kount 返回的所有信息。
$response->score(); // 33 $response->omniscore(); // 67 $response->toArray(); /** [ 'score' => 33, 'omniscore' => 67, 'system' => [ 'version' => '0720', 'mode' => 'Q', 'merchantId' => '201000', 'sessonId' => '3', 'orderReference' => '1234', ], 'decision' => [ 'code' => 'D', 'description' => 'DECLINE', 'shouldApprove' => false, 'shouldDecline' => true, 'shouldReview' => false, ], 'verification' => [ 'geolocationCountry' => 'US', 'geolocationRegion' => '', 'cardBrand' => 'VISA', 'cardIsBlacklisted' => false, 'aCatchVerificationHasBeenPerformed' => true, 'threeDsMerchantResponse' => '', 'denialReasonCode' => '', ], 'ip' => [ 'address' => '181.128.85.221', 'latitude' => '6.2518', 'longitude' => '-75.5636', 'country' => 'CO', 'state' => 'Antioquia', 'city' => 'Medellín', 'provider' => 'UNE', ], 'transaction' => [ 'id' => 'P01J0KZN329Z', 'usedCardsCount' => 1, 'usedDevicesCount' => 1, 'deviceLayers' => '81BBF7770C..D92909FF92.1867A9B2CB.D6112C09F7', 'usedEmailsCount' => 1, 'velocity' => 0, 'maxAllowedVelocity' => 0, 'site' => 'DEFAULT', 'fingerprint' => '4C2410BA22A64E21BF0C73EA88E48D7E', 'timezone' => '300', 'localtime' => '2017-05-31 00:19', 'region' => 'CO_02', 'country' => 'CO', 'httpCountry' => 'US', 'hasProxy' => false, 'hasJavascript' => true, 'hasFlash' => false, 'hasCookies' => true, 'language' => 'en', 'processedFromMobileDevice' => false, 'mobileType' => '', 'mobileIsThroughMobileForwarder' => false, 'processedFromVoiceDevice' => false, 'processedFromRemotePC' => false, ], 'additional' => [ 'dateSinceFirstMadeTransaction' => '2017-05-30', 'screenResolution' => '768x1366', 'userAgent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36', 'operativeSystem' => 'Linux', 'browser' => 'Chrome 58.0.3029.110', 'wasPreviouslyWhitelisted' => false, ], 'triggeredRules' => [ '729832' => 'Billing Country is not BIN Country', '729852' => 'Decline Network Chargebacks >1', '729854' => 'Review Non-Normal Network Type', '729858' => 'Device Location Lower Risk Review Countries', '729872' => 'Card on Network Chargeback List >0', ], 'triggeredCounters' => [ 'CONTRACARGOSREPORTADOS' => '1', 'HISTORICONEGATIVO' => '1', ], 'warnings' => [ 'THIS IS THE FIRST WARNING', 'THIS IS THE SECOND WARNING', ], 'errorsBag' => [ 'isErrorResponse' => false, 'code' => null, 'key' => null, 'errors' => [], ], ] */
标识符和引用
$response->system->version(); // '0720' $response->system->mode(); // 'Q' $response->system->merchantId(); // '201000' $response->system->sessionId(); // '3' $response->system->orderReference(); // '1234' $response->system->toArray(); /** [ 'version' => '0720', 'mode' => 'Q', 'merchantId' => '201000', 'sessonId' => '3', 'orderReference' => '1234', ] */
决策信息
$response->decision->code(); // 'D' $response->decision->description(); // 'DECLINE' $response->decision->shouldApprove(); // false $response->decision->shouldDecline(); // true $response->decision->shouldReview(); // false $response->decision->toArray(); /** [ 'code' => 'D', 'description' => 'DECLINE', 'shouldApprove' => false, 'shouldDecline' => true, 'shouldReview' => false, ] */
验证结果
$response->verification->geolocationCountry(); // 'US' $response->verification->geolocationRegion(); // 'EAST' $response->verification->cardBrand(); // 'VISA' $response->verification->cardIsBlacklisted(); // false $response->verification->aCatchVerificationHasBeenPerformed(); // true $response->verification->threeDsMerchantResponse(); // '' $response->verification->denialReasonCode(); // '' $response->verification->toArray(); /** [ 'geolocationCountry' => 'US', 'geolocationRegion' => 'EAST', 'cardBrand' => 'VISA', 'cardIsBlacklisted' => false, 'aCatchVerificationHasBeenPerformed' => true, 'threeDsMerchantResponse' => '', 'denialReasonCode' => '', ] */
交易信息
$response->transaction->id(); // 'P01J0KZN329Z' $response->transaction->usedCardsCount(); // 1 $response->transaction->usedDevicesCount(); // 1 $response->transaction->deviceLayers(); // '81BBF7770C..D92909FF92.1867A9B2CB.D6112C09F7' $response->transaction->usedEmailsCount(); // 1 $response->transaction->velocity(); // 0 $response->transaction->maxAllowedVelocity(); // 0 $response->transaction->site(); // 'DEFUALT $response->transaction->fingerprint(); // '4C2410BA22A64E21BF0C73EA88E48D7E' $response->transaction->timezone(); // '300 $response->transaction->localtime(); // '2017-05-31 00:19' $response->transaction->region(); // 'CO_02' $response->transaction->country(); // 'CO' $response->transaction->httpCountry(); // 'US' $response->transaction->hasProxy(); // false $response->transaction->hasJavascript(); // true $response->transaction->hasFlash(); // false $response->transaction->hasCookies(); // true $response->transaction->language(); // 'en' $response->transaction->processedFromMobileDevice(); // false $response->transaction->mobileType(); // '' $response->transaction->mobileIsThroughMobileForwarder(); // false $response->transaction->processedFromVoiceDevice(); // false $response->transaction->processedFromRemotePC(); // true $response->transaction->toArray(); /** [ 'id' => 'P01J0KZN329Z', 'usedCardsCount' => 1, 'usedDevicesCount' => 1, 'deviceLayers' => '81BBF7770C..D92909FF92.1867A9B2CB.D6112C09F7', 'usedEmailsCount' => 1, 'velocity' => 0, 'maxAllowedVelocity' => 0, 'site' => 'DEFAULT', 'fingerprint' => '4C2410BA22A64E21BF0C73EA88E48D7E', 'timezone' => '300', 'localtime' => '2017-05-31 00:19', 'region' => 'CO_02', 'country' => 'CO', 'httpCountry' => 'US', 'hasProxy' => false, 'hasJavascript' => true, 'hasFlash' => false, 'hasCookies' => true, 'language' => 'en', 'processedFromMobileDevice' => false, 'mobileType' => '', 'mobileIsThroughMobileForwarder' => false, 'processedFromVoiceDevice' => false, 'processedFromRemotePC' => true, ] */
交易 IP 信息
$response->ip->address(); // '181.128.85.221' $response->ip->latitude(); // '6.2518' $response->ip->longitude(); // '-75.5636' $response->ip->country(); // 'CO' $response->ip->state(); // 'Antioquia' $response->ip->city(); // 'Medellín' $response->ip->provider(); // 'UNE' $response->ip->toArray(); /** [ 'address' => '181.128.85.221', 'latitude' => '6.2518', 'longitude' => '-75.5636', 'country' => 'CO', 'state' => 'Antioquia', 'city' => 'Medellín', 'provider' => 'UNE', ] */
触发规则
$response->triggeredRules->count(); // 5 $response->triggeredRules->rules(); /** [ '729832' => 'Billing Country is not BIN Country', '729852' => 'Decline Network Chargebacks >1', '729854' => 'Review Non-Normal Network Type', '729858' => 'Device Location Lower Risk Review Countries', '729872' => 'Card on Network Chargeback List >0', ] */ $response->triggeredRules->toArray(); /** [ '729832' => 'Billing Country is not BIN Country', '729852' => 'Decline Network Chargebacks >1', '729854' => 'Review Non-Normal Network Type', '729858' => 'Device Location Lower Risk Review Countries', '729872' => 'Card on Network Chargeback List >0', ] */
触发计数器
$response->triggeredCounters->count(); // 2 $response->triggeredCounters->counters(); /** [ 'CONTRACARGOSREPORTADOS' => '1', 'HISTORICONEGATIVO' => '1', ] */ $response->triggeredCounters->toArray(); /** [ 'CONTRACARGOSREPORTADOS' => '1', 'HISTORICONEGATIVO' => '1', ] */
警告
$response->warnings->count(); // 2 $response->warnings->warnings(); /** [ 'THIS IS THE FIRST WARNING', 'THIS IS THE SECOND WARNING', ] */ $response->warnings->toArray(); /** [ 'THIS IS THE FIRST WARNING', 'THIS IS THE SECOND WARNING', ] */
错误
// Example of a failed response $response->errors->isErrorResponse(); // true $response->errors->count(); // 2 $response->errors->code(); // '323' $response->errors->key(); // 'The website identifier that was created in the Agent Web Console (’DEFAULT’ is the default website ID) does not match what was created in the AWC.' $response->errors->errors(); /** [ '323 BAD_SITE Cause: [[TEST] does not exist for merchant [201000]], Field: [SITE], Value: [TEST]', '362 BAD_CART Cause: [Shopping cart type index[0] is missing], Field: [PROD_TYPE], Value: [1=>111, 2=>234]', ] */ $response->errors->toArray(); /** [ 'isErrorResponse' => true, 'code' => '323', 'key' => 'The website identifier that was created in the Agent Web Console (’DEFAULT’ is the default website ID) does not match what was created in the AWC.', 'errors' => [ '323 BAD_SITE Cause: [[TEST] does not exist for merchant [201000]], Field: [SITE], Value: [TEST]', '362 BAD_CART Cause: [Shopping cart type index[0] is missing], Field: [PROD_TYPE], Value: [1=>111, 2=>234]', ], ] */
附加信息
$response->additional->dateSinceFirstMadeTransaction(); // '2017-05-30' $response->additional->screenResolution(); // '768x1366' $response->additional->userAgent(); // 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36' $response->additional->operativeSystem(); // 'Linux' $response->additional->browser(); // 'Chrome 58.0.3029.110' $response->additional->wasPreviouslyWhitelisted(); // false $response->additional->toArray(); /** [ 'dateSinceFirstMadeTransaction' => '2017-05-30', 'screenResolution' => '768x1366', 'userAgent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36', 'operativeSystem' => 'Linux', 'browser' => 'Chrome 58.0.3029.110', 'wasPreviouslyWhitelisted' => false, ] */
模拟响应
如果您更改模拟客户端的设置,则响应将是模拟的,并且不会使用真实的服务
return new KountService([ 'client' => MockClient::client(), ... ]);
在此模拟实例加载后,可用的模拟选项是这些。这些是通过 payment.reference
传递的,意味着交易上的引用
- AUTH_ERR - 模拟无效或过期的 ApiKey
- REVIEW - 模拟审核响应
- DECLINE - 模拟拒绝响应
- EXCEPTION - 模拟内部异常
任何其他引用都将返回已批准的响应