예제 #1
0
     $params = array('url' => $base_url . 'parcels', 'token' => $api_key, 'methodType' => 'POST', 'params' => array('description' => $line[0], 'receiver' => array('email' => $line[1], 'phone' => $line[2]), 'size' => $line[3], 'tmp_id' => RestApi::generate(4, 15), 'target_machine' => $line[4]));
     if ($num >= 10) {
         $params['sender_address'] = array('first_name' => $line[5], 'last_name' => $line[6], 'post_code' => $line[7], 'town' => $line[8], 'street' => $line[9]);
     }
     if ($num >= 11) {
         $params['sender_address']['company_name'] = $line[10];
     }
     if ($num >= 12) {
         $params['sender_address']['building_number'] = $line[11];
     }
     if ($num == 13) {
         $params['sender_address']['flat_number'] = $line[12];
     }
     //echo print_r($params) . '<br>';
     $ret = new RestApi($params);
     $info_arr = $ret->getInfo();
     if ($info_arr['http_code'] != 201) {
         $err = $ret->getResponse();
         $message[] = "Parcel Create failed for line {$row} <br>Error Code: " . $info_arr["http_code"] . " " . $err;
         $error_rows++;
         $row++;
         continue;
     }
     $response = json_decode($ret->getResponse());
     $parcel_id = $response->id;
     // Add the parcel to the log table.
     $params['parcel_id'] = $parcel_id;
     add_parcel($params, $num);
     $processed_rows++;
     $row++;
 }
