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(); }
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(); } }
/** * create an address * * @param string $name * @param string $street * @param string $street2 * @param string $city * @param string $state * @param string $zip * @param string $country * @return \EasyPost\Address * @throws \browner12\shipping\ShippingException */ public function address($name, $street, $street2, $city, $state, $zip, $country) { //create address object try { $address = Address::create(['name' => $name, 'street' => $street, 'street2' => $street2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country]); } catch (EasyPostException $e) { throw new ShippingException('Unable to create address.', 0, $e); } //return address object return $address; }
/** * @depends testRetrieve */ public function testAll(\EasyPost\Address $address) { $all = \EasyPost\Address::all(); $address_in_all = false; for ($_i = 0, $_k = count($all); $_i < $_k; $_i++) { if ($all[$_i]->id === $address->id) { $address_in_all = true; } } $this->assertTrue($address_in_all); }
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; } }
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); }
<?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 "../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;
<?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; }
<?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";
<?php // require_once("../vendor/autoload.php"); require_once "../lib/easypost.php"; \EasyPost\EasyPost::setApiKey('cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi'); // create addresses $sf_address_params = array("name" => "Jon Calhoun", "street1" => "388 Townsend St", "street2" => "Apt 20", "city" => "San Francisco", "state" => "CA", "zip" => "94107-8273", "phone" => "415-456-7890"); $sf2_address_params = array("name" => "Dirk Diggler", "street1" => "63 Ellis Street", "city" => "San Francisco", "state" => "CA", "zip" => "94102", "phone" => "415-482-2937"); $canada_address_params = array("name" => "Sawyer Bateman", "street1" => "1A Larkspur Cres", "city" => "St. Albert", "state" => "AB", "zip" => "t8n2m4", "country" => "CA", "phone" => "780-252-8464"); $china_address_params = array("name" => "姚明", "street1" => "香港东路6号,5号楼,8号室", "city" => "青岛市", "zip" => "201900", "phone" => "21-7283-8264", "country" => "CN"); $uk_address_params = array("name" => "Queen Elizabeth", "street1" => "Buckingham Palace", "phone" => "+44 20 7930 4832", "city" => "London", "zip" => "SW1A 1AA", "country" => "GB"); $from_address = \EasyPost\Address::create($sf_address_params); $to_address = \EasyPost\Address::create($canada_address_params); // create parcel $parcel_params = array("length" => 20.2, "width" => 10.9, "height" => 5, "weight" => 14.8); $parcel = \EasyPost\Parcel::create($parcel_params); // customs info form $customs_item_params = array("description" => "Many, many EasyPost stickers.", "hs_tariff_number" => 123456, "origin_country" => "US", "quantity" => 1, "value" => 879.47, "weight" => 14); $customs_item = \EasyPost\CustomsItem::create($customs_item_params); $customs_info_params = array("customs_certify" => true, "customs_signer" => "Borat Sagdiyev", "contents_type" => "gift", "contents_explanation" => "", "eel_pfc" => "NOEEI 30.37(a)", "non_delivery_option" => "abandon", "restriction_type" => "none", "restriction_comments" => "", "customs_items" => array($customs_item)); $customs_info = \EasyPost\CustomsInfo::create($customs_info_params); // create shipment $shipment_params = array("from_address" => $from_address, "to_address" => $to_address, "parcel" => $parcel, "customs_info" => $customs_info); $shipment = \EasyPost\Shipment::create($shipment_params); $shipment->buy(array('rate' => $shipment->lowest_rate('usps'), 'insurance' => 249.99)); // $shipment->buy(array('rate' => $shipment->lowest_rate(array('ups', 'fedex')))); // $shipment->buy($shipment->lowest_rate(null, 'PriorityMailInternational')); // Refund specific shipment example // $shipment = \EasyPost\Shipment::retrieve('shp_fX5JFpdF'); // $shipment->refund(); $shipment->insure(array('amount' => 100));