API - Expectus

Struktura zapytania



https://ex.salelifter.com/XXXXXX/json/email/example@example.com


{"example@example.com":20}

Przykłady skryptów JS oraz PHP

Javascript

Poniżej przykład wywołania Javascript w formularzu z użyciem biblioteki jQuery:

<script>
$('.check-form').click(function () {

    var data = {
        email: $('#email').val(),
        firstname: $('#firstname').val(),
        lastname: $('#lastname').val(),
        gsm: $('#gsm').val(),
        text: $('#text').val(),
        zip: $('#zip').val(),
        city: $('#city').val(),
        nip: $('#nip').val(),
        pesel: $('#pesel').val(),
        regon: $('#regon').val(),
        referer: window.location.href
    }
    validationExpectus(data);
});

function validationExpectus(data){

    var valid = true;
    $.ajax({
        type: 'POST',
        url: '/check_ex.php',
        data:  data,
        success: function(res){
            var chk = res[0]['email'][data['email']];
            if(chk!=undefined && chk<30) {
                valid = false;
               alert('Error')
            }
        },
        dataType: 'json',
        async: false
    });

    return valid;
}

</script>
                    

PHP - check_ex.php

Skrypt pośredniczący między Javascript formularza a systemem Expectus.

<?php

$curl = curl_init('http://ex.salelifter.com/post');
$data = array(
    'format' => 'json',
    'apiKey' => '#############################', // your API key
    'importDeduplication' => false,
    'fileDeduplication' => false,
    'recordTests' => array(
        'AveragePointsRecord',
        'IsPerfectRecord',
        'ZipCityRecord',
        'FullnameRecord',
    )
);

foreach (array('email', 'gsm', 'zip', 'city', 'answer', 'firstname', 'lastname',  'nip', 'pesel', 'regon') as $field) {
    if (isset($_POST[$field]) && !empty($_POST[$field])) {
         if ($field == 'gsm') {
             $record['gsm'] = '48' . trim(strtolower($_POST['gsm']));
        } else {
             $record[$field] = trim(strtolower($_POST[$field]));
        }
    }
}
$data['records'] = array();
$data['records'][] = $record;



// for hlr test
$data['hlrCallback'] = 'http://mydomain.com/hlr_response.php';
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_REFERER, $_POST['referer']);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("HTTP_X_FORWARDED_FOR: " . $_SERVER['REMOTE_ADDR']));
$returnJson = curl_exec($curl);
if ($returnJson === false) {
    die("expectus call error: \n$url\n" . print_r($data, true) . "\n" . curl_error($curl));
}
curl_close($curl);

$return = json_decode($returnJson, true);