# 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.SubscriptionsAPI do @moduledoc """ API calls for all endpoints tagged `SubscriptionsAPI`. """ alias MollieAPI.Connection import MollieAPI.RequestBuilder @doc """ Cancel subscription Cancel an existing subscription. Canceling a subscription has no effect on the mandates of the customer. ### Parameters - `connection` (MollieAPI.Connection): Connection to server - `customer_id` (String.t): Provide the ID of the related customer. - `subscription_id` (String.t): Provide the ID of the related subscription. - `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, MollieAPI.Model.SubscriptionResponse.t}` on success - `{:error, Tesla.Env.t}` on failure """ @spec cancel_subscription(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, MollieAPI.Model.ErrorResponse.t} | {:ok, MollieAPI.Model.SubscriptionResponse.t} | {:error, Tesla.Env.t} def cancel_subscription(connection, customer_id, subscription_id, opts \\ []) do optional_params = %{ :"idempotency-key" => :headers, :body => :body } request = %{} |> method(:delete) |> url("/v2/customers/#{customer_id}/subscriptions/#{subscription_id}") |> add_optional_params(optional_params, opts) |> Enum.into([]) connection |> Connection.request(request) |> evaluate_response([ {200, MollieAPI.Model.SubscriptionResponse}, {404, MollieAPI.Model.ErrorResponse} ]) end @doc """ Create subscription With subscriptions, you can schedule recurring payments to take place at regular intervals. For example, by simply specifying an `amount` and an `interval`, you can create an endless subscription to charge a monthly fee, until you cancel the subscription. Or, you could use the times parameter to only charge a limited number of times, for example to split a big transaction in multiple parts. A few example usages: `amount[currency]=\"EUR\"` `amount[value]=\"5.00\"` `interval=\"2 weeks\"` Your customer will be charged €5 once every two weeks. `amount[currency]=\"EUR\"` `amount[value]=\"20.00\"` `interval=\"1 day\" times=5` Your customer will be charged €20 every day, for five consecutive days. `amount[currency]=\"EUR\"` `amount[value]=\"10.00\"` `interval=\"1 month\"` `startDate=\"2018-04-30\"` Your customer will be charged €10 on the last day of each month, starting in April 2018. ### 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` (SubscriptionRequest): ### Returns - `{:ok, MollieAPI.Model.SubscriptionResponse.t}` on success - `{:error, Tesla.Env.t}` on failure """ @spec create_subscription(Tesla.Env.client, String.t, keyword()) :: {:ok, MollieAPI.Model.ErrorResponse.t} | {:ok, MollieAPI.Model.SubscriptionResponse.t} | {:error, Tesla.Env.t} def create_subscription(connection, customer_id, opts \\ []) do optional_params = %{ :"idempotency-key" => :headers, :body => :body } request = %{} |> method(:post) |> url("/v2/customers/#{customer_id}/subscriptions") |> add_optional_params(optional_params, opts) |> ensure_body() |> Enum.into([]) connection |> Connection.request(request) |> evaluate_response([ {201, MollieAPI.Model.SubscriptionResponse}, {404, MollieAPI.Model.ErrorResponse} ]) end @doc """ Get subscription Retrieve a single subscription by its ID and the ID of its parent customer. ### Parameters - `connection` (MollieAPI.Connection): Connection to server - `customer_id` (String.t): Provide the ID of the related customer. - `subscription_id` (String.t): Provide the ID of the related subscription. - `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.SubscriptionResponse.t}` on success - `{:error, Tesla.Env.t}` on failure """ @spec get_subscription(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, MollieAPI.Model.ErrorResponse.t} | {:ok, MollieAPI.Model.SubscriptionResponse.t} | {:error, Tesla.Env.t} def get_subscription(connection, customer_id, subscription_id, opts \\ []) do optional_params = %{ :testmode => :query, :"idempotency-key" => :headers } request = %{} |> method(:get) |> url("/v2/customers/#{customer_id}/subscriptions/#{subscription_id}") |> add_optional_params(optional_params, opts) |> Enum.into([]) connection |> Connection.request(request) |> evaluate_response([ {200, MollieAPI.Model.SubscriptionResponse}, {404, MollieAPI.Model.ErrorResponse} ]) end @doc """ List all subscriptions Retrieve all subscriptions initiated across all your 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. - `:profileId` (String.t): The identifier referring to the [profile](get-profile) you wish to retrieve subscriptions for. Most API credentials are linked to a single profile. In these cases the `profileId` is already implied. To retrieve all subscriptions across the organization, use an organization-level API credential and omit the `profileId` parameter. - `: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.ListAllSubscriptions200Response.t}` on success - `{:error, Tesla.Env.t}` on failure """ @spec list_all_subscriptions(Tesla.Env.client, keyword()) :: {:ok, MollieAPI.Model.ErrorResponse.t} | {:ok, MollieAPI.Model.ListAllSubscriptions200Response.t} | {:error, Tesla.Env.t} def list_all_subscriptions(connection, opts \\ []) do optional_params = %{ :from => :query, :limit => :query, :profileId => :query, :testmode => :query, :"idempotency-key" => :headers } request = %{} |> method(:get) |> url("/v2/subscriptions") |> add_optional_params(optional_params, opts) |> Enum.into([]) connection |> Connection.request(request) |> evaluate_response([ {200, MollieAPI.Model.ListAllSubscriptions200Response}, {400, MollieAPI.Model.ErrorResponse}, {404, MollieAPI.Model.ErrorResponse} ]) end @doc """ List subscription payments Retrieve all payments of a specific subscription. The results are paginated. ### Parameters - `connection` (MollieAPI.Connection): Connection to server - `customer_id` (String.t): Provide the ID of the related customer. - `subscription_id` (String.t): Provide the ID of the related subscription. - `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_subscription_payments(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, MollieAPI.Model.ListPayments200Response.t} | {:ok, MollieAPI.Model.ErrorResponse.t} | {:error, Tesla.Env.t} def list_subscription_payments(connection, customer_id, subscription_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}/subscriptions/#{subscription_id}/payments") |> add_optional_params(optional_params, opts) |> Enum.into([]) connection |> Connection.request(request) |> evaluate_response([ {200, MollieAPI.Model.ListPayments200Response}, {400, MollieAPI.Model.ErrorResponse} ]) end @doc """ List customer subscriptions Retrieve all subscriptions of a customer. The results are paginated. ### 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. - `: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.ListSubscriptions200Response.t}` on success - `{:error, Tesla.Env.t}` on failure """ @spec list_subscriptions(Tesla.Env.client, String.t, keyword()) :: {:ok, MollieAPI.Model.ErrorResponse.t} | {:ok, MollieAPI.Model.ListSubscriptions200Response.t} | {:error, Tesla.Env.t} def list_subscriptions(connection, customer_id, opts \\ []) do optional_params = %{ :from => :query, :limit => :query, :sort => :query, :testmode => :query, :"idempotency-key" => :headers } request = %{} |> method(:get) |> url("/v2/customers/#{customer_id}/subscriptions") |> add_optional_params(optional_params, opts) |> Enum.into([]) connection |> Connection.request(request) |> evaluate_response([ {200, MollieAPI.Model.ListSubscriptions200Response}, {400, MollieAPI.Model.ErrorResponse}, {404, MollieAPI.Model.ErrorResponse} ]) end @doc """ Update subscription Update an existing subscription. Canceled subscriptions cannot be updated. For an in-depth explanation of each parameter, refer to the [Create subscription](create-subscription) endpoint. ### Parameters - `connection` (MollieAPI.Connection): Connection to server - `customer_id` (String.t): Provide the ID of the related customer. - `subscription_id` (String.t): Provide the ID of the related subscription. - `opts` (keyword): Optional parameters - `:"idempotency-key"` (String.t): A unique key to ensure idempotent requests. This key should be a UUID v4 string. - `:body` (UpdateSubscriptionRequest): ### Returns - `{:ok, MollieAPI.Model.SubscriptionResponse.t}` on success - `{:error, Tesla.Env.t}` on failure """ @spec update_subscription(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, MollieAPI.Model.ErrorResponse.t} | {:ok, MollieAPI.Model.SubscriptionResponse.t} | {:error, Tesla.Env.t} def update_subscription(connection, customer_id, subscription_id, opts \\ []) do optional_params = %{ :"idempotency-key" => :headers, :body => :body } request = %{} |> method(:patch) |> url("/v2/customers/#{customer_id}/subscriptions/#{subscription_id}") |> add_optional_params(optional_params, opts) |> ensure_body() |> Enum.into([]) connection |> Connection.request(request) |> evaluate_response([ {200, MollieAPI.Model.SubscriptionResponse}, {404, MollieAPI.Model.ErrorResponse} ]) end end