REFACTOR: Use the Prices API in place of Plans (#17)
Stripe has a newer API called Prices where you can create a price for any product and it can either be recurring or one-time. The easy part is existing Plans work with the Prices API by passing a Plan ID, but objects are returned in the slightly-different Prices API object format. This commit is a refactor to the new API to handle the data in its new form, and lays the foundation for a one time payment plan to be added to any subscriptions product.
This commit is contained in:
@@ -27,12 +27,17 @@ module DiscourseSubscriptions
|
||||
|
||||
def create
|
||||
begin
|
||||
plan = ::Stripe::Plan.retrieve(params[:plan])
|
||||
plan = ::Stripe::Price.retrieve(params[:plan])
|
||||
|
||||
if plan[:metadata] && plan[:metadata][:trial_period_days]
|
||||
trial_days = plan[:metadata][:trial_period_days]
|
||||
end
|
||||
|
||||
@subscription = ::Stripe::Subscription.create(
|
||||
customer: params[:customer],
|
||||
items: [ { plan: params[:plan] } ],
|
||||
items: [ { price: params[:plan] } ],
|
||||
metadata: metadata_user,
|
||||
trial_period_days: trial_days
|
||||
)
|
||||
|
||||
group = plan_group(plan)
|
||||
|
||||
Reference in New Issue
Block a user