How to implement multiple plan in rails with stripe checkout

foliwe83

I am trying to implement multiple plan subscription on a rails app with stripe.

My subscription controller

def new
    session = Stripe::Checkout::Session.create(
      payment_method_types: ['card'],
      client_reference_id: current_user.id,
      customer_email: current_user.email,
      subscription_data: {
        items: [{
          plan: 'beginner'
        }]
      },
      success_url: 'http://localhost:3000/',
      cancel_url: 'http://localhost:3000/'
    )
    @session_id = session.id
  end

My Routes

....
resources :subscriptions, only: :new
....

My subscription button is like

<%= link_to 'Subscribe to Beginner', new_subscription_path,  %>
<%= link_to 'Subscribe to Pro', #TODO,  %>

With this setup, I can subscribe to the beginner plan with no issue.

My question is how to add a pro plan to this setup. What will the routes look like?

I have all the plans created in my stripe dashboard. I have checked the docs but it is not clear for me.

I have seen you can pass params in the link like so

<%= link_to "subscribe", some_path(:params[:value]) %>

How can I achieve that kind of URL?

And after all, I want to have a method on the user model to check if the user is subscribed to the beginner or pro

Thanks

tywhang

Looks like you're asking about "query parameters".

You can add params to the URL

<%= link_to 'Subscribe to Beginner', new_subscription_path(plan: :beginner),  %>
<%= link_to 'Subscribe to Pro', new_subscription_path(plan: :pro),  %>

new_subscription_path(plan: :beginner) will evaluate to subscription/new?plan=beginner

Then you can access this in the model via params.

  def new
    plan_type = params[:plan]

    session = Stripe::Checkout::Session.create(
      payment_method_types: ['card'],
      client_reference_id: current_user.id,
      customer_email: current_user.email,
      subscription_data: {
        items: [{
          plan: plan_type
        }]
      },
      success_url: 'http://localhost:3000/',
      cancel_url: 'http://localhost:3000/'
    )
    @session_id = session.id
  end

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Confirming how to use Stripe.net Customer on a plan

From Dev

How do I change the language of the checkout form in Stripe?

From Dev

Rails3: How to implement multiple checkboxes in a form?

From Dev

How can I modify Stripe Checkout to instead send an AJAX request?

From Dev

how to pass email address from checkout form to charge page with Stripe

From Dev

How to write integration tests for Stripe checkout on Rails?

From Dev

Rails 4: how to implement a column with multiple elements

From Dev

Looking to Submit Rails Form Only After Successful Stripe Checkout Payment

From Dev

Adding Parameters with Stripe Checkout

From Dev

stripe checkout, custom integration: how to detect abort?

From Dev

Rails with Stripe Checkout: How can i seed my db with sample charges and use stripe checkout to generate tokens for each charge?

From Dev

How to add custom fields to popup form of Stripe Checkout

From Dev

How should I implement Guava cache when I plan to cache multiple values efficiently?

From Dev

Is Stripe Checkout broken?

From Dev

Stripe Checkout - PHP

From Dev

How do I know what plan the user chose with Stripe's Checkout.js?

From Dev

How to implement Trumbowyg in Rails

From Dev

Stripe checkout is not working

From Dev

Stripe Checkout charging a card

From Dev

Completely stuck with Stripe Checkout

From Dev

Display description for a plan on Stripe checkout page

From Dev

How do I develop this action creator for stripe checkout payments?

From Dev

Rails3: How to implement multiple checkboxes in a form?

From Dev

unable to update role and stripe plan rails

From Dev

how to pass email address from checkout form to charge page with Stripe

From Dev

How to write integration tests for Stripe checkout on Rails?

From Dev

How can I implement this plan in android studio?

From Dev

Stripe Checkout and Customer Creation

From Dev

How to disable default payment method (Credit Card) in Stripe Checkout

Related Related

  1. 1

    Confirming how to use Stripe.net Customer on a plan

  2. 2

    How do I change the language of the checkout form in Stripe?

  3. 3

    Rails3: How to implement multiple checkboxes in a form?

  4. 4

    How can I modify Stripe Checkout to instead send an AJAX request?

  5. 5

    how to pass email address from checkout form to charge page with Stripe

  6. 6

    How to write integration tests for Stripe checkout on Rails?

  7. 7

    Rails 4: how to implement a column with multiple elements

  8. 8

    Looking to Submit Rails Form Only After Successful Stripe Checkout Payment

  9. 9

    Adding Parameters with Stripe Checkout

  10. 10

    stripe checkout, custom integration: how to detect abort?

  11. 11

    Rails with Stripe Checkout: How can i seed my db with sample charges and use stripe checkout to generate tokens for each charge?

  12. 12

    How to add custom fields to popup form of Stripe Checkout

  13. 13

    How should I implement Guava cache when I plan to cache multiple values efficiently?

  14. 14

    Is Stripe Checkout broken?

  15. 15

    Stripe Checkout - PHP

  16. 16

    How do I know what plan the user chose with Stripe's Checkout.js?

  17. 17

    How to implement Trumbowyg in Rails

  18. 18

    Stripe checkout is not working

  19. 19

    Stripe Checkout charging a card

  20. 20

    Completely stuck with Stripe Checkout

  21. 21

    Display description for a plan on Stripe checkout page

  22. 22

    How do I develop this action creator for stripe checkout payments?

  23. 23

    Rails3: How to implement multiple checkboxes in a form?

  24. 24

    unable to update role and stripe plan rails

  25. 25

    how to pass email address from checkout form to charge page with Stripe

  26. 26

    How to write integration tests for Stripe checkout on Rails?

  27. 27

    How can I implement this plan in android studio?

  28. 28

    Stripe Checkout and Customer Creation

  29. 29

    How to disable default payment method (Credit Card) in Stripe Checkout

HotTag

Archive