function print_many_labels(&$params, &$parcels, $username)
{
    require "config.php";
    $return = array();
    $zipname = "test_" . $username . '_' . session_id() . ".zip";
    $zip = new ZipArchive();
    $res = $zip->open($zipname, ZipArchive::CREATE);
    if ($res === TRUE) {
        $timestamp = date('dmy_His', time());
        foreach ($parcels as $key => $parcel) {
            $params['url'] = $base_url . 'reverselogistics/' . $parcel . '/label.json';
            //echo json_encode($params);
            $restApi2 = new RestApi($params);
            $file_name = "InPost_Return_Label" . $timestamp . $key . ".pdf";
            $pdf = $restApi2->getResponse();
            $info = $restApi2->getInfo();
            if ($info['http_code'] != 200) {
                $_SESSION['error_message'] = 'Failed to create your labels ' . $info["http_code"];
                continue;
            }
            $binary = base64_decode($pdf);
            // Add to the list of parcels that need their status
            // updated.
            $return[] = $parcel;
            // Add the PDF to the main ZIP file.
            $zip->addFromString($file_name, $binary);
        }
        $zip->close();
    } else {
        $_SESSION['error_message'] = 'Failed to create ZIP file for your labels.';
        header("Location: r_orders.php");
        return $return;
    }
    return $return;
}
예제 #3
0
//echo '<pre>';
//print_r($restApi1->getInfo());
//echo '</pre><br>';
//echo '<pre>';
//print_r($restApi1->getResponse());
//echo '</pre>';
//returned header info
$info_arr1 = $restApi1->getInfo();
//if parcel creation successful
if ($info_arr1["http_code"] == 201) {
    $response = json_decode($restApi1->getResponse());
    $parcel_id = $response->id;
    //pay for the parcel
    $restApi2 = new RestApi(array('url' => $base_url . 'parcels/' . $parcel_id . '/pay', 'token' => $api_key, 'methodType' => 'POST', 'params' => array()));
    //returned header info
    $info_arr2 = $restApi2->getInfo();
    // if payment successful
    if ($info_arr2["http_code"] == 204) {
        //update payment status in db
        $creation_date = date('Y-m-d H:i:s');
        $query = tep_db_query("UPDATE " . $table_prefix . $parcel_table . " SET status='PAID', rl_code='{$rl_code}', parcel_id='{$parcel_id}', creation_date='{$creation_date}' WHERE id={$new_id}");
        echo "<td><div style='text-align: center'>CREATED & PAID</div></td>";
        echo "<td><div style='text-align: center'>NONE</div></td>";
        //header("Location: u_orders.php");
    } else {
        //if not, display the error code, error description
        $error_cr = $info_arr2["http_code"];
        echo "<td><div style='text-align: center'>UNPAID</div></td>";
        echo "<td><div style='text-align: center'>" . $error_cr . "</div></td>";
    }
    echo "</tr>";
예제 #4
0
    if ($session_life > $inactive) {
        header("Location: logout.php");
    }
    $_SESSION['start'] = time();
} else {
    header("Location: 404_error.php");
}
// Set the timezone
// Europe/London
date_default_timezone_set('Europe/London');
// Get a list of the machines for use on the form.
$params['url'] = $base_url . 'machines';
$params['token'] = $api_key;
$params['methodType'] = 'GET';
$rest_api = new RestApi($params);
$info = $rest_api->getInfo();
$reply = $rest_api->getResponse();
$parcelTargetMachinesId = array();
$parcelTargetMachinesDetail = array();
$defaultSelect = 'Select Machine..';
if ($info['http_code'] == 200) {
    $machines = json_decode($reply);
    if (is_array(@$machines) && !empty($machines)) {
        foreach ($machines as $key => $machine) {
            $parcelTargetMachinesId[$machine->id] = $machine->id . ', ' . @$machine->address->city . ', ' . @$machine->address->street;
            $parcelTargetMachinesDetail[$machine->id] = array('id' => $machine->id, 'address' => array('building_number' => @$machine->address->building_number, 'flat_number' => @$machine->address->flat_number, 'post_code' => @$machine->address->post_code, 'province' => @$machine->address->province, 'street' => @$machine->address->street, 'city' => @$machine->address->city));
        }
    }
} else {
    echo 'Failed to get the machines.<br>';
    echo 'Error code : ' . $info['http_code'] . '<br>';
예제 #5
0
 if ($ret != true) {
     $_SESSION['error_message'] = "The password must contain:<br>one lower case letter, one upper case letter,<br>one digit, one special character,<br>be 8-20 in length, and have no spaces.";
     session_write_close();
     header("Location: register.php");
     return;
 }
 $username = test_input($_POST["email"]);
 $api_key = test_input($_POST["api_key"]);
 $answer = test_input($_POST["answer"]);
 $label_format = $_POST['label_format'];
 $question = $_POST['question'];
 $password = $_POST['password'];
 $password_hash = better_crypt($password);
 // Check if the API Key is valid
 $restApi = new RestApi(array('url' => $base_url . 'machines', 'token' => $api_key, 'methodType' => 'GET', 'params' => array()));
 $info_arr = $restApi->getInfo();
 //echo $info_arr["http_code"];
 if ($info_arr["http_code"] != 200) {
     $_SESSION['error_message'] = 'Your API Key does not seem to be valid<br>Error Code: ' . $info_arr["http_code"];
     header("Location: register.php");
     return;
 }
 // check if the username or API already exists in the DB
 if (checkRedundantVal($username) || checkRedundantVal($api_key)) {
     header("Location: check_user_false.php");
 } else {
     // Connect to the DB
     $con = tep_db_connect();
     if (!$con) {
         die('Could not connect: ' . mysqli_error());
     }
    die('Could not connect: ' . mysqli_error());
}
//var_dump($parcels);
$count = count($parcels);
$to_print_array = array();
$message = array();
// We now have the situation that both Paid and Unpaid lines will come through.
// So we must pay for some.
foreach ($parcels as $parcel) {
    $query = tep_db_query("SELECT * from {$table_prefix}{$parcel_table} where parcel_id='{$parcel}'");
    $ret = tep_db_fetch_array($query);
    if ($ret['status'] == 'UNPAID') {
        // Pay for the parcel.
        $params = array('url' => $base_url . 'parcels/' . $ret['parcel_id'] . '/pay', 'token' => $api_key, 'methodType' => 'POST', 'params' => array());
        $rest = new RestApi($params);
        $info = $rest->getInfo();
        $reply = $rest->getResponse();
        if ($info['http_code'] != 204) {
            $message[] = "Parcel Payment failed for parcel {$parcel}<br>Error Code: " . $info["http_code"] . " " . $reply;
            continue;
        }
        tep_db_query("UPDATE {$table_prefix}{$parcel_table} set status='PAID' WHERE parcel_id='{$parcel}'");
        $to_print_array[] = $parcel;
    } elseif ($ret['status'] == 'PAID') {
        $to_print_array[] = $parcel;
    }
}
//echo $count;
if (count($to_print_array) == 0) {
    // Simply return. We have no labels to print
    header('Location: c_orders.php');
예제 #7
0
 
<body>

<div class="wrapper">
<?php 
include_once 'includes/menu.php';
?>

<div align="center" style="position: relative; top:75px; margin-left:auto; margin-right:auto;">

<?php 
//Generate an active return code
$params = array('url' => $base_url . 'reverselogistics.json', 'token' => $api_key, 'methodType' => 'POST', 'params' => array('rma' => $rma_code, 'parcel_size' => $size, 'expire_at' => $expiry_date, 'sender_phone' => $mobile, 'sender_email' => $email, 'with_label' => 'TRUE', 'additional_description_1' => $add_desc1, 'additional_description_2' => $add_desc2, 'additional_description_3' => $add_desc3, 'address' => array('first_name' => $fname, 'last_name' => $lname, 'company_name' => $cname, 'post_code' => $postcode, 'town' => $town, 'street' => $street, 'building_number' => $building, 'flat_number' => '', 'province' => $county, 'phone' => $rmobile)));
//echo 'sent paramsters ' . json_encode($params) . '<br>';
$restApi = new RestApi($params);
$request = $restApi->getInfo();
//echo 'request ' . print_r($request) . '<br>';
$response = json_decode($restApi->getResponse(), true);
$info_arr = $restApi->getInfo();
//echo '<pre>';
//echo '<br>response ' . print_r($response);
//echo '</pre>';
//echo '<pre>';
//echo '<br>info_arr ' . print_r($info_arr);
//echo '</pre>';
//echo 'getErrno ' . $restApi->getErrno() . '<br>';
//echo 'getError ' . $restApi->getError() . '<br>';
if ($info_arr["http_code"] == 200) {
    $ex_date = $response['expire_at'];
    $exp_date = substr($ex_date, 0, 10);
    //extract expiry date