Vincent Webb

Not Your Average Blogger

How to use the Kount Anti-Fraud SDK with PHP

Kount is an API that merchants use to verify their credit card data before they run transactions. This is to help weed out potentially fraudalent transaction sbefore they hit the merchant account and cause potential chargebacks.

Using the intelligence that Kount has amassed they are able to supply a SCORE that determines if a transaction is potentially fraudulent.

I recently helped out on a project that was using Kount and their documentation was not so great. So I decided to post this article so hopefully other PHP developers after me who are faced with the problem of having to integrate Kount in PHP will have a much easier time.

For some strange reason, there is actually no PHP example code included with the Kount PHP SDK to perform Kount's most basic and important function.

Googling for various clues turns up nothing, so with some luck this article will make it's way there.

First you need the Kount PHP SDK which can be downloaded from here: https://support.kount.com/DeveloperResources/SoftwareDevelopmentKits(SDKs)

Unzip it on your webserver and make sure you setup the settings.ini file with all of the proper info as specified in the install documents.

There are 2 parts to the Kount platform. The first part is the Device fingerprinting. Their documentation on how to set this up is good. You basically setup a passthrough .html and .gif on your webserver and this allows you to retrieve a session ID. You will need to pass this session ID to the step below.

After you've done the device fingerprint, you need to do a Kount RIS Inquiry.

Here is the code you need to test a credit card number against the Kount database and return a SCORE. Anything over 70 is GOOD, under 70 and you should not pass the transaction.

include ‘autoload.php';  
include 'Kount/Ris/Request/Inquiry.php';  
try {

$_GET['name'] = "Tester";
$_GET['email'] = "tester@dispostable.com";
$_GET['ipAddress'] = "127.0.0.1"; //IP of buyer
$_GET[’kountSessionId'] = “1111111111111"; //Get this from the previous step of device fingerprinting

$inquiry = new Kount_Ris_Request_Inquiry(); 
$inquiry->setSessionId($_GET[’kountSessionId']); 
$inquiry->setName($_GET['name']);
$inquiry->setEmail($_GET['email']);
$inquiry->setMack("Y");
$inquiry->setWebsite(“DEFAULT”);
$inquiry->setIpAddress($_GET['ipAddress']);
$inquiry->setTotal(“995”); //price in pennies

$inquiry->setCardPayment("4111111111111111");
$inquiry->setExpirationMonth(1);
$inquiry->setExpirationYear(2017);

$cart = new Kount_Ris_Data_CartItem("1", "Title", "Description", 1, 995); //add 1 item for $9.95
$inquiry->setCart(array($cart));

$response = $inquiry->getResponse();

//return what we have so we can see what the score is.
print_r($response);

$status = $response->getErrorCode();

if (null !== $status) {  
// handle/record RIS error 
}


if ($response['SCOR'] >70){  
    //accept transaction and continue to payment processing
}else{
    //display message to user- card can not be used
}


} catch (Exception $e) { 
// handle exception 
}

This code should get you extremely close. If it was helpful for completing your Kount PHP API project, please leave me a comment below.

Check out the links in the right sidebar to see what else is currently making me money.

comments powered by Disqus