PHP code example of siftscience / sift-php

1. Go to this page and download the library: Download siftscience/sift-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

siftscience / sift-php example snippets




$sift = new SiftClient([
    'api_key' => 'my_api_key',
    'account_id' => 'my_account_id'
]);

// or

Sift::setApiKey('my_api_key');
Sift::setAccountId('my_account_id');
$sift = new SiftClient();

       $sift = new SiftClient([
        'api_key' => 'my_api_key',
        'account_id' => 'my_account_id'
    ]);
    

$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->track('$transaction', [
    '$user_id' => '23056',
    '$user_email' => '[email protected]',
    '$seller_user_id' => '2371',
    '$transaction_id' => '573050',
    '$currency_code' => 'USD',
    '$amount' => 15230000,
    '$time' => 1327604222,
    'seller_user_email' => '[email protected]',
    'trip_time' => 930,
    'distance_traveled' => 5.26,
]);

$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->label('23056', [
    '$is_bad' => true,
    '$abuse_type' => 'promotion_abuse'
]);

$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->unlabel('23056', ['abuse_type' => 'content_abuse']);

$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->score('23056');
$response->body['scores']['payment_abuse']['score']; // => 0.030301357270181357

$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->getWorkflowStatus('my_run_id');
$response->body['state']; // => "running"

$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->getUserDecisions('example_user');
$response->body['decisions']['account_abuse']['decision']['id']; // => "ban_user"

$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->getOrderDecisions('example_order');
$response->body['decisions']['payment_abuse']['decision']['id']; // => "ship_order"

$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->getSessionDecisions('example_user', 'example_session');
$response->body['decisions']['account_takeover']['decision']['id']; // => "session_decision"

$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $this->client->getDecisions(['entity_type' => 'example_entity_type','abuse_types' => 'example_abuse_types']);
$response->isOk()

$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->applyDecisionToUser('example_user','example_decision','example_source',['analyst' => '[email protected]']
$response->isOk()

$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->applyDecisionToOrder('example_user','example_order','example_decision','example_source',['analyst' => '[email protected]']
$response->isOk()

$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->applyDecisionToSession('example_user','example_session','example_decision','example_source',['analyst' => '[email protected]']
$response->isOk()

$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->postWebhooks(["payload_type" => "ORDER_V1_0",
    "status"=> "active",
    "url"=> "https://example1.com/",
    "enabled_events" => ['$create_order'],
    "name"=> "My webhook name",
    "description"=> "This is a webhook!"]);
$response->isOk()

$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->retrieveWebhook('webhook_id');
$response->isOk()

$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->listAllWebhooks();
$response->isOk()

$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->updateWebhook('webhook_id', ["payload_type" => "ORDER_V1_0",
    "status"=> "active",
    "url"=> "https://example1.com/",
    "enabled_events" => ['$create_order'],
    "name"=> "My webhook name update",
    "description"=> "This is a webhook! update"]);
$response->isOk()

$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->deleteWebhook('webhook_id');
$response->isOk()

composer update
composer exec phpunit -v -- --bootstrap vendor/autoload.php test

$sift = new SiftClient([
    'api_key' => 'my_api_key',
    'account_id' => 'my_account_id',
    'api_endpoint' => 'http://api.sift.com',
    'curl_opts' => [CURLOPT_CONNECT_TO => ['api.sift.com:80:localhost:8081']],
]);
shell script
composer