| Both sides previous revisionPrevious revisionNext revision | Previous revision |
| integration:fraudlabspro [2018/03/30 06:47] – [Code] fraudlabspro | integration:fraudlabspro [2026/05/18 09:48] (current) – [Code] adam |
|---|
| systems : FraudLabsPro # the system(s) that the integration is for, separated with commas if more than one | systems : FraudLabsPro # the system(s) that the integration is for, separated with commas if more than one |
| name : FraudLabsPro # the name of the integration | name : FraudLabsPro # the name of the integration |
| description : Adds additional fraud protections for transactions using FraudLabsPro.com | description : Block payment fraud to minimize chargebacks and fraud losses. |
| tags_tags : fraud # tags, separated by commas. don't include the "system" here. | tags_tags : fraud # tags, separated by commas. don't include the "system" here. |
| date_dt : 2018-03-09 # the date in YYYY-MM-DD format | date_dt : 2024-09-25 # the date in YYYY-MM-DD format |
| version : # if you have a version for your code, enter it here | version : 1.2.1 # if you have a version for your code, enter it here |
| developer_url : https://www.fraudlabspro.com # if you'd like a link back to your site, stick it here | developer_url : https://www.fraudlabspro.com # if you'd like a link back to your site, stick it here |
| ---- | ---- |
| | |
| | |
| |
| |
| <WRAP important round> | <WRAP important round> |
| //**Please note:**// | //**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 [[http://forum.foxycart.com/|post in our forum]], but if we cannot offer assistance (due to unfamiliarity with this particular system or language) we apologize in advance. | 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. Though we believe it works well, this isn't official Foxy code at this point. Contact us if you have any trouble. |
| </WRAP> | </WRAP> |
| |
| * Email notification of fraud orders | * Email notification of fraud orders |
| * Mobile app notification of fraud orders | * Mobile app notification of fraud orders |
| * Social Profile query | |
| |
| ===== Free Micro Plan ===== | ===== Free Micro Plan ===== |
| Looking for a free yet comprehensive fraud prevention solution? Look no more, we offer you one right here. With our free Micro plan, you can start protecting your online business from malicious fraudsters. We provide you with 500 free validation queries that auto-reset every month and is more than sufficient for small & medium business. | Looking for a free yet comprehensive fraud prevention solution? Look no more, we offer you one right here. With our free Micro plan, you can start protecting your online business from malicious fraudsters. It’s absolutely free if your monthly orders are less than 500 transactions or monthly sales are less than 25K USD. There is no upfront credit card information needed, commitment, hidden cost and whatsoever. |
| |
| |
| ===== Installation ===== | ===== Installation ===== |
| - Edit the below code with your FraudLabs Pro API Key and save it as fraudlabspro.php. | - Edit the below code with your FraudLabs Pro API Key and save it as **//fraudlabspro.php//**. |
| - Upload it to your site. | - Upload it to your site. |
| - Log in to FoxyCart admin page. | - Log in to FoxyCart admin page. |
| - Click on payment menu under store option. | - Click on payment menu under store option. |
| - Configure the pre-payment hook url under Custom Webhooks section. | - Configure the pre-payment hook url under Custom Webhooks section and enter the url where the **//fraudlabspro.php//** located. |
| - Save. | - Click on the save button to save the new configuration. |
| ===== Requirements ===== | ===== Requirements ===== |
| * FoxyCart v2.0 | * FoxyCart v2.0 |
| <?php | <?php |
| $rawPost = file_get_contents('php://input'); | $rawPost = file_get_contents('php://input'); |
| $cart_details = json_decode($rawPost, true); | $cartDetails = json_decode($rawPost, true); |
| |
| // Set payment method | if ($cartDetails == '') { |
| if ( $cart_details['_embedded']['fx:customer']['_embedded']['fx:payments'][0]['cc_type'] == 'plastic' ) { | die; |
| $payment_mode = 'creditcard'; | |
| } | } |
| else if ( $cart_details['_embedded']['fx:customer']['_embedded']['fx:payments'][0]['cc_type'] == 'skrill' ) { | |
| $payment_mode = 'skrill'; | $qty = 0; |
| | $itemSku = ''; |
| | foreach ($cartDetails['_embedded']['fx:items'] as $itemId => $itemData) { |
| | $itemQuantity = $itemData['quantity']; |
| | if ($itemData['code'] != '') { |
| | $itemSku .= $itemData['code'] . ':' . $itemQuantity . ','; |
| | } |
| | $qty += $itemQuantity; |
| } | } |
| else if ( strpos ( $cart_details['_embedded']['fx:customer']['_embedded']['fx:payments'][0]['cc_type'], 'paypal' ) !== false ) { | $itemSku = rtrim($itemSku, ','); |
| $payment_mode = 'paypal'; | |
| | if (preg_match('/^\d+(\.\d)*$/', $qty)) { |
| | $qty = ceil($qty); |
| | } |
| | |
| | // Set payment method |
| | $paymentGateway = $cartDetails['_embedded']['fx:customer']['_embedded']['fx:payments'][0]['cc_type']; |
| | if ($paymentGateway == 'plastic') { |
| | $paymentMode = 'creditcard'; |
| | } |
| | elseif (strpos($paymentGateway, 'paypal') !== false) { |
| | $paymentMode = 'paypal'; |
| } | } |
| else { | else { |
| $payment_mode = 'others'; | $paymentMode = $paymentGateway; |
| | } |
| | |
| | $couponCode = ''; |
| | $couponAmt = ''; |
| | $couponType = ''; |
| | if (count($cartDetails['_embedded']['fx:discounts']) > 0) { |
| | if ($cartDetails['_embedded']['fx:discounts'][0]['code'] != '') { |
| | $couponCode = $cartDetails['_embedded']['fx:discounts'][0]['code']; |
| | $couponAmt = -($cartDetails['_embedded']['fx:discounts'][0]['amount']); |
| | } |
| } | } |
| |
| // Set parameters for fraud checking | // Set parameters for fraud checking |
| $params['format'] = 'json'; | $params['format'] = 'json'; |
| $params['ip'] = $cart_details['customer_ip']; | $params['ip'] = $cartDetails['customer_ip']; |
| $params['first_name'] = $cart_details['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['first_name']; | $params['key'] = $apiKey; |
| $params['last_name'] = $cart_details['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['last_name']; | $params['first_name'] = $cartDetails['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['first_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['last_name'] = $cartDetails['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['last_name']; |
| $params['bill_city'] = $cart_details['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['city']; | $params['bill_to'] = $cartDetails['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['company']; |
| $params['bill_state'] = $cart_details['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['region']; | $params['bill_addr'] = $cartDetails['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['address1'] . ' ' . $cartDetails['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['address2']; |
| $params['bill_zip_code'] = $cart_details['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['postal_code']; | $params['bill_city'] = $cartDetails['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['city']; |
| $params['bill_country'] = $cart_details['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['country']; | $params['bill_state'] = $cartDetails['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['region']; |
| $params['ship_addr'] = $cart_details['_embedded']['fx:shipment']['address1'] . ' ' . $cart_details['_embedded']['fx:shipment']['address2']; | $params['bill_zip_code'] = $cartDetails['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['postal_code']; |
| $params['ship_city'] = $cart_details['_embedded']['fx:shipment']['city']; | $params['bill_country'] = $cartDetails['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['country']; |
| $params['ship_state'] = $cart_details['_embedded']['fx:shipment']['region']; | $params['ship_first_name'] = $cartDetails['_embedded']['fx:shipment']['first_name']; |
| $params['ship_zip_code'] = $cart_details['_embedded']['fx:shipment']['postal_code']; | $params['ship_last_name'] = $cartDetails['_embedded']['fx:shipment']['last_name']; |
| $params['ship_country'] = $cart_details['_embedded']['fx:shipment']['country']; | $params['ship_addr'] = $cartDetails['_embedded']['fx:shipment']['address1'] . ' ' . $cartDetails['_embedded']['fx:shipment']['address2']; |
| $params['email'] = $cart_details['_embedded']['fx:customer']['email']; | $params['ship_city'] = ($cartDetails['_embedded']['fx:shipment']['address1'] != '') ? $cartDetails['_embedded']['fx:shipment']['city'] : ''; |
| $params['email_domain'] = substr( $cart_details['_embedded']['fx:customer']['email'], strpos( $cart_details['_embedded']['fx:customer']['email'], '@' ) + 1 ); | $params['ship_state'] = ($cartDetails['_embedded']['fx:shipment']['address1'] != '') ? $cartDetails['_embedded']['fx:shipment']['region'] : ''; |
| $params['email_hash'] = fraudlabspro_hash($cart_details['_embedded']['fx:customer']['email']); | $params['ship_zip_code'] = ($cartDetails['_embedded']['fx:shipment']['address1'] != '') ? $cartDetails['_embedded']['fx:shipment']['postal_code'] : ''; |
| $params['user_phone'] = $cart_details['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['phone']; | $params['ship_country'] = ($cartDetails['_embedded']['fx:shipment']['address1'] != '') ? $cartDetails['_embedded']['fx:shipment']['country'] : ''; |
| $params['user_order_id'] = substr($cart_details['_links']['self']['href'], strrpos($cart_details['_links']['self']['href'], '/') + 1); | $params['email'] = $cartDetails['_embedded']['fx:customer']['email']; |
| $params['amount'] = $cart_details['total_order']; | $params['email_domain'] = substr($cartDetails['_embedded']['fx:customer']['email'], strpos($cartDetails['_embedded']['fx:customer']['email'], '@') + 1); |
| $params['payment_mode'] = $payment_mode; | $params['email_hash'] = fraudlabspro_hash($cartDetails['_embedded']['fx:customer']['email']); |
| $params['quantity'] = count($cart_details['_embedded']['fx:items']); | $params['user_phone'] = $cartDetails['_embedded']['fx:customer']['_embedded']['fx:default_billing_address']['phone']; |
| $params['flp_checksum'] = ( isset( $_COOKIE['flp_checksum'] ) ) ? $_COOKIE['flp_checksum'] : ''; | $params['user_order_id'] = substr($cartDetails['_links']['self']['href'], strrpos($cartDetails['_links']['self']['href'], '/') + 1); |
| | $params['amount'] = $cartDetails['total_order']; |
| | $params['payment_gateway'] = $paymentGateway; |
| | $params['payment_mode'] = $paymentMode; |
| | $params['currency'] = $cartDetails['currency_code']; |
| | $params['quantity'] = $qty; |
| | $params['items'] = $itemSku; |
| | $params['coupon_code'] = $couponCode; |
| | $params['coupon_amount'] = $couponAmt; |
| | $params['coupon_type'] = $couponType; |
| | $params['flp_checksum'] = (isset($_COOKIE['flp_checksum'])) ? $_COOKIE['flp_checksum'] : ''; |
| $params['source'] = 'foxycart'; | $params['source'] = 'foxycart'; |
| $params['source_version'] = '1.0.1'; | $params['source_version'] = '1.3.0'; |
| |
| $query = ''; | $result = http('https://api.fraudlabspro.com/v2/order/screen', $params); |
| | |
| foreach($params as $key=>$value){ | |
| $query .= '&' . $key . '=' . rawurlencode($value); | |
| } | |
| | |
| $result = file_get_contents('https://api.fraudlabspro.com/v1/order/screen?key=' . $apiKey . $query); | |
| |
| $data = json_decode($result); | $data = json_decode($result); |
| |
| function fraudlabspro_hash($s){ | function fraudlabspro_hash($s) { |
| $hash = 'fraudlabspro_' . $s; | $hash = 'fraudlabspro_' . $s; |
| for($i=0; $i<65536; $i++) $hash = sha1('fraudlabspro_' . $hash); | for($i=0; $i<65536; $i++) { |
| | $hash = sha1('fraudlabspro_' . $hash); |
| return $hash; | } |
| | $hash2 = hash('sha256', $hash); |
| | return $hash2; |
| } | } |
| |
| |
| // Reject response for FoxyCart Pre-Payment Hook | // Reject response for FoxyCart Pre-Payment Hook |
| if ( $data->fraudlabspro_status == 'REVIEW' || $data->fraudlabspro_status == 'REJECT' ) { | if ($data->fraudlabspro_status == 'REVIEW' || $data->fraudlabspro_status == 'REJECT') { |
| $response['ok'] = false; | $response['ok'] = false; |
| // Notification show to customer in checkout page | // Notification show to customer in checkout page |
| header('Content-Type: application/json'); | header('Content-Type: application/json'); |
| print json_encode($response); | print json_encode($response); |
| | |
| | function http($url, $fields = '') |
| | { |
| | $ch = curl_init(); |
| | curl_setopt($ch, \CURLOPT_URL, $url); |
| | curl_setopt($ch, \CURLOPT_FAILONERROR, 0); |
| | curl_setopt($ch, \CURLOPT_FOLLOWLOCATION, 1); |
| | curl_setopt($ch, \CURLOPT_AUTOREFERER, 1); |
| | curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); |
| | curl_setopt($ch, \CURLOPT_ENCODING, 'gzip, deflate'); |
| | curl_setopt($ch, \CURLOPT_SSL_VERIFYPEER, 0); |
| | curl_setopt($ch, \CURLOPT_HTTP_VERSION, '1.1'); |
| | curl_setopt($ch, \CURLOPT_TIMEOUT, 60); |
| | |
| | if ($fields) { |
| | curl_setopt($ch, \CURLOPT_POST, 1); |
| | curl_setopt($ch, \CURLOPT_POSTFIELDS, (is_array($fields)) ? http_build_query($fields) : $fields); |
| | } |
| | |
| | $response = curl_exec($ch); |
| | |
| | if (!curl_errno($ch)) { |
| | return $response; |
| | } |
| | |
| | return false; |
| | } |
| ?> | ?> |
| </code> | </code> |
| |
| |