Paypal.Order (Paypal v0.2.0)

Copy Markdown View Source

The orders is the element that let us to charge an amount to the clients.

We have two ways to proceed, it's called the intent and depending on what you choose, it will let you charge the money instantly or hold the money until the process, product or service will be released.

  • capture is the intent that charges the money immediately. The flow is:

    1. Create the order using capture as the intent, see create/3.
    2. Use the URL inside of the response for approving the payment.
    3. Capture the money, see capture/1.
  • authorize is the intent that holds the money and lets you capture the funds later. The flow is:

    1. Create the order using authorize as the intent, see create/3.
    2. Use the URL inside of the response for approving the payment.
    3. Create the authorization, see authorize/1.
    4. Capture funds using the authorization, see Paypal.Payment.capture/1.

If you are interested in the authorization, check Paypal.Payment module for further information.

Official PayPal API Documentation: PayPal Orders API v2

Summary

Functions

Authorize payment for an order.

Capture payment for an order.

The kind of intents, for further information Paypal.Order.

Show order details by ID.

Statuses for the order. The order is following different states, we could illustrate it as a state diagram

Functions

authorize(id)

@spec authorize(String.t()) ::
  {:ok, Paypal.Order.Authorized.t()}
  | {:error, Paypal.Common.Error.t() | term()}

Authorize payment for an order.

Official documentation: Authorize Payment for Order

capture(id)

@spec capture(String.t()) ::
  {:ok, Paypal.Order.Info.t()} | {:error, Paypal.Common.Error.t() | term()}

Capture payment for an order.

Official documentation: Capture Payment for Order

create(intent, purchase_units, experience_context)

@spec create(
  :capture | :authorize,
  [Paypal.Order.PurchaseUnit.t() | map()],
  Paypal.Order.ExperienceContext.t() | map()
) :: {:ok, Paypal.Order.Info.t()} | {:error, Paypal.Common.Error.t() | term()}

Create an order.

Official documentation: Create Order

intents()

@spec intents() :: [capture: String.t(), authorize: String.t()]

The kind of intents, for further information Paypal.Order.

show(id)

@spec show(String.t()) ::
  {:ok, Paypal.Order.Info.t()} | {:error, Paypal.Common.Error.t() | term()}

Show order details by ID.

Official documentation: Show Order Details

statuses()

@spec statuses() :: [
  created: String.t(),
  saved: String.t(),
  approved: String.t(),
  voided: String.t(),
  completed: String.t(),
  payer_action_required: String.t()
]

Statuses for the order. The order is following different states, we could illustrate it as a state diagram:

stateDiagram-v2
    [*] --> CREATED
    CREATED --> PAYER_ACTION_REQUIRED
    PAYER_ACTION_REQUIRED --> APPROVED
    APPROVED --> SAVED
    SAVED --> APPROVED
    APPROVED --> VOIDED
    APPROVED --> COMPLETED
    VOIDED --> [*]
    COMPLETED --> [*]

As you can see, we start in CREATED state and we are moving until reach VOIDED or COMPLETED.