@@ -9,10 +9,10 @@ def create
99 session = Stripe ::Checkout ::Session . create \
1010 customer : find_or_create_stripe_customer ,
1111 mode : "subscription" ,
12- line_items : [ { price : Plan . paid . stripe_price_id , quantity : 1 } ] ,
12+ line_items : [ { price : plan_param . stripe_price_id , quantity : 1 } ] ,
1313 success_url : account_subscription_url + "?session_id={CHECKOUT_SESSION_ID}" ,
1414 cancel_url : account_subscription_url ,
15- metadata : { account_id : Current . account . id , plan_key : Plan . paid . key } ,
15+ metadata : { account_id : Current . account . id , plan_key : plan_param . key } ,
1616 automatic_tax : { enabled : true } ,
1717 tax_id_collection : { enabled : true } ,
1818 billing_address_collection : "required" ,
@@ -22,6 +22,10 @@ def create
2222 end
2323
2424 private
25+ def plan_param
26+ @plan_param ||= Plan [ params [ :plan_key ] ] || Plan . paid
27+ end
28+
2529 def set_stripe_session
2630 @stripe_session = Stripe ::Checkout ::Session . retrieve ( params [ :session_id ] ) if params [ :session_id ]
2731 end
@@ -36,7 +40,7 @@ def find_stripe_customer
3640
3741 def create_stripe_customer
3842 Stripe ::Customer . create ( email : Current . user . identity . email_address , name : Current . account . name , metadata : { account_id : Current . account . id } ) . tap do |customer |
39- Current . account . create_subscription! ( stripe_customer_id : customer . id , plan_key : Plan . paid . key , status : "incomplete" )
43+ Current . account . create_subscription! ( stripe_customer_id : customer . id , plan_key : plan_param . key , status : "incomplete" )
4044 end
4145 end
4246end
0 commit comments