Overview

Namespaces

  • ShippoClient
    • Entity
    • Http
      • Request
        • Addresses
        • Parcels
        • Shipments
        • Transactions
      • Response
        • Exception

Classes

  • ShippoClient\Addresses
  • ShippoClient\Entity\Address
  • ShippoClient\Entity\AddressCollection
  • ShippoClient\Entity\EntityCollection
  • ShippoClient\Entity\Location
  • ShippoClient\Entity\ObjectInformation
  • ShippoClient\Entity\Parcel
  • ShippoClient\Entity\ParcelCollection
  • ShippoClient\Entity\Rate
  • ShippoClient\Entity\RateCollection
  • ShippoClient\Entity\Refund
  • ShippoClient\Entity\RefundCollection
  • ShippoClient\Entity\ServiceLevel
  • ShippoClient\Entity\Shipment
  • ShippoClient\Entity\ShipmentCollection
  • ShippoClient\Entity\TrackingHistory
  • ShippoClient\Entity\TrackingStatus
  • ShippoClient\Entity\Tracks
  • ShippoClient\Entity\Transaction
  • ShippoClient\Entity\TransactionCollection
  • ShippoClient\Entity\WebhookTracks
  • ShippoClient\Http\Request
  • ShippoClient\Http\Request\Addresses\CreateObject
  • ShippoClient\Http\Request\CommonParameter
  • ShippoClient\Http\Request\MockCollection
  • ShippoClient\Http\Request\Parcels\CreateObject
  • ShippoClient\Http\Request\Shipments\CreateObject
  • ShippoClient\Http\Request\Shipments\CreateObjectByNested
  • ShippoClient\Http\Request\Shipments\CreateReturnObject
  • ShippoClient\Http\Request\Transactions\CreateObject
  • ShippoClient\Http\Response\AddressList
  • ShippoClient\Http\Response\ListResponse
  • ShippoClient\Http\Response\ParcelList
  • ShippoClient\Http\Response\RateList
  • ShippoClient\Http\Response\RefundList
  • ShippoClient\Http\Response\ShipmentList
  • ShippoClient\Http\Response\TransactionList
  • ShippoClient\Parcels
  • ShippoClient\Rates
  • ShippoClient\Refunds
  • ShippoClient\Shipments
  • ShippoClient\ShippoClient
  • ShippoClient\Tracks
  • ShippoClient\Transactions

Exceptions

  • ShippoClient\Http\Response\Exception\BadResponseException
  • ShippoClient\Http\Response\Exception\ClientErrorException
  • ShippoClient\Http\Response\Exception\ServerErrorException
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: namespace ShippoClient\Http\Request\Parcels;
  4: 
  5: use ShippoClient\Http\Request\CommonParameter;
  6: use TurmericSpice\Container;
  7: use TurmericSpice\Container\InvalidAttributeException;
  8: use TurmericSpice\ReadWriteAttributes;
  9: 
 10: /**
 11:  * Parcel objects are used for creating Shipment, obtaining Rates and printing Labels,
 12:  * and thus are one of the fundamental building blocks of the Shippo API.
 13:  * Parcel are created with their basic dimensions and their weight.
 14:  */
 15: class CreateObject extends CommonParameter
 16: {
 17:     use ReadWriteAttributes {
 18:         toArray as public __toArray;
 19:     }
 20: 
 21:     /**
 22:      * First dimension of the Parcel.
 23:      * The length should always be the largest of the three dimensions length, width and height;
 24:      * our API will automatically order them if this is not the case.
 25:      * Up to six digits in front and four digits after the decimal separator are accepted.
 26:      *
 27:      * Required
 28:      *
 29:      * @return int
 30:      * @throws InvalidAttributeException
 31:      */
 32:     public function getLength()
 33:     {
 34:         return $this->attributes->mustHave('length')->asInteger();
 35:     }
 36: 
 37:     /**
 38:      * Second dimension of the Parcel.
 39:      * The width should always be the second largest of the three dimensions length, width and height;
 40:      * our API will automatically order them if this is not the case.
 41:      * Up to six digits in front and four digits after the decimal separator are accepted.
 42:      *
 43:      * Required
 44:      *
 45:      * @return int
 46:      * @throws InvalidAttributeException
 47:      */
 48:     public function getWidth()
 49:     {
 50:         return $this->attributes->mustHave('width')->asInteger();
 51:     }
 52: 
 53:     /**
 54:      * Third dimension of the parcel.
 55:      * The height should always be the smallest of the three dimensions length, width and height;
 56:      * our API will automatically order them if this is not the case.
 57:      * Up to six digits in front and four digits after the decimal separator are accepted.
 58:      *
 59:      * Required
 60:      *
 61:      * @return int
 62:      * @throws InvalidAttributeException
 63:      */
 64:     public function getHeight()
 65:     {
 66:         return $this->attributes->mustHave('height')->asInteger();
 67:     }
 68: 
 69:     /**
 70:      * The unit used for length, width and height.
 71:      *
 72:      * Required
 73:      *
 74:      * @return string
 75:      * @throws InvalidAttributeException
 76:      */
 77:     public function getDistanceUnit()
 78:     {
 79:         return $this->attributes->mustHave('distance_unit')->asString(function ($distanceUnit) {
 80:             return in_array($distanceUnit, ['cm', 'in', 'ft', 'mm', 'm', 'yd'], true);
 81:         });
 82:     }
 83: 
 84:     /**
 85:      * Weight of the parcel. Up to six digits in front and four digits after the decimal separator are accepted.
 86:      *
 87:      * Required
 88:      *
 89:      * @return int
 90:      * @throws InvalidAttributeException
 91:      */
 92:     public function getWeight()
 93:     {
 94:         return $this->attributes->mustHave('weight')->asInteger();
 95:     }
 96: 
 97:     /**
 98:      * The unit used for weight.
 99:      *
100:      * Required
101:      *
102:      * @return string
103:      * @throws InvalidAttributeException
104:      */
105:     public function getMassUnit()
106:     {
107:         return $this->attributes->mustHave('mass_unit')->asString(function ($massUnit) {
108:             return in_array($massUnit, ['g', 'oz', 'lb', 'kg'], true);
109:         });
110:     }
111: 
112:     /**
113:      * A parcel template is a predefined package used by one or multiple carriers.
114:      * See the table below for all available values and the corresponding tokens.
115:      * When a template is given, the parcel dimensions have to be sent, but will not be used for the Rate generation.
116:      * The dimensions below will instead be used. The parcel weight is not affected by the use of a template.
117:      *
118:      * Optional
119:      *
120:      * @return string
121:      */
122:     public function getTemplate()
123:     {
124:         return $this->attributes->mayHave('template')->asString();
125:     }
126: 
127:     public function toArray()
128:     {
129:         return array_filter($this->__toArray());
130:     }
131: }
132: 
API documentation generated by ApiGen