ExCorreios v1.1.4 ExCorreios View Source

This module provides a function to calculate shipping based on one or more services.

Link to this section Summary

Functions

Calculate shipping based on one or more services.

Finds an address by a postal code.

Link to this section Functions

Link to this function

calculate(services, package, params, opts \\ [])

View Source
calculate(
  [atom()],
  %ExCorreios.Calculator.Shipping.Package{
    diameter: term(),
    format: term(),
    height: term(),
    length: term(),
    weight: term(),
    width: term()
  },
  map(),
  [Keyword.t()]
) :: {:ok, [map()]} | {:error, atom()}

Calculate shipping based on one or more services.

Examples

iex> dimensions = [%{diameter: 40, width: 11.0, height: 2.0, length: 16.0, weight: 0.9}]
iex> package = ExCorreios.Shipping.Packages.Package.build(:package_box, dimensions)
iex> shipping_params = %{
  destination: "05724005",
  origin: "08720030",
  enterprise: "",
  password: "",
  receiving_alert: false,
  declared_value: 0,
  manually_entered: false
}
iex> ExCorreios.calculate([:pac, :sedex], package, shipping_params)
{:ok,
  [
    %{
      deadline: 5,
      declared_value: 0.0,
      error_code: "0",
      error_message: "",
      home_delivery: "S",
      manually_entered_value: 0.0,
      notes: "",
      receiving_alert_value: 0.0,
      response_status: "0",
      saturday_delivery: "N",
      service_code: "04510",
      value: 19.8,
      value_without_additionals: 19.8
    },
    %{
      deadline: 2,
      declared_value: 0.0,
      error_code: "0",
      error_message: "",
      home_delivery: "S",
      manually_entered_value: 0.0,
      notes: "",
      receiving_alert_value: 0.0,
      response_status: "0",
      saturday_delivery: "S",
      service_code: "04014",
      value: 21.2,
      value_without_additionals: 21.2
    }
  ]
}
Link to this function

find_address(postal_code, opts \\ [])

View Source
find_address(String.t(), keyword()) ::
  {:ok, ExCorreios.Address.t()} | {:error, atom()}

Finds an address by a postal code.

Examples

iex> ExCorreios.find_address("35588-000")
{:ok,
   %{
     city: "Arcos",
     complement: "",
     district: "",
     postal_code: "35588-000",
     state: "MG",
     street: ""
   }}

iex> ExCorreios.find_address("00000-000")
{:error, :invalid_postal_code}