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(); }
/** * @param OrderAddressDTO $toAddress * @param ParcelDTO $parcel * @return ShipmentRate[] */ public function getRates(OrderAddressDTO $toAddress, ParcelDTO $parcel) { $shipment = EasyPost\Shipment::create(['from_address' => $this->getEasyPostAddress($this->fromAddress), 'to_address' => $this->getEasyPostAddress($toAddress), 'parcel' => $this->getEasyPostParcel($parcel)]); $shipmentRates = []; foreach ($shipment->rates as $rate) { $shipmentRates[] = $this->getShipmentRateFromEasyPostRate($rate); } $this->sortShipmentRatesLowestToHighest($shipmentRates); return $shipmentRates; }
/** * create a shipment * * @param mixed $to * @param mixed $from * @param mixed $parcel * @param mixed $customs * @return \EasyPost\Shipment * @throws \browner12\shipping\ShippingException */ public function shipment($to, $from, $parcel, $customs) { //shipment try { $shipment = Shipment::create(['to_address' => $to, 'from_address' => $from, 'parcel' => $parcel, 'customs' => $customs]); } catch (EasyPostException $e) { throw new ShippingException('Unable to create shipment.', 0, $e); } //return return $shipment; }
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'); }
<?php require_once "../lib/easypost.php"; \EasyPost\EasyPost::setApiKey('cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi'); $shipment = \EasyPost\Shipment::create(array('to_address' => array("name" => "Dr. Steve Brule", "street1" => "179 N Harbor Dr", "city" => "Redondo Beach", "state" => "CA", "zip" => "90277", "phone" => "310-808-5243"), 'from_address' => array("company" => "EasyPost", "street1" => "118 2nd Street", "street2" => "4th Floor", "city" => "San Francisco", "state" => "CA", "zip" => "94105", "phone" => "415-456-7890"), 'parcel' => array('length' => 9, 'width' => 6, 'height' => 2, 'weight' => 10))); echo $shipment->id; $shipment->buy($shipment->lowest_rate("USPS")); $shipment->insure(array('amount' => 100));
<?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]);
<?php require_once "../lib/easypost.php"; \EasyPost\EasyPost::setApiKey('cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi'); try { // create addresses $from_address = array("company" => "EasyPost", "street1" => "388 Townsend St", "city" => "San Francisco", "state" => "CA", "zip" => "94107-8273", "phone" => "415-456-7890"); $parcel = array("predefined_package" => 'Parcel', "weight" => 22.9); // in your application orders will likely // come from an external data source $orders = array(array("address" => array("name" => "Ronald", "street1" => "6258 Amesbury St", "city" => "San Diego", "state" => "CA", "zip" => "92114"), "reference" => "123456786"), array("address" => array("name" => "Hamburgler", "street1" => "8308 Fenway Rd", "city" => "Bethesda", "state" => "MD", "zip" => "20817"), "reference" => "123456787"), array("address" => array("name" => "Grimace", "street1" => "10 Wall St", "city" => "Burlington", "state" => "MA", "zip" => "01803"), "reference" => "123456788")); // create shipments $shipments = array(); for ($i = 0, $j = count($orders); $i < $j; $i++) { $shipment = \EasyPost\Shipment::create(array("to_address" => $orders[$i]["address"], "from_address" => $from_address, "parcel" => $parcel, "reference" => $orders[$i]["reference"])); $shipment->buy(array("rate" => $shipment->lowest_rate('usps'))); $shipments[] = $shipment; } // create a batch to hold shipments and scan_form $batch = \EasyPost\Batch::create(); $batch->add_shipments(array("shipments" => $shipments)); // this could alternatively take a list of shipment_ids rather than shipment objects // request a scan form $batch->create_scan_form(); // wait for scan form to complete while (empty($batch->scan_form)) { sleep(5); $batch->refresh(); } // print scan form url print_r($batch);
<?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;
<h2 class="title-2 uppercase"><strong> <i class="icon-docs"></i> Shipping Rates</strong> </h2> <div class="row"> <div class="col-sm-12"> <p>Select shipping rate.</p> <?php require_once 'includes/plugins/easypost-php-master/lib/easypost.php'; \EasyPost\EasyPost::setApiKey('kZvkSRX4nEqTN3ju6ybPmg'); $shipment = \EasyPost\Shipment::create(array('to_address' => array('name' => 'George Costanza', 'company' => 'Vandelay Industries', 'street1' => '8605 Santa Monica Blvd ', 'street2' => '', 'city' => 'Los Angeles', 'state' => 'CA', 'zip' => '90069'), 'from_address' => array('company' => 'EasyPost', 'street1' => '410 Andover Park E', 'street2' => '', 'city' => 'Tukwila', 'state' => 'WA', 'zip' => '98188', 'phone' => '206-767-9950'), 'parcel' => array('length' => 9, 'width' => 6, 'height' => 2, 'weight' => 10))); ?> <table class="table table-striped table-bordered table-hover table-condensed"> <thead> <tr> <th></th> <th>#</th> <th>Carrier</th> <th>Service</th> <th>Rate</th> <th>New Rate</th> </tr> </thead> <tbody> <h2><?php echo $shipment->id;
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(); } }
<h2 class="title-2 uppercase"><strong> <i class="icon-docs"></i> Shipping Rates</strong> </h2> <div class="row"> <div class="col-sm-12"> <p>Select shipping rate.</p> <?php require_once 'includes/plugins/easypost-php-master/lib/easypost.php'; \EasyPost\EasyPost::setApiKey('kZvkSRX4nEqTN3ju6ybPmg'); $shipment = \EasyPost\Shipment::create(array('to_address' => array('name' => 'George Costanza', 'company' => 'Vandelay Industries', 'street1' => '1 E 161st St.', 'street2' => '4th Floor', 'city' => 'Bronx', 'state' => 'NY', 'zip' => '10451'), 'from_address' => array('company' => 'EasyPost', 'street1' => '118 2nd Street', 'street2' => '4th Floor', 'city' => 'San Francisco', 'state' => 'CA', 'zip' => '94105', 'phone' => '415-528-7555'), 'parcel' => array('length' => 24, 'width' => 24, 'height' => 15, 'weight' => 304))); ?> <table class="table table-striped table-bordered table-hover table-condensed"> <thead> <tr> <th>#</th> <th>Carrier</th> <th>Service</th> <th>Rate</th> <th>ID</th> </tr> </thead> <tbody> <?php $number_row = 1;
/** * @param $to_address * @param $from_address * @param $parcel * @return mixed */ private function _createShipment($to_address, $from_address, $parcel) { $shipment = \EasyPost\Shipment::create(array("to_address" => $to_address, "from_address" => $from_address, "parcel" => $parcel)); return $shipment; }