Reputation: 719
I'm following the Stripe Rails Checkout Guide, except I'm trying to use it for subscriptions instead of a one-time payment.
my code looks like:
def create
token = params[:stripeToken]
customer = Stripe::Customer.create(
:card => token,
:plan => "year",
:email => current_user.email
)
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to charges_path
end
I have a plan existing, but when I enter in my card details, I don't get any response, and on Stripe it says there are no subscribers?
Upvotes: 0
Views: 51
Reputation: 1021
This definitely sounds like a Javascript problem, not a Rails problem. Take a look at your JS error console. Are there problems there? In Chrome and Firefox, check the "preserve log" checkbox to keep the logs around for the next page load so you can see what's happening. If you're using Turbolinks I would suggest disabling it until you can figure out what's happening.
Upvotes: 0
Reputation: 16506
Follow the article here for testing (incase you have not already)
https://stripe.com/docs/testing
Since you have not setup any webhook, your stipe dashboard would not be able to show if any new customer is created or not. In that case easiest way to validate is by inspecting the customer
object created.
Also as you plan for subscription, its important you keep track of customer id's. Simplest way to do this is add a new attribute(column) strip_id
to your users model(table). Then do something like:
if @user.stripe_id
customer = Stripe::Customer.retrieve(@user.stripe_id)
else
customer = Stripe::Customer.create(
:description => "User: #{@user.id}",
:email => @user.email,
:card => params[:stripe_token]
)
@user.update_attributes!(:stripe_id => customer.id)
end
If customer
object is created, this validates your code is running fine.
For getting confirmation from stripe regarding this, you will need to create a webhook and a controller for stripe. You cannot provide your http://localhost:3000/stripe
url as webhook. For that you need some additional tool like ngrok. I have written an article for that, you can refer to it here: https://codefiddle.wordpress.com/2014/06/17/localhost-to-internet/
Its better to try this (creating customer) out in rails console
first. If the customer object is created that validates all it good.
Upvotes: 1