1
0
mirror of synced 2026-08-05 14:47:03 +00:00

plans and products

This commit is contained in:
Rimian Perkins
2019-10-17 12:07:06 +11:00
parent 01b78b31df
commit e2b915b905
13 changed files with 107 additions and 40 deletions
+24 -7
View File
@@ -7,14 +7,31 @@ module DiscoursePatrons
before_action :set_api_key
def create
subscription = ::Stripe::Subscription.create(
customer: params[:customer],
items: [
{ plan: params[:plan] },
]
)
begin
subscription = ::Stripe::Subscription.create(
customer: params[:customer],
items: [
{ plan: params[:plan] },
]
)
render_json_dump subscription
if subscription_ok(subscription)
# TODO: check group credentials
group = Group.find_by_name('group-123')
group.add(current_user)
end
render_json_dump subscription
rescue ::Stripe::InvalidRequestError => e
return render_json_error e.message
end
end
private
def subscription_ok(subscription)
['active', 'trialing'].include?(subscription[:status])
end
end
end