Ejemplo n.º 1
0
 public static function writeResponse(api\AVRSAPI $api, $prefix = null, $suffix = 'json')
 {
     if (!isset($prefix)) {
         $prefix = date(self::$prefixFormat);
     }
     $fh = fopen(__DIR__ . '/' . $prefix . 'response.' . $suffix, 'w');
     fwrite($fh, $api->getResult());
     fclose($fh);
 }
Ejemplo n.º 2
0
<?php

namespace samples;

if (!class_exists(__NAMESPACE__ . '\\Loader')) {
    require_once realpath(__DIR__ . '/loader.php');
}
use api\AVRSAPI;
$json = json_encode(array('_gte' => '-2 hours', '_lte' => 'now'));
$url = '/api/v1/deals/?pdf=1&accept-time=' . urlencode($json);
$api = new AVRSAPI();
$api->enableDebug();
$api->setURL($url);
$api->send();
Writer::writeRequest($api);
if ($api->getInfo('http_code') == 200) {
    Writer::writeResponse($api, null, 'pdf');
} else {
    Writer::writeResponse($api, null, 'txt');
}
Ejemplo n.º 3
0
$retryDelayBase = 3;
// do we have an inventory reservation already?
// check from newest reservation to oldest
$haveReservation = false;
$reservations = array_reverse(TestRecords::getRecords());
foreach ($reservations as $reservation) {
    if (($reservation['conditions'] & $bitmask) == $bitmask) {
        $haveReservation = true;
        break;
    }
}
if (!$haveReservation) {
    $reservation = TestRecords::reserveRecord($bitmask);
}
// create a deal with the required fields and immediately request fees
$api = new AVRSAPI();
$api->setURL('/api/v1/deals/');
$api->setMethod('POST');
$api->addPayload('vehicles', array(array('vin' => $reservation['vin'], 'plate' => $reservation['plate'], 'insurance' => 'Y')));
$api->addPayload('status', 'QF');
$api->addPayload('transaction-type', 6);
$api->send();
$response = json_decode($api->getResult(), true);
while ($retryAttempts++ < $retryMax && $response['deals'][0]['error-code'] == 'CADMV/Q023') {
    error_log('DMV Retry Code Encountered');
    sleep($retryDelayBase * pow(2, $retryAttempts));
    $api->send();
    $response = json_decode($api->getResult(), true);
}
Writer::writeRequestResponse($api);
if (empty($response['deals'][0]['error-code'])) {
Ejemplo n.º 4
0
function createApiKey(array $keyDetails)
{
    $api = new AVRSAPI();
    $api->setMethod('POST');
    $api->setURL('/api/v1.5/apiauthkeys/');
    foreach ($keyDetails as $key => $value) {
        $api->addPayload($key, $value);
    }
    $api->send();
    $httpInfo = $api->getInfo();
    $results = json_decode($api->getResult(), true);
    if ($httpInfo['http_code'] != 200) {
        print_r($results);
        throw new \Exception('Unable to create API key.  Received http error code: ' . $httpInfo['http_code']);
    }
    if (isset($results['keys'][0]) && is_array($results['keys'][0])) {
        return $results['keys'][0];
    }
    return [];
}
Ejemplo n.º 5
0
$retryDelayBase = 3;
// do we have an inventory reservation already?
// check from newest reservation to oldest
$haveReservation = false;
$reservations = array_reverse(TestRecords::getRecords());
foreach ($reservations as $reservation) {
    if (($reservation['conditions'] & $bitmask) == $bitmask) {
        $haveReservation = true;
        break;
    }
}
if (!$haveReservation) {
    $reservation = TestRecords::reserveRecord($bitmask);
}
// create a deal with the required fields and immediately request fees
$api = new AVRSAPI();
$api->setURL('/api/v1/deals/');
$api->setMethod('POST');
$api->addPayload('vehicles', [['vin' => $reservation['vin'], 'plate' => $reservation['plate'], 'prior-owner-name' => $reservation['owner'], 'prior-lienholder-name' => $reservation['lien-holder'], 'insurance' => 'Y', 'smog' => 'CRT', 'transfer-number' => 1, 'use-tax-reclass' => 'Y', 'ownership-cert-date' => '2015-06-06', 'odometer' => 123456, 'odometer-code' => 'actual', 'odometer-unit' => 'M', 'transfer-date' => date('Y-m-d'), 'cost' => 5000]]);
$api->addPayload('owners', [['city' => 'Sacramento', 'county' => 34, 'dl-type' => 'unlicensed', 'name:0' => 'Owner New', 'state' => 'CA', 'street:0' => '4625 Madison Ave', 'type' => 'owner', 'zip' => 95841]]);
$api->addPayload('status', 'QF');
$api->addPayload('transaction-type', 5);
$api->addPayload('attributes', 0x4);
// no lien holder
$api->send();
$response = json_decode($api->getResult(), true);
while ($retryAttempts++ < $retryMax && $response['deals'][0]['error-code'] == 'CADMV/Q023') {
    error_log('DMV Retry Code Encountered');
    sleep($retryDelayBase * pow(2, $retryAttempts));
    $api->send();
    $response = json_decode($api->getResult(), true);
Ejemplo n.º 6
0
// do we have an inventory reservation already?
// check from newest reservation to oldest
$haveReservation = false;
$reservations = array_reverse(TestRecords::getRecords());
foreach ($reservations as $reservation) {
    if (($reservation['conditions'] & $bitmask) == $bitmask) {
        $haveReservation = true;
        break;
    }
}
if (!$haveReservation) {
    $reservation = TestRecords::reserveRecord($bitmask);
}
// create a deal with the required fields and immediately request fees
// indicate that this is a posting-fees transaction
$api = new AVRSAPI();
$api->setURL('/api/v1/deals/');
$api->setMethod('POST');
$api->addPayload('vehicles', array(array('vin' => $reservation['vin'], 'plate' => $reservation['plate'], 'insurance' => 'Y', 'smog' => 'CRT')));
$api->addPayload('status', 'QF');
$api->addPayload('transaction-type', 6);
$api->addPayload('rdf', AVRSAPI::$rdfBitmask['U']);
// RDF Code U: Posting Fees Only
$api->addPayload('avs', array('street:0' => '770 E SHAW', 'zip' => 93710));
// the most common address for commercial vehicles is this Pac Bell address
$api->send();
$response = json_decode($api->getResult(), true);
while ($retryAttempts++ < $retryMax && $response['deals'][0]['error-code'] == 'CADMV/Q023') {
    error_log('DMV Retry Code Encountered');
    sleep($retryDelayBase * pow(2, $retryAttempts));
    $api->send();
use api\AVRSAPI;
use api\TestRecords;
// exponential backoff settings
$retryAttempts = 0;
$retryMax = 3;
$retryDelayBase = 3;
// create a deal with the required fields, request fees after getting a deal with decoded vin info back
$api = new AVRSAPI();
$api->setURL('/api/v1/deals/');
$api->setMethod('POST');
$api->addPayload('owners', [['zip' => 95492]]);
$api->addPayload('vehicles', [['cost' => 45000, 'first-operated-date' => '2017-11-11', 'first-sold-date' => '2017-11-11', 'vin' => '3B7HC13YXYG105749', 'type-license-code' => 11]]);
$api->addPayload('transaction-type', 3);
$api->addPayload('gateway-type', 'CALC-CA');
$api->send();
$response = json_decode($api->getResult(), true);
Writer::writeRequestResponse($api);
$api = new AVRSAPI();
$api->setURL('/api/v1/deals/');
$api->setMethod('PUT');
$api->addPayload('status', 'QF');
$api->addPayload('id', $response['deals'][0]['id']);
$api->send();
$response = json_decode($api->getResult(), true);
while ($retryAttempts++ < $retryMax && $response['deals'][0]['error-code'] == 'CADMV/Q023') {
    error_log('DMV Retry Code Encountered');
    sleep($retryDelayBase * pow(2, $retryAttempts));
    $api->send();
    $response = json_decode($api->getResult(), true);
}
Writer::writeRequestResponse($api);
Ejemplo n.º 8
0
<?php

namespace samples;

if (!class_exists(__NAMESPACE__ . '\\Loader')) {
    require_once realpath(__DIR__ . '/loader.php');
}
use api\AVRSAPI;
use api\TestRecords;
// exponential backoff settings
$retryAttempts = 0;
$retryMax = 3;
$retryDelayBase = 3;
// create a deal with the required fields and immediately request fees
$api = new AVRSAPI();
$api->setURL('/api/v1/deals/');
$api->setMethod('POST');
$api->addPayload('owners', [['zip' => 95492]]);
$api->addPayload('vehicles', [['cost' => 45000, 'first-operated-date' => '2017-11-11', 'first-sold-date' => '2017-11-11', 'vin' => '3B7HC13YXYG105749', 'fuel-type' => 'F', 'make' => 'GMC', 'model-body' => 'SD', 'model-year' => 2015, 'type-license-code' => 11]]);
$api->addPayload('status', 'QF');
$api->addPayload('transaction-type', 3);
$api->addPayload('gateway-type', 'CALC-CA');
$api->send();
$response = json_decode($api->getResult(), true);
while ($retryAttempts++ < $retryMax && $response['deals'][0]['error-code'] == 'CADMV/Q023') {
    error_log('DMV Retry Code Encountered');
    sleep($retryDelayBase * pow(2, $retryAttempts));
    $api->send();
    $response = json_decode($api->getResult(), true);
}
Writer::writeRequestResponse($api);
Ejemplo n.º 9
0
<?php

namespace samples;

if (!class_exists(__NAMESPACE__ . '\\Loader')) {
    require_once realpath(__DIR__ . '/loader.php');
}
use api;
$api = new api\AVRSAPI();
$api->setURL('/api/v1.5/apiauthkeys/');
$api->setMethod('POST');
$api->addPayload('passphrase', md5('this is my unhashed passphrase'));
$api->send();
Writer::writeRequestResponse($api);
$response = json_decode($api->getResult(), true);
$api->resetPayload();
$api->setMethod('DELETE');
$api->addPayload('id', $response['keys'][0]['id']);
$api->send();
Writer::writeRequestResponse($api);
Ejemplo n.º 10
0
<?php

namespace samples;

if (!class_exists(__NAMESPACE__ . '\\Loader')) {
    require_once realpath(__DIR__ . '/loader.php');
}
use api;
$api = new api\AVRSAPI();
$api->setURL('/api/v1/test-records/');
$api->send();
Writer::writeRequestResponse($api);
var_export(json_decode($api->getResult(), true));
Ejemplo n.º 11
0
<?php

namespace samples;

if (!class_exists(__NAMESPACE__ . '\\Loader')) {
    require_once realpath(__DIR__ . '/loader.php');
}
use api;
$api = new api\AVRSAPI();
$api->setURL('/api/v1/test-records/');
$api->setMethod('POST');
// See https://github.com/PaulJulio/avrs-php-api/blob/master/api/testrecords.php for the bit listing
$api->addPayload('conditions', api\TestRecords::BIT_AUTO | api\TestRecords::BIT_RENEWAL_DUE);
$api->send();
Writer::writeRequestResponse($api);
echo $api->getResult();