Paddle.Subscription (paddlex v0.1.0) View Source
This module corresponds to the subscription/users
endpoint in the Paddle API,
I've changed it to Subscription as I found it to be more accurate.
Link to this section Summary
Functions
Cancel the specified user’s subscription
List all users subscribed to any of your subscription plans
Update the quantity, price, and/or plan of a user’s subscription
Link to this section Types
Specs
t() :: %{ subscription_id: integer(), plan_id: integer(), user_id: integer(), user_email: String.t(), marketing_consent: boolean(), state: String.t(), signup_date: String.t(), last_payment: map(), next_payment: map() | nil, update_url: String.t(), cancel_url: String.t(), paused_at: String.t() | nil, paused_from: String.t() | nil, payment_information: map() }
Link to this section Functions
Specs
cancel(integer()) :: {:ok, nil}
Cancel the specified user’s subscription
Examples
Paddle.Subscriber.cancel(12345)
{:ok, nil}
Specs
list(keyword()) :: {:ok, [t()]} | {:error, Paddle.Error.t()}
List all users subscribed to any of your subscription plans
Optionally also accepts plan_id
, subscription_id
, and state
to filter the response to just users of a specific plan, a user subscription, or the status of the user’s subscription.
If not filtering by the subscription_id
, it is strongly recommend to utilize results_per_page
and page
to limit the amount of results returned within each API call. This ensures that the response time remains quick and consistent as the amount of user subscriptions build up over time.
Examples
Paddle.Subscriber.list()
{:ok, [
%Paddle.Subscriber{
subscription_id: 502198,
plan_id: 496199,
user_id: 285846,
user_email: "name@example.com",
marketing_consent: true,
update_url: "https://checkout.paddle.com/subscription/update?user=12345&subscription=87654321&hash=eyJpdiI6Ik1RTE1nbHpXQmtJUG5...",
cancel_url: "https://checkout.paddle.com/subscription/cancel?user=12345&subscription=87654321&hash=eyJpdiI6IlU0Nk5cL1JZeHQyTXd...",
state: "active",
signup_date: ~U"2015-10-06 09:44:23Z",
last_payment: %{
"amount" => 5,
"currency" => "USD",
"date" => ~D"2015-10-06"
},
payment_information: %{
"payment_method" => "card",
"card_type" => "visa",
"last_four_digits" => "1111",
"expiry_date" => "02/2020"
},
next_payment: %{
"amount" => 10,
"currency" => "USD",
"date" => ~D"2015-11-06"
}
}
]}
Specs
update(integer(), params) :: {:ok, map()} | {:error, Paddle.Error.t()} when params: %{ :quantity => integer(), optional(:currency) => String.t(), optional(:recurring_price) => number(), optional(:bill_immediately) => boolean(), optional(:plan_id) => integer(), optional(:prorate) => boolean(), optional(:keep_modifiers) => boolean(), optional(:passthrough) => String.t(), optional(:pause) => boolean() }
Update the quantity, price, and/or plan of a user’s subscription
Usage Notes
- Subscribers on non-quantity plans can move to quantity plans but not the inverse.
- Subscribers must be billed immediately when moving to a plan with a different billing interval.
- Subscribers cannot be moved to a plan where the current currency is not enabled.
- Subscribers cannot be moved to a different plan while on a trialing state.
- Subscribers in a paused state cannot be modified until they restart their subscription.
- Subscribers in a past due state can only have the passthrough or pause field updated.
- The currency of an existing subscription cannot be changed.
- Recurring coupons (if present) will be removed when this API is used.
Examples
params = %{
bill_immediately: true,
plan_id: 525123,
prorate: true,
keep_modifiers: true,
passthrough: true,
pause: true
}
Paddle.Subscriber.update(12345, params)
{:ok, %{
subscription_id: 12345,
user_id: 425123,
plan_id: 525123,
next_payment: %{
"amount" => 144.06,
"currency" => "GBP",
"date" => ~D"2018-02-15",
}
}}