Using Stripe with Devise for Ruby on Rails Subscri

2020-07-26 11:38发布

I am attempting to integrate Stripe's recurring payment system with Devise, using Ryan's recent Railscast as a guide ( http://railscasts.com/episodes/288-billing-with-stripe?view=asciicast ).

Instead of a Subscription model, I want to use my existing User model. I got past adding the Stripe keys, adding the form fields to /users/sign_up, adding the js and meta tag in the head, and I have created a users.js.coffee file in assets.

When I submit the form, I get no error, and no type of feedback that anything was submitted to Stripe. Logs show nothing at all from the subscription side of things. Instead, I just get a user created with Devise.

Any idea what step I'm missing or which file I've named incorrectly?

Thanks, --Mark

1条回答
Fickle 薄情
2楼-- · 2020-07-26 11:48

My bet is that you're not loading jQuery. The subscriptions.js(or .coffee) requires jQuery, but Ryan assumes that knowledge is implicit in his rails cast.

Edit: Having just solved the same problem myself I had the simple issue of not replacing #new_subscription in subscriptions.js with the html form name attribute. So for example if your html looks like:

<form accept-charset="UTF-8" action="/plans" class="new_plan" id="new_plan" method="post">

Then you would use #new_plan instead of #new_subscription.

If you don't use the proper form name jQuery won't 'hijack'(trigger the callback on) the form submit button to send data to stripe before letting rails process the form.

Hope this helps!

查看更多
登录 后发表回答