Inheritance: extends easypost\Resource
示例#1
0
 protected function _processShipping()
 {
     // Required Values
     $requiredValues = array('Length', 'Width', 'Height', 'Weight', 'Packer', 'NumTrees', 'ShipName', 'ShipAddress', 'ShipCity', 'ShipState', 'ShipZip', 'Phone');
     // All variables passed
     $request = Request::all();
     // Array of missing fields
     $return['errorFields'] = array();
     foreach ($requiredValues as $val) {
         if (empty($request[$val])) {
             $return['errorFields'][] = $val;
         }
     }
     // IF fields are missing
     if (!empty($return['errorFields'])) {
         return $return;
     }
     // Connect to API
     \EasyPost\EasyPost::setApiKey(config('app.easyPostAPIKey'));
     $toData = array("name" => $request['ShipName'], "street1" => $request['ShipAddress'], "street2" => $request['ShipAddress2'], "city" => $request['ShipCity'], "state" => $request['ShipState'], "zip" => $request['ShipZip'], "phone" => $request['Phone']);
     $toAddress = \EasyPost\Address::create($toData);
     // Build from address object
     $fromData = array("company" => config('app.fromCompany'), "street1" => config('app.fromStreet1'), "city" => config('app.fromCity'), "state" => config('app.fromState'), "zip" => config('app.fromZip'));
     $fromAddress = \EasyPost\Address::create($fromData);
     // Build parcel object
     $parcelData = array("length" => $request['Length'], "width" => $request['Width'], "height" => $request['Height'], "weight" => $request['Weight']);
     $parcel = \EasyPost\Parcel::create($parcelData);
     // Create shipment object
     $shipment = \EasyPost\Shipment::create(array("to_address" => $toAddress, "from_address" => $fromAddress, "parcel" => $parcel));
     return $shipment->lowest_rate();
 }
示例#2
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();
     }
 }
示例#3
0
 public function buildLabel($id, $size)
 {
     $shipping = $this->getShipping($id);
     $to_address = \EasyPost\Address::create(array("name" => "{$shipping->ship_f_name} {$shipping->ship_l_name}", "street1" => "{$shipping->ship_address1}", "street2" => "{$shipping->ship_address2}", "city" => "{$shipping->ship_city}", "state" => "{$shipping->ship_state}", "zip" => "{$shipping->ship_zip}", "phone" => "{$shipping->phone}"));
     $from_address = \EasyPost\Address::create(array("company" => "Eternally Nocturnal", "street1" => "31121 Westfield", "city" => "Livonia", "state" => "MI", "zip" => "48150", "phone" => "313-515-5094"));
     $parcel = \EasyPost\Parcel::create(array("predefined_package" => $size, "weight" => 16.0));
     $shipment = \EasyPost\Shipment::create(array("to_address" => $to_address, "from_address" => $from_address, "parcel" => $parcel));
     $shipment->buy($shipment->lowest_rate());
     ShippingLabel::create(['cart_id' => $id, 'easypost_id' => $shipment->postage_label->id, 'tracking_code' => $shipment->tracking_code, 'easypost_tracking' => $shipment->tracker->id, 'label_url' => $shipment->postage_label->label_url, 'created' => $shipment->postage_label->created_at, 'rate' => $shipment->selected_rate->rate, 'carrier' => $shipment->selected_rate->carrier, 'shipment_id' => $shipment->selected_rate->shipment_id]);
     Shipping::where('cart_id', $id)->update(['shipped_status' => 'SHIPPED', 'tracking_number' => $shipment->tracking_code]);
     $link = $shipment->postage_label->label_url;
     $this->slacker->sendShippingLabel($link);
     return redirect()->route('salesmanager.index');
 }
 /**
  * @return mixed
  */
 private function _getQuotes()
 {
     $api_key = Mage::helper('core')->decrypt($this->getConfigData('api_key'));
     \EasyPost\EasyPost::setApiKey($api_key);
     $r = $this->_rawRequest;
     $to_address = \EasyPost\Address::create(array("name" => "", "street1" => "", "street2" => "", "city" => $r->getOrigCountry(), "state" => $r->getOrigRegionCode(), "zip" => $r->getOrigPostal(), "phone" => "", "country" => $r->getOrigCountry()));
     $from_address = \EasyPost\Address::create(array("company" => "", "street1" => "", "city" => "", "state" => $r->getDestRegionCode(), "zip" => $r->getDestPostal(), "phone" => '', "country" => $r->getDestCountry()));
     $parcel = \EasyPost\Parcel::create(array("weight" => $r->getWeight()));
     $shipment = $this->_createShipment($to_address, $from_address, $parcel);
     try {
         if (self::ONLY_LOWEST_RATE == $this->getConfigData('only_lowest_option')) {
             $rates = $shipment->lowest_rate();
             return $this->_paserSingleResponse($rates);
         } else {
             $rates = $shipment->rates;
             return $this->_paserMutiResponse($rates);
         }
     } catch (Exception $e) {
         return null;
     }
 }
