View Source ExCheckout.Package (ex_checkout v1.5.2)

Defines the struct for storing a Package, which is then passed along with an origin and destination address for shipping estimates. A description is optional, as it may or may not be used with various carriers.

For USPS, a package has a container string which can be one of the pre-defined USPS containers.

Do not pass a weight parameter. Instead, pass in a list of :items with a weight parameter on each of these. The weight on the package will be the sum of the weights of each of these. Same for :monetary_value.

:description can optionally be passed in. Otherwise, it will be generated by joining the descriptions of each of the items.

ExCheckout.Package.package(%{length: 8,
                          width: 8,
                          height: 8,
                          items: [
                            %{weight: 1, monetary_value: 100, description: "A"},
                            %{weight: 2, monetary_value: 200, description: "B"}
                          ]})

# => %Package{weight: 3, monetary_value: 300, description: "A, B", ...}

Link to this section Summary

Functions

Builds and returns a Package. Use this instead of directly initializing the struct.

Returns a map of predefined containers for use with USPS. These can be passed to package.container for fetching rates.

Returns a map of flat rate USPS containers, along with their string description and flat shipping rate (in cents).

Link to this section Types

@type t() :: %ExCheckout.Package{
  container: nil | atom() | String.t(),
  description: nil | String.t(),
  girth: nil | number(),
  height: number(),
  insurance: nil | number(),
  items: [ExCheckout.Item.t()],
  length: number(),
  monetary_value: number(),
  weight: number(),
  width: number()
}

Link to this section Functions

@spec new(map()) :: t()

Builds and returns a Package. Use this instead of directly initializing the struct.

@spec usps_containers() :: %{required(atom()) => String.t()}

Returns a map of predefined containers for use with USPS. These can be passed to package.container for fetching rates.

Link to this function

usps_flat_rate_containers()

View Source
@spec usps_flat_rate_containers() :: %{required(atom()) => flat_rate_container()}

Returns a map of flat rate USPS containers, along with their string description and flat shipping rate (in cents).