1
0
mirror of synced 2026-08-31 19:35:40 +00:00

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:
Justin DiRose
2020-07-15 08:44:40 -05:00
committed by GitHub
parent 8bcb7aa93c
commit c9ff55b46a
22 changed files with 128 additions and 136 deletions
@@ -17,7 +17,7 @@ module DiscourseSubscriptions
subscriptions = []
if subscription_ids
plans = ::Stripe::Plan.list(
plans = ::Stripe::Price.list(
expand: ['data.product'],
limit: 100
)
@@ -34,8 +34,9 @@ module DiscourseSubscriptions
subscriptions = subscriptions.select { |sub| subscription_ids.include?(sub[:id]) }
subscriptions.map! do |subscription|
plan = plans[:data].find { |p| p[:id] == subscription[:plan][:id] }
subscription.to_h.merge(product: plan[:product].to_h.slice(:id, :name))
plan = plans[:data].find { |p| p[:id] == subscription[:items][:data][0][:price][:id] }
subscription.to_h.except!(:plan)
subscription.to_h.merge(plan: plan, product: plan[:product].to_h.slice(:id, :name))
end
end