Inheritance: extends EasypostResource
示例#1
0
 public function get_shipping_customs($shp_id)
 {
     $this->db->select('cst_desc as description, cst_qty as quantity, cst_weight as weight, cst_value as value, cst_hts as hs_tariff_number, cst_id');
     $this->db->where('cst_shp_id', $shp_id);
     $items = $this->db->get('customs')->result_array();
     $custom_items = array();
     foreach ($items as $item) {
         $new_item = \EasyPost\CustomsItem::create($item);
         if (!empty($new_item->id)) {
             $this->db->set('cst_ep_ref', $new_item->id);
             $this->db->where('cst_id', $item['cst_id']);
             $this->db->update('customs');
             $custom_items[] = $new_item;
         }
     }
     return $custom_items;
 }
示例#2
0
 /**
  * create a customs item
  *
  * @param \browner12\shipping\Contracts\OrderLine $orderLine
  * @return mixed
  */
 public function customsItem(OrderLine $orderLine)
 {
     return CustomsItem::create(['description' => $orderLine->getProduct()->getDescription(), 'quantity' => $orderLine->getQuantity(), 'weight' => $orderLine->getWeight(), 'value' => $orderLine->getValue(), 'hs_tariff_number' => $orderLine->getProduct()->getTariffNumber(), 'origin_country' => $orderLine->getProduct()->getOriginCountry()]);
 }
<?php

require_once "../vendor/autoload.php";
\EasyPost\EasyPost::setApiKey('cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi');
// CustomsItem: create
$params = array("description" => "I like your dog, he's vry nice.", "hs_tariff_number" => 123456, "origin_country" => "US", "quantity" => 2, "value" => 1.23, "weight" => 14);
$customs_item = \EasyPost\CustomsItem::create($params);
// retrieve
$retrieved = \EasyPost\CustomsItem::retrieve($customs_item->id);
print_r($retrieved);
// all
$all = \EasyPost\CustomsItem::all();
//print_r($all);
/*
for($i = 0, $k = count($all); $i < $k; $i++) {
  print_r(\EasyPost\CustomsItem::retrieve($all[$i]->id));
}
*/
// CustomsInfo: create
$params = array("integrated_form_type" => "form_2976", "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($params);
// retrieve
$retrieved = \EasyPost\CustomsInfo::retrieve($customs_info->id);
print_r($retrieved);
// all
$all = \EasyPost\CustomsInfo::all();
//print_r($all);
// 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));
print_r($shipment);
echo $shipment->postage_label->label_url;