You are here

public function USPSShipmentInternational::buildPackage in Commerce USPS 8

Returns an initialized rate package object.

Return value

\USPS\RatePackage The rate package entity.

Overrides USPSShipmentBase::buildPackage

File

src/USPSShipmentInternational.php, line 18

Class

USPSShipmentInternational
Class that sets the shipment details needed for the USPS request.

Namespace

Drupal\commerce_usps

Code

public function buildPackage() {
  parent::buildPackage();

  // Object has to be created in exact order defined
  // by IntlRateV2 API.
  // See:  https://www.usps.com/business/web-tools-apis/rate-calculator-api.pdf
  $this
    ->setWeight();
  $this->uspsPackage
    ->setField('Machinable', 'True');
  $this->uspsPackage
    ->setField('MailType', 'Package');

  // Todo: Add shipment value for insurance.
  $this->uspsPackage
    ->setField('ValueOfContents', 0);
  $this
    ->setCountry();
  $this->uspsPackage
    ->setField('Container', 'RECTANGULAR');
  $this
    ->setDimensions();
  $this
    ->setOriginZip();
  $this
    ->setRateClass();
  return $this->uspsPackage;
}