This is an old revision of the document!


type:
integration
supports-foxycart-version-from:
2.0
system:
FraudLabsPro
name:
FraudLabsPro
description:
Adds additional fraud protections for transactions using FraudLabsPro.com
tags:
fraud
date:
2018-03-09
developer:
https://www.fraudlabspro.com

FraudLabsPro

Please note: The code on this page is submitted by members of the FoxyCart community, and may not verified by FoxyCart.com LLC in any way, shape, or form. Please double check the code before installing. If you need help with it please post in our forum, but if we cannot offer assistance (due to unfamiliarity with this particular system or language) we apologize in advance.

Description

FraudLabs Pro is a fraud prevention integration to help FoxyCart merchants to protect their online stores from malicious fraudsters by screening all order transactions for fraud patterns. Its comprehensive and advanced algorithm engines validate all elements such as geolocation, proxy, email, blacklist, transaction velocity and much more to unveil fraud orders accurately.

This integration utilizes the FoxyCart Pre-Payment Webhook that will check the transaction before the payment for an order has been processed. It provides detailed reports of all orders for the merchant’s reference.

Installation

  1. Edit the below code with your FraudLabs Pro API Key and save it as fraudlabspro.php.
  2. Upload it to your site.
  3. Log in to FoxyCart admin page.
  4. Click on payment menu under store option.
  5. Configure the pre-payment hook url under Custom Webhooks section.
  6. Save.

Requirements

  • FoxyCart v2.0

Code

<?php
$rawPost = file_get_contents('php://input');
$cart_details = json_decode($rawPost, true);
 
// Set payment method
if ( $cart_details['_embedded']['fx:customer']['_embedded']['fx:payments'][0]['cc_type'] == 'plastic' ) {
    $payment_mode = 'creditcard';
}
else if ( $cart_details['_embedded']['fx:customer']['_embedded']['fx:payments'][0]['cc_type'] == 'skrill' ) {
    $payment_mode = 'skrill';
}
else if ( strpos ( $cart_details['_embedded']['fx:customer']['_embedded']['fx:payments'][0]['cc_type'], 'paypal' ) !== false ) {
    $payment_mode = 'paypal';
}
else {
    $payment_mode = 'others';
}
 
// Please sign up an API key at https://www.fraudlabspro.com/pricing ,if you do not have one
$apiKey = 'ENTER YOUR API KEY';
 
// Set parameters for fraud checking
$params['format']           = 'json';
$params['ip']               = $cart_details['customer_ip'];
$params['first_name']       = $cart_details['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['first_name'];
$params['last_name']        = $cart_details['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['last_name'];
$params['bill_addr']        = $cart_details['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['address1'] . ' ' . $cart_details['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['address2'];
$params['bill_city']        = $cart_details['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['city'];
$params['bill_state']       = $cart_details['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['region'];
$params['bill_zip_code']    = $cart_details['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['postal_code'];
$params['bill_country']     = $cart_details['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['country'];
$params['ship_addr']        = $cart_details['_embedded']['fx:shipment']['address1'] . ' ' . $cart_details['_embedded']['fx:shipment']['address2'];
$params['ship_city']        = $cart_details['_embedded']['fx:shipment']['city'];
$params['ship_state']       = $cart_details['_embedded']['fx:shipment']['region'];
$params['ship_zip_code']    = $cart_details['_embedded']['fx:shipment']['postal_code'];
$params['ship_country']     = $cart_details['_embedded']['fx:shipment']['country'];
$params['email']            = $cart_details['_embedded']['fx:customer']['email'];
$params['email_domain']     = substr( $cart_details['_embedded']['fx:customer']['email'], strpos( $cart_details['_embedded']['fx:customer']['email'], '@' ) + 1 );
$params['email_hash']       = fraudlabspro_hash($cart_details['_embedded']['fx:customer']['email']);
$params['user_phone']       = $cart_details['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['phone'];
$params['user_order_id']    = substr($cart_details['_links']['self']['href'], strrpos($cart_details['_links']['self']['href'], '/') + 1);
$params['amount']           = $cart_details['total_order'];
$params['payment_mode']     = $payment_mode;
$params['quantity']         = count($cart_details['_embedded']['fx:items']);
$params['flp_checksum']     = ( isset( $_COOKIE['flp_checksum'] ) ) ? $_COOKIE['flp_checksum'] : '';
$params['source']           = 'foxycart';
$params['source_version']   = '1.0.0';
 
$query = '';
 
foreach($params as $key=>$value){
    $query .= '&' . $key . '=' . rawurlencode($value);
}
 
$try = 0;
do {
    $result = file_get_contents('https://api.fraudlabspro.com/v1/order/screen?key=' . $apiKey . $query);
} while(!$result && $try++ < 3);
 
$data = json_decode($result);
 
function fraudlabspro_hash($s){
    $hash = 'fraudlabspro_' . $s;
    for($i=0; $i<65536; $i++) $hash = sha1('fraudlabspro_' . $hash);
 
    return $hash;
}
 
// Approve response for FoxyCart Pre-Payment Hook
$response = array(
    'ok' => true,
    'details' => ''
);
 
// Reject response for FoxyCart Pre-Payment Hook
if ( $data->fraudlabspro_status == 'REVIEW' || $data->fraudlabspro_status == 'REJECT' ) {
    $response['ok'] = false;
    // Notification show to customer in checkout page
    $response['details'] = "Sorry, this order is in high risk. Please contact us to continue.";
}
 
header('Content-Type: application/json');
print json_encode($response);
?>

Site Tools