상속: extends EasypostResource
예제 #1
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);
 }
예제 #2
0
<?php

require_once "../lib/easypost.php";
\EasyPost\EasyPost::setApiKey('cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi');
$to_address = \EasyPost\Address::create(array("name" => "Jeff Greenstein", "street1" => "2 8th St", "city" => "Hermosa Beach", "state" => "CA", "zip" => "90254", "phone" => "310-456-7890"));
$from_address = \EasyPost\Address::create(array("company" => "EasyPost", "street1" => "164 Townsend", "street2" => "#1", "city" => "San Francisco", "state" => "CA", "zip" => "94107", "phone" => "415-379-7678"));
$parcel = \EasyPost\Parcel::create(array("height" => 10, "length" => 15, "width" => 5, "weight" => 32));
$shipment = \EasyPost\Shipment::create(array("to_address" => $to_address, "from_address" => $from_address, "parcel" => $parcel));
$shipment->buy($shipment->lowest_rate(array('UPS')));
echo $shipment->id;
$pickup = \EasyPost\Pickup::create(array("address" => $from_address, "shipment" => $shipment, "reference" => $shipment->id, "max_datetime" => date("Y-m-d H:i:s"), "min_datetime" => date("Y-m-d H:i:s", strtotime('+1 day')), "is_account_address" => false, "instructions" => "Will be next to garage"));
$pickup->buy(array('carrier' => 'UPS', 'service' => 'Future-day Pickup'));
echo "Confirmation: " . $pickup->confirmation . "\n";