Braintree v0.7.0 Braintree.Subscription
Manage customer subscriptions to reocurring billing plans.
For additional reference see: https://developers.braintreepayments.com/reference/request/subscription/create/ruby
Summary
Functions
Cancel an existing subscription by subscription_id
. A cancelled subscription
cannot be reactivated, you would need to create a new one
Convert a map into a Subscription struct. Add_ons and transactions are converted to a list of structs as well
Create a subscription, or return an error response with after failed validation
Find an existing subscription by subscription_id
You can manually retry charging past due subscriptions
To update a subscription, use its ID along with new attributes. The same validations apply as when creating a subscription. Any attribute not passed will remain unchanged
Types
t :: %Braintree.Subscription{add_ons: [], balance: String.t, billing_day_of_month: String.t, billing_period_end_date: String.t, billing_period_start_date: String.t, created_at: String.t, current_billing_cycle: String.t, days_past_due: String.t, descriptor: String.t, discounts: [], failure_count: String.t, first_billing_date: String.t, id: String.t, merchant_account_id: String.t, never_expires: String.t, next_bill_amount: String.t, next_billing_date: String.t, next_billing_period_amount: String.t, number_of_billing_cycles: String.t, paid_through_date: String.t, payment_method_token: String.t, plan_id: String.t, price: String.t, status: String.t, status_history: [], transactions: [], trial_duration: String.t, trial_duration_unit: String.t, trial_period: String.t, updated_at: String.t}
Functions
Specs
cancel(String.t) ::
{:ok, t} |
{:error, Braintree.ErrorResponse.t}
Cancel an existing subscription by subscription_id
. A cancelled subscription
cannot be reactivated, you would need to create a new one.
Example
{:ok, subscription} = Subscription.cancel("123")
Convert a map into a Subscription struct. Add_ons and transactions are converted to a list of structs as well.
Example
subscripton = Braintree.Subscription.construct(%{"plan_id" => "business",
"status" => "Active"})
Specs
create(Map.t) ::
{:ok, t} |
{:error, Braintree.ErrorResponse.t}
Create a subscription, or return an error response with after failed validation.
Example
{:ok, sub} = Braintree.Subscription.create(%{payment_method_token: card.token, plan_id: "starter"})
Specs
find(String.t) ::
{:ok, t} |
{:error, Braintree.ErrorResponse.t}
Find an existing subscription by subscription_id
Example
{:ok, subscription} = Subscription.find("123")
Specs
retry_charge(String.t, String.t | nil) ::
{:ok, Braintree.Transaction.t} |
{:error, Braintree.ErrorResponse.t}
You can manually retry charging past due subscriptions.
By default, we will use the subscription balance when retrying the transaction. If you would like to use a different amount you can optionally specify the amount for the transaction.
A successful manual retry of a past due subscription will always reduce the balance of that subscription to $0, regardless of the amount of the retry.
Example
{:ok, transaction} = Braintree.Subscription.retry_charge(sub_id)
{:ok, transaction} = Braintree.Subscription.retry_charge(sub_id, "24.00")
Specs
update(binary, Map.t) ::
{:ok, t} |
{:error, Braintree.ErrorResponse.t}
To update a subscription, use its ID along with new attributes. The same validations apply as when creating a subscription. Any attribute not passed will remain unchanged.
Example
{:ok, subscription} = Braintree.Subscription.update("subscription_id", %{
plan_id: "new_plan_id"
})
subscription.plan_id # "new_plan_id"