Inheritance: extends EasypostResource
コード例 #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 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');
 }
コード例 #3
0
ファイル: User.php プロジェクト: vhghorecha/smartdhl
 public function refund()
 {
     if (!$this->is_logged) {
         redirect("user/login");
     }
     $data = array();
     $shp_id = $this->input->post('shp_id');
     $shp_data = $this->shipping_model->get_shipment($shp_id);
     $user_id = $this->user_model->get_current_user_id();
     if ($user_id == $shp_data['shp_user']) {
         try {
             $shipment = \EasyPost\Shipment::retrieve($shp_data['shp_ep_ref']);
             $response = $shipment->refund();
             $response = $response->__toArray();
             $data['success'] = 'Shipment Cancelled...';
         } catch (Exception $ex) {
             $data['error'] = $ex->getMessage();
         }
     } else {
         $data['error'] = 'Access Denied...';
     }
     die(json_encode($data));
 }
コード例 #4
0
ファイル: shipment.php プロジェクト: easypost/easypost-php
<?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));
コード例 #5
0
// 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]);
$shipment->insure(array('amount' => 100));
echo $shipment->postage_label->label_url;
コード例 #6
0
              <div class="col-sm-12">
			  
			 
			  
			  
			  
			  
			  
			  
			  
			  <?php 
require_once 'includes/plugins/easypost-php-master/lib/easypost.php';
\EasyPost\EasyPost::setApiKey('kZvkSRX4nEqTN3ju6ybPmg');
$shipping_rate = $_POST['shipping_rate'];
$shipment_id = $_POST['shipment_id'];
$shipment = \EasyPost\Shipment::retrieve($shipment_id);
$shipment->buy(array('rate' => array('id' => $shipping_rate)));
$shipment->label(array('file_format' => 'pdf'));
?>
<div class="row">
<div class="col-xs-12 col-md-6">
 <p>Print your shipping label.</p>
<h2>Tracking Code</h2>
<p><?php 
echo $shipment->tracking_code;
?>
</p>
</br>
</br>
</br>
<a href="<?php 
コード例 #7
0
ファイル: scanforms.php プロジェクト: ghola/easypost-php
<?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);
コード例 #8
0
ファイル: readme.php プロジェクト: ghola/easypost-php
<?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;
コード例 #9
0
ファイル: shipping-rates.php プロジェクト: antbusk/buy4square
            <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;
コード例 #10
0
 /**
  * get label for shipment
  *
  * @param string $shipmentId
  * @return string
  * @throws \browner12\shipping\ShippingException
  */
 public function label($shipmentId)
 {
     //try to retrieve the label
     try {
         //retrieve shipment
         $shipment = Shipment::retrieve($shipmentId);
         //retrieve label
         $label = $shipment->label(['file_format' => 'zpl']);
         return $label->postage_label->label_url;
     } catch (EasyPostException $e) {
         //throw shipping exception
         throw new ShippingException('Unable to retrieve label.', 0, $e);
     }
 }
コード例 #11
0
 public function purchaseship($ship_data)
 {
     try {
         $shipment = \EasyPost\Shipment::retrieve($ship_data['shp_ep_ref']);
         $ship_array = $shipment->__toArray(true);
         if (empty($ship_array['tracking_code'])) {
             $lowest_rate = $shipment->lowest_rate();
             $response = $shipment->buy($lowest_rate);
             $response = $response->__toArray(true);
             $tracking_code = $response['tracking_code'];
             if (is_null($tracking_code)) {
                 $tracking_code = '';
             }
             $tracking_code = 'EZ1000000001';
             $label_url = $response['postage_label']['label_url'];
             if (is_null($label_url)) {
                 $label_url = '';
             }
             $ep_ref = $response['id'];
             $shipment->insure(array('amount' => 100));
         } else {
             //$tracking_code = $ship_array['tracking_code'];
             $tracking_code = 'EZ1000000001';
             $label_url = $ship_array['postage_label']['label_url'];
             $ep_ref = $ship_array['postage_label']['id'];
         }
         $carrier = 'DHLExpress';
         $tracker = \EasyPost\Tracker::create(array('tracking_code' => $tracking_code, 'carrier' => $carrier));
         $tracker = json_decode($tracker);
         if (isset($tracker->est_delivery_date)) {
             $est_date = $tracker->est_delivery_date;
         } else {
             $est_date = '';
         }
         $result = array('shp_trackingcode' => $tracking_code, 'shp_labelurl' => $label_url, 'shp_estdate' => $est_date, 'shp_ep_ref' => $ep_ref);
         return $result;
     } catch (Exception $ex) {
         return $ex->getMessage();
     }
 }
コード例 #12
0
            <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;
コード例 #13
0
 /**
  * @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;
 }
コード例 #14
0
 /**
  * @param string $shipmentExternalId
  * @param string $rateExternalId
  * @return ShipmentTracker
  */
 public function buy($shipmentExternalId, $rateExternalId)
 {
     $shipment = new EasyPost\Shipment($shipmentExternalId);
     $shipment->buy(['rate' => ['id' => $rateExternalId]]);
     return $this->getShipmentTrackerFromEasyPostShipment($shipment);
 }
コード例 #15
0
// 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;
コード例 #16
0
<?php

require_once "../lib/easypost.php";
\EasyPost\EasyPost::setApiKey('cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi');
$shipment = \EasyPost\Shipment::create_from_tracking_code(array("tracking_code" => "1Z0X89330378901784", "options" => array("residential_to_address" => 1)));
print_r($shipment->rates);