EasyPost\Shipment::buy PHP Method

buy() public method

buy a shipment
public buy ( mixed $params = null )
$params mixed
    public function buy($params = null)
    {
        $requestor = new Requestor($this->_apiKey);
        $url = $this->instanceUrl() . '/buy';
        if (isset($params['id']) && (!isset($params['rate']) || !is_array($params['rate']))) {
            $clone = $params;
            unset($params);
            $params['rate'] = $clone;
        }
        list($response, $apiKey) = $requestor->request('post', $url, $params);
        $this->refreshFrom($response, $apiKey, true);
        return $this;
    }

Usage Example

コード例 #1
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);
 }