1
0
mirror of synced 2026-08-05 06:36:55 +00:00

FEATURE: Allow one-time purchases on products (#18)

Building off the foundation of using the Prices API, this PR adds the ability to create a one-time purchase plan for any product, which then can add a user to the specified plan group.

Some things to be aware of:

    One-time purchases cannot have trials.
    One-time purchases use the Invoice API instead of Subscriptions. Invoices are created then charged immediately.
    Users should receive emails for these invoices directly from Stripe just like subscriptions.
This commit is contained in:
Justin DiRose
2020-07-22 11:06:34 -05:00
committed by GitHub
parent fcc90e4fcc
commit 587661fafb
31 changed files with 272 additions and 533 deletions
@@ -12,7 +12,6 @@ module DiscourseSubscriptions
plans = ::Stripe::Price.list(product_params)
render_json_dump plans.data
rescue ::Stripe::InvalidRequestError => e
render_json_error e.message
end
@@ -20,12 +19,9 @@ module DiscourseSubscriptions
def create
begin
plan = ::Stripe::Price.create(
price_object = {
nickname: params[:nickname],
unit_amount: params[:amount],
recurring: {
interval: params[:interval],
},
product: params[:product],
currency: params[:currency],
active: params[:active],
@@ -33,10 +29,17 @@ module DiscourseSubscriptions
group_name: params[:metadata][:group_name],
trial_period_days: params[:trial_period_days]
}
)
}
if params[:type] == 'recurring'
price_object[:recurring] = {
interval: params[:interval]
}
end
plan = ::Stripe::Price.create(price_object)
render_json_dump plan
rescue ::Stripe::InvalidRequestError => e
render_json_error e.message
end
@@ -74,7 +77,6 @@ module DiscourseSubscriptions
)
render_json_dump plan
rescue ::Stripe::InvalidRequestError => e
render_json_error e.message
end