Current section

Files

Jump to
polarex lib polarex operations payments.ex
Raw

lib/polarex/operations/payments.ex

defmodule Polarex.Payments do
@moduledoc """
Provides API endpoints related to payments
"""
@default_client Polarex.Support.Client
@doc """
Get Payment
Get a payment by ID.
**Scopes**: `payments:read`
"""
@spec payments_get(String.t(), keyword) ::
{:ok, Polarex.CardPayment.t() | Polarex.GenericPayment.t()}
| {:error, Polarex.HTTPValidationError.t() | Polarex.ResourceNotFound.t()}
def payments_get(id, opts \\ []) do
client = opts[:client] || @default_client
client.request(%{
args: [id: id],
call: {Polarex.Payments, :payments_get},
url: "/v1/payments/#{id}",
method: :get,
response: [
{200, {:union, [{Polarex.CardPayment, :t}, {Polarex.GenericPayment, :t}]}},
{404, {Polarex.ResourceNotFound, :t}},
{422, {Polarex.HTTPValidationError, :t}}
],
opts: opts
})
end
@doc """
List Payments
List payments.
**Scopes**: `payments:read`
## Options
* `organization_id`: Filter by organization ID.
* `checkout_id`: Filter by checkout ID.
* `order_id`: Filter by order ID.
* `status`: Filter by payment status.
* `method`: Filter by payment method.
* `customer_email`: Filter by customer email.
* `page`: Page number, defaults to 1.
* `limit`: Size of a page, defaults to 10. Maximum is 100.
* `sorting`: Sorting criterion. Several criteria can be used simultaneously and will be applied in order. Add a minus sign `-` before the criteria name to sort by descending order.
"""
@spec payments_list(keyword) ::
{:ok, Polarex.ListResource.t()} | {:error, Polarex.HTTPValidationError.t()}
def payments_list(opts \\ []) do
client = opts[:client] || @default_client
query =
Keyword.take(opts, [
:checkout_id,
:customer_email,
:limit,
:method,
:order_id,
:organization_id,
:page,
:sorting,
:status
])
client.request(%{
args: [],
call: {Polarex.Payments, :payments_list},
url: "/v1/payments/",
method: :get,
query: query,
response: [{200, {Polarex.ListResource, :t}}, {422, {Polarex.HTTPValidationError, :t}}],
opts: opts
})
end
end