2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-12 20:03:43 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
|
|
|
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
2018-03-25 17:30:42 +00:00
|
|
|
require 'stripe'
|
|
|
|
require 'active_support/core_ext'
|
|
|
|
|
|
|
|
module ConstructBillingSubscription
|
2019-07-30 21:29:24 +00:00
|
|
|
def self.with_stripe(np, billing_plan)
|
|
|
|
raise ArgumentError, 'Billing plan not found' if billing_plan.nil?
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
customer = Stripe::Customer.retrieve np.active_card.stripe_customer_id
|
|
|
|
stripe_subscription = customer.subscriptions.create(
|
2019-11-05 19:38:36 +00:00
|
|
|
plan: billing_plan.stripe_plan_id
|
2019-07-30 21:29:24 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
billing_plan_id: billing_plan.id,
|
|
|
|
stripe_subscription_id: stripe_subscription.id,
|
|
|
|
status: stripe_subscription.status
|
|
|
|
}
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|