View Source ExPorterSDK.Order (ExPorterSDK v0.1.0)

Order operations dispatcher based on environment.

This module provides functions to create, track, and cancel orders in the Porter API. It dynamically dispatches to the appropriate implementation based on the application configuration.

Functions

  • create/1: Create a new order.
  • track/1: Retrieve the status of an existing order.
  • cancel/2: Cancel an existing order.

Example Usage

iex> ExPorterSDK.Order.create(%{pickup_details: ..., drop_details: ..., delivery_instructions: ...})
{:ok, order_response}

iex> ExPorterSDK.Order.track("order_id")
{:ok, order_status}

iex> ExPorterSDK.Order.cancel("order_id", "Customer request")
{:ok, cancellation_response}

Summary

Functions

Cancel an order.

Create an order.

Track an order.

Functions

Cancel an order.

This function cancels an existing order based on its order ID.

Parameters

  • order_id: The unique identifier of the order to be canceled.
  • reason: A string specifying the reason for cancellation.

Returns

  • {:ok, cancellation_response}: On success, returns the cancellation response.
  • {:error, reason}: On failure, returns an error reason.

Example

iex> ExPorterSDK.Order.cancel("order_id")
{:ok, %{message: "Order canceled successfully"}}

Create an order.

This function takes a map of parameters required to create an order. It delegates the call to the appropriate implementation.

Parameters

  • params: A map containing the necessary details for the order including pickup_details, drop_details, and delivery_instructions.

Returns

  • {:ok, response}: On success, returns the response from the API.
  • {:error, reason}: On failure, returns an error reason.

Example

iex> ExPorterSDK.Order.create(%{pickup_details: ..., drop_details: ..., delivery_instructions: ...})
{:ok, %{order_id: "12345", status: "created"}}

Track an order.

This function retrieves the current status of a specific order.

Parameters

  • order_id: The unique identifier of the order to be tracked.

Returns

  • {:ok, order_status}: On success, returns the current status of the order.
  • {:error, reason}: On failure, returns an error reason.

Example

iex> ExPorterSDK.Order.track("order_id")
{:ok, %{status: "in_transit", estimated_delivery: "2023-10-20T10:00:00Z"}}