retrieve() public static method

retrieve a shipment
public static retrieve ( string $id, string $apiKey = null ) : mixed
$id string
$apiKey string
return mixed
Exemplo n.º 1
0
 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));
 }
Exemplo n.º 2
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;
Exemplo n.º 3
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();
     }
 }
Exemplo n.º 4
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 
Exemplo n.º 5
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);
     }
 }