create_and_verify() публичный статический Метод

create and verify an address
public static create_and_verify ( mixed $params = null, string $apiKey = null ) : mixed
$params mixed
$apiKey string
Результат mixed
Пример #1
0
 public function savebooking($shp_id)
 {
     try {
         $ship_data = $this->get_shipment($shp_id);
         if (empty($ship_data['shp_ep_ref'])) {
             $faddr = $this->address_model->get_booking_addr($ship_data['shp_from']);
             $from_address = \EasyPost\Address::create_and_verify(array('name' => $faddr['adr_contact'], 'street1' => $faddr['adr_street1'], 'street2' => $faddr['adr_street2'], 'city' => $faddr['city_name'], 'state' => $faddr['state_name'], 'zip' => $faddr['adr_zip'], 'country' => 'US', 'phone' => $faddr['adr_phone'], 'email' => $faddr['adr_email']));
             $taddr = $this->address_model->get_booking_addr($ship_data['shp_to']);
             $to_address = \EasyPost\Address::create(array('name' => $taddr['adr_contact'], 'street1' => $taddr['adr_street1'], 'street2' => $taddr['adr_street2'], 'city' => $taddr['city_name'], 'state' => $taddr['state_name'], 'zip' => $taddr['adr_zip'], 'country' => $taddr['cnt_code'], 'phone' => $taddr['adr_phone'], 'email' => $taddr['adr_email']));
             $custom_info = array("description" => $ship_data['shp_desc'], "quantity" => $ship_data['shp_quantity'], "weight" => $ship_data['shp_weight'], "value" => $ship_data['shp_value'], "origin_country" => 'US', "eel_pfc" => $ship_data['shp_eelpfc']);
             if ($ship_data['shp_type'] == 'document') {
                 $parcel = \EasyPost\Parcel::create(array("predefined_package" => 'DHLExpressEnvelope', "weight" => $ship_data['shp_weight']));
             } else {
                 $parcel = array("length" => $ship_data['shp_length'], "width" => $ship_data['shp_width'], "height" => $ship_data['shp_height'], "weight" => $ship_data['shp_weight']);
                 $custom_info['customs_items'] = $this->get_shipping_customs($shp_id);
             }
             $shipment = \EasyPost\Shipment::create(array("to_address" => $to_address, "from_address" => $from_address, "parcel" => $parcel, "customs_info" => $custom_info, "carrier_accounts" => array(array('id' => 'ca_2bafcd3ab9b34db9a4de8040f143917f'))));
             $ship_array = $shipment->__toArray(true);
             $this->update_ep_ref($ship_array['id'], $shp_id);
         } else {
             $shipment = \EasyPost\Shipment::retrieve($ship_data['shp_ep_ref']);
         }
         $ship_array = $shipment->__toArray(true);
         if (!empty($ship_array['messages'])) {
             return $ship_array['messages'][0]['message'];
         }
         return $ship_array;
     } catch (Exception $ex) {
         return $ex->getMessage();
     }
 }
Пример #2
0
 public function pickup($shp_id)
 {
     if (!$this->is_logged) {
         redirect("user/login");
     }
     try {
         $user_id = $this->user_model->get_current_user_id();
         $shiping_data = $this->shipping_model->get_shipment($shp_id);
         $shiping_data['fromaddr'] = $this->address_model->get_addr_combo('Sender');
         $shiping_data['scountry'] = $this->address_model->get_country_combo();
         if ($shiping_data['shp_user'] == $user_id) {
             $shipment = \EasyPost\Shipment::retrieve($shiping_data['shp_ep_ref']);
             $btnschedule = $this->input->post('btnschedule');
             if (!empty($btnschedule)) {
                 $selfromaddr = $this->input->post('selfromaddr');
                 $country_code = $this->address_model->get_iso_code_from_country($this->input->post('txtscountry'));
                 $data = array('adr_name' => $this->input->post('txtsname'), 'adr_contact' => $this->input->post('txtscontact'), 'adr_street1' => $this->input->post('txtsstr1'), 'adr_street2' => $this->input->post('txtsstr2'), 'adr_city' => $this->input->post('txtscity'), 'adr_state' => $this->input->post('txtsstate'), 'adr_country' => $country_code, 'adr_phone' => $this->input->post('txtsphone'), 'adr_zip' => $this->input->post('txtszip'), 'adr_email' => $this->input->post('txtsemail'), 'adr_type' => 'Sender', 'adr_userid' => $user_id);
                 if (empty($selfromaddr)) {
                     $selfromaddr = $this->address_model->insert_addr($data);
                 } else {
                     $savesaddr = $this->input->post('savesaddr');
                     if (!empty($savesaddr)) {
                         $where = array('adr_id' => $selfromaddr);
                         $this->address_model->update_addr($data, $where);
                     }
                 }
                 $faddr = $this->address_model->get_booking_addr($selfromaddr);
                 $from_address = \EasyPost\Address::create_and_verify(array('name' => $faddr['adr_contact'], 'street1' => $faddr['adr_street1'], 'street2' => $faddr['adr_street2'], 'city' => $faddr['city_name'], 'state' => $faddr['state_name'], 'zip' => $faddr['adr_zip'], 'country' => 'US', 'phone' => $faddr['adr_phone'], 'email' => $faddr['adr_email']));
                 $instructions = $this->input->post('txtins');
                 $min_date = $shiping_data['shp_date'] . " " . $this->input->post('txtrtime') . ":00";
                 $max_date = $shiping_data['shp_date'] . " " . $this->input->post('txtctime') . ":00";
                 $data = array('address' => $from_address, 'shipment' => $shipment, 'max_datetime' => $max_date, 'min_datetime' => $min_date, 'instructions' => $instructions);
                 $pickup = \EasyPost\Pickup::create($data);
                 $response = $pickup->buy(array('carrier' => 'DHLExpress'));
                 $response = $response->__toArray(true);
                 $shpdata = array('shp_pickupid' => $response['id'], 'shp_pickupconf' => $response['confirmation'], 'shp_scheduled' => 1);
                 $where = array('shp_id' => $shp_id);
                 $this->shipping_model->update($shpdata, $where);
                 $data['message'] = 'Pickup Information Updated..';
                 $this->load->template('history', $data);
                 return;
             }
         } else {
             die('Access Denied...');
         }
     } catch (Exception $ex) {
         $shiping_data['error'] = $ex->getMessage();
     }
     $this->load->template("pickup", $shiping_data);
 }
Пример #3
0
<?php

// require_once("../vendor/autoload.php");
require_once "../lib/easypost.php";
\EasyPost\EasyPost::setApiKey('cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi');
try {
    // create address
    $address_params = array("name" => "Sawyer Bateman", "street1" => "388 Townasend St", "city" => "San Francisco", "state" => "CA", "zip" => "94107", "country" => "US");
    $address = \EasyPost\Address::create($address_params);
    print_r($address);
    // retrieve
    $retrieved_address = \EasyPost\Address::retrieve($address->id);
    print_r($retrieved_address);
    // verify
    $verified_address = $address->verify();
    print_r($verified_address);
    // create and verify at the same time
    $verified_on_create = \EasyPost\Address::create_and_verify($address_params);
    print_r($verified_on_create);
    // all
    // $all = \EasyPost\Address::all();
    //print_r($all);
} catch (Exception $e) {
    echo "Status: " . $e->getHttpStatus() . ":\n";
    echo $e->getMessage();
    if (!empty($e->param)) {
        echo "\nInvalid param: {$e->param}";
    }
    exit;
}