Current section

Files

Jump to
mollie_api lib mollie_api api customers_api.ex
Raw

lib/mollie_api/api/customers_api.ex

# NOTE: This file is auto generated by OpenAPI Generator 7.17.0 (https://openapi-generator.tech).
# Do not edit this file manually.
defmodule MollieAPI.Api.CustomersAPI do
@moduledoc """
API calls for all endpoints tagged `CustomersAPI`.
"""
alias MollieAPI.Connection
import MollieAPI.RequestBuilder
@doc """
Create customer
Creates a simple minimal representation of a customer. Payments, recurring mandates, and subscriptions can be linked to this customer object, which simplifies management of recurring payments. Once registered, customers will also appear in your Mollie dashboard.
### Parameters
- `connection` (MollieAPI.Connection): Connection to server
- `opts` (keyword): Optional parameters
- `:"idempotency-key"` (String.t): A unique key to ensure idempotent requests. This key should be a UUID v4 string.
- `:body` (EntityCustomer):
### Returns
- `{:ok, MollieAPI.Model.CustomerResponse.t}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec create_customer(Tesla.Env.client, keyword()) :: {:ok, MollieAPI.Model.ErrorResponse.t} | {:ok, MollieAPI.Model.CustomerResponse.t} | {:error, Tesla.Env.t}
def create_customer(connection, opts \\ []) do
optional_params = %{
:"idempotency-key" => :headers,
:body => :body
}
request =
%{}
|> method(:post)
|> url("/v2/customers")
|> add_optional_params(optional_params, opts)
|> ensure_body()
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{201, MollieAPI.Model.CustomerResponse},
{404, MollieAPI.Model.ErrorResponse},
{429, MollieAPI.Model.ErrorResponse}
])
end
@doc """
Create customer payment
Creates a payment for the customer. Linking customers to payments enables you to: * Keep track of payment preferences for your customers * Allow your customers to charge a previously used credit card with a single click in our hosted checkout * Improve payment insights in the Mollie dashboard * Use recurring payments This endpoint is effectively an alias of the [Create payment endpoint](create-payment) with the `customerId` parameter predefined.
### Parameters
- `connection` (MollieAPI.Connection): Connection to server
- `customer_id` (String.t): Provide the ID of the related customer.
- `opts` (keyword): Optional parameters
- `:"idempotency-key"` (String.t): A unique key to ensure idempotent requests. This key should be a UUID v4 string.
- `:body` (PaymentRequest):
### Returns
- `{:ok, MollieAPI.Model.PaymentResponse.t}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec create_customer_payment(Tesla.Env.client, String.t, keyword()) :: {:ok, MollieAPI.Model.ErrorResponse.t} | {:ok, MollieAPI.Model.PaymentResponse.t} | {:error, Tesla.Env.t}
def create_customer_payment(connection, customer_id, opts \\ []) do
optional_params = %{
:"idempotency-key" => :headers,
:body => :body
}
request =
%{}
|> method(:post)
|> url("/v2/customers/#{customer_id}/payments")
|> add_optional_params(optional_params, opts)
|> ensure_body()
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{201, MollieAPI.Model.PaymentResponse},
{422, MollieAPI.Model.ErrorResponse},
{429, MollieAPI.Model.ErrorResponse},
{503, MollieAPI.Model.ErrorResponse}
])
end
@doc """
Delete customer
Delete a customer. All mandates and subscriptions created for this customer will be canceled as well.
### Parameters
- `connection` (MollieAPI.Connection): Connection to server
- `customer_id` (String.t): Provide the ID of the related customer.
- `opts` (keyword): Optional parameters
- `:"idempotency-key"` (String.t): A unique key to ensure idempotent requests. This key should be a UUID v4 string.
- `:body` (DeletePaymentLinkRequest):
### Returns
- `{:ok, nil}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec delete_customer(Tesla.Env.client, String.t, keyword()) :: {:ok, nil} | {:ok, MollieAPI.Model.ErrorResponse.t} | {:error, Tesla.Env.t}
def delete_customer(connection, customer_id, opts \\ []) do
optional_params = %{
:"idempotency-key" => :headers,
:body => :body
}
request =
%{}
|> method(:delete)
|> url("/v2/customers/#{customer_id}")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{204, false},
{404, MollieAPI.Model.ErrorResponse},
{429, MollieAPI.Model.ErrorResponse}
])
end
@doc """
Get customer
Retrieve a single customer by its ID.
### Parameters
- `connection` (MollieAPI.Connection): Connection to server
- `customer_id` (String.t): Provide the ID of the related customer.
- `opts` (keyword): Optional parameters
- `:testmode` (boolean()): Most API credentials are specifically created for either live mode or test mode. In those cases the `testmode` query parameter must not be sent. For organization-level credentials such as OAuth access tokens, you can enable test mode by setting the `testmode` query parameter to `true`. Test entities cannot be retrieved when the endpoint is set to live mode, and vice versa.
- `:"idempotency-key"` (String.t): A unique key to ensure idempotent requests. This key should be a UUID v4 string.
### Returns
- `{:ok, MollieAPI.Model.CustomerResponse.t}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec get_customer(Tesla.Env.client, String.t, keyword()) :: {:ok, MollieAPI.Model.ErrorResponse.t} | {:ok, MollieAPI.Model.CustomerResponse.t} | {:error, Tesla.Env.t}
def get_customer(connection, customer_id, opts \\ []) do
optional_params = %{
:testmode => :query,
:"idempotency-key" => :headers
}
request =
%{}
|> method(:get)
|> url("/v2/customers/#{customer_id}")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, MollieAPI.Model.CustomerResponse},
{404, MollieAPI.Model.ErrorResponse},
{429, MollieAPI.Model.ErrorResponse}
])
end
@doc """
List customer payments
Retrieve all payments linked to the customer.
### Parameters
- `connection` (MollieAPI.Connection): Connection to server
- `customer_id` (String.t): Provide the ID of the related customer.
- `opts` (keyword): Optional parameters
- `:from` (String.t): Provide an ID to start the result set from the item with the given ID and onwards. This allows you to paginate the result set.
- `:limit` (integer()): The maximum number of items to return. Defaults to 50 items.
- `:sort` (Sorting): Used for setting the direction of the result set. Defaults to descending order, meaning the results are ordered from newest to oldest.
- `:profileId` (String.t): The identifier referring to the [profile](get-profile) you wish to retrieve the resources for. Most API credentials are linked to a single profile. In these cases the `profileId` must not be sent. For organization-level credentials such as OAuth access tokens however, the `profileId` parameter is required.
- `:testmode` (boolean()): Most API credentials are specifically created for either live mode or test mode. In those cases the `testmode` query parameter must not be sent. For organization-level credentials such as OAuth access tokens, you can enable test mode by setting the `testmode` query parameter to `true`. Test entities cannot be retrieved when the endpoint is set to live mode, and vice versa.
- `:"idempotency-key"` (String.t): A unique key to ensure idempotent requests. This key should be a UUID v4 string.
### Returns
- `{:ok, MollieAPI.Model.ListPayments200Response.t}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec list_customer_payments(Tesla.Env.client, String.t, keyword()) :: {:ok, MollieAPI.Model.ListPayments200Response.t} | {:ok, MollieAPI.Model.ErrorResponse.t} | {:error, Tesla.Env.t}
def list_customer_payments(connection, customer_id, opts \\ []) do
optional_params = %{
:from => :query,
:limit => :query,
:sort => :query,
:profileId => :query,
:testmode => :query,
:"idempotency-key" => :headers
}
request =
%{}
|> method(:get)
|> url("/v2/customers/#{customer_id}/payments")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, MollieAPI.Model.ListPayments200Response},
{400, MollieAPI.Model.ErrorResponse},
{429, MollieAPI.Model.ErrorResponse}
])
end
@doc """
List customers
Retrieve a list of all customers. The results are paginated.
### Parameters
- `connection` (MollieAPI.Connection): Connection to server
- `opts` (keyword): Optional parameters
- `:from` (String.t): Provide an ID to start the result set from the item with the given ID and onwards. This allows you to paginate the result set.
- `:limit` (integer()): The maximum number of items to return. Defaults to 50 items.
- `:sort` (Sorting): Used for setting the direction of the result set. Defaults to descending order, meaning the results are ordered from newest to oldest.
- `:testmode` (boolean()): Most API credentials are specifically created for either live mode or test mode. In those cases the `testmode` query parameter must not be sent. For organization-level credentials such as OAuth access tokens, you can enable test mode by setting the `testmode` query parameter to `true`. Test entities cannot be retrieved when the endpoint is set to live mode, and vice versa.
- `:"idempotency-key"` (String.t): A unique key to ensure idempotent requests. This key should be a UUID v4 string.
### Returns
- `{:ok, MollieAPI.Model.ListCustomers200Response.t}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec list_customers(Tesla.Env.client, keyword()) :: {:ok, MollieAPI.Model.ErrorResponse.t} | {:ok, MollieAPI.Model.ListCustomers200Response.t} | {:error, Tesla.Env.t}
def list_customers(connection, opts \\ []) do
optional_params = %{
:from => :query,
:limit => :query,
:sort => :query,
:testmode => :query,
:"idempotency-key" => :headers
}
request =
%{}
|> method(:get)
|> url("/v2/customers")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, MollieAPI.Model.ListCustomers200Response},
{400, MollieAPI.Model.ErrorResponse},
{404, MollieAPI.Model.ErrorResponse},
{429, MollieAPI.Model.ErrorResponse}
])
end
@doc """
Update customer
Update an existing customer. For an in-depth explanation of each parameter, refer to the [Create customer](create-customer) endpoint.
### Parameters
- `connection` (MollieAPI.Connection): Connection to server
- `customer_id` (String.t): Provide the ID of the related customer.
- `opts` (keyword): Optional parameters
- `:"idempotency-key"` (String.t): A unique key to ensure idempotent requests. This key should be a UUID v4 string.
- `:body` (UpdateCustomerRequest):
### Returns
- `{:ok, MollieAPI.Model.CustomerResponse.t}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec update_customer(Tesla.Env.client, String.t, keyword()) :: {:ok, MollieAPI.Model.ErrorResponse.t} | {:ok, MollieAPI.Model.CustomerResponse.t} | {:error, Tesla.Env.t}
def update_customer(connection, customer_id, opts \\ []) do
optional_params = %{
:"idempotency-key" => :headers,
:body => :body
}
request =
%{}
|> method(:patch)
|> url("/v2/customers/#{customer_id}")
|> add_optional_params(optional_params, opts)
|> ensure_body()
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, MollieAPI.Model.CustomerResponse},
{404, MollieAPI.Model.ErrorResponse},
{429, MollieAPI.Model.ErrorResponse}
])
end
end