示例#5
0
<?php

require_once "../vendor/autoload.php";
\EasyPost\EasyPost::setApiKey('cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi');
// Parcel: create
$params = array("length" => 20.2, "width" => 10.9, "height" => 5, "weight" => 14.8);
$parcel = \EasyPost\Parcel::create($params);
$params = array("predefined_package" => 'SmallFlatRateBox', "weight" => 38.1);
$parcel = \EasyPost\Parcel::create($params);
// retrieve
$retrieved = \EasyPost\Parcel::retrieve($parcel->id);
print_r($retrieved);
// all
$all = \EasyPost\Parcel::all();
//print_r($all);
/*
for($i = 0, $k = count($all); $i < $k; $i++) {
  print_r(\EasyPost\Parcel::retrieve($all[$i]->id));
}
*/
<?php

// require_once("../vendor/autoload.php");
require_once "../lib/easypost.php";
\EasyPost\EasyPost::setApiKey('cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi');
// create addresses
$to_address_params = array("name" => "Sawyer Bateman", "street1" => "388 Townsend St", "street2" => "Apt 30", "city" => "San Francisco", "state" => "CA", "zip" => "94107");
$to_address = \EasyPost\Address::create($to_address_params);
$from_address_params = array("name" => "Jon Calhoun", "street1" => "388 Townsend St", "street2" => "Apt 20", "city" => "San Francisco", "state" => "CA", "zip" => "94107", "phone" => "323-855-0394");
$from_address = \EasyPost\Address::create($from_address_params);
// create parcel
$parcel_params = array("length" => 20.2, "width" => 10.9, "height" => 5, "predefined_package" => null, "weight" => 14.8);
$parcel = \EasyPost\Parcel::create($parcel_params);
// create shipment
$shipment_params = array("from_address" => $from_address, "to_address" => $to_address, "parcel" => $parcel);
$shipment = \EasyPost\Shipment::create($shipment_params);
print_r($shipment);
// get shipment rates - optional, rates are added to the obj when it's created if addresses and parcel are present
if (count($shipment->rates) === 0) {
    $shipment->get_rates();
    print_r($shipment);
}
// retrieve one rate
$rate = \EasyPost\Rate::retrieve($shipment->lowest_rate());
print_r($rate);
// create rates the other way
$created_rates = \EasyPost\Rate::create($shipment);
print_r($created_rates);
print_r(\EasyPost\Shipment::retrieve($shipment));
$shipment = \EasyPost\Shipment::retrieve(array('id' => "shp_iUXLz4n0"));
$shipment->buy($shipment->rates[1]);
示例#7
0
<?php

require_once "../vendor/autoload.php";
\EasyPost\EasyPost::setApiKey('cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi');
$to_address = \EasyPost\Address::create(array("name" => "Dirk Diggler", "street1" => "388 Townsend St", "street2" => "Apt 20", "city" => "San Francisco", "state" => "CA", "zip" => "94107", "phone" => "415-456-7890"));
$from_address = \EasyPost\Address::create(array("company" => "Simpler Postage Inc", "street1" => "764 Warehouse Ave", "city" => "Kansas City", "state" => "KS", "zip" => "66101", "phone" => "620-123-4567"));
$parcel = \EasyPost\Parcel::create(array("predefined_package" => "LargeFlatRateBox", "weight" => 76.90000000000001));
$shipment = \EasyPost\Shipment::create(array("to_address" => $to_address, "from_address" => $from_address, "parcel" => $parcel));
$shipment->buy($shipment->lowest_rate());
echo $shipment->postage_label->label_url;
示例#8
0
 /**
  * create a parcel
  *
  * weight needs to be in ounces (oz)
  * length, width, and height need to be inches (in)
  *
  * @param float $weight
  * @param float $length
  * @param float $width
  * @param float $height
  * @return \EasyPost\Parcel
  * @throws \browner12\shipping\ShippingException
  */
 public function parcel($weight, $length, $width, $height)
 {
     //try to create parcel
     try {
         $parcel = Parcel::create(['predefined_package' => null, 'weight' => round($weight, 1), 'length' => round($length, 1), 'width' => round($width, 1), 'height' => round($height, 1)]);
     } catch (EasyPostException $e) {
         throw new ShippingException('Unable to create parcel.', 0, $e);
     }
     //return parcel object
     return $parcel;
 }
示例#9
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";