Stripe: cannot charge a customer who does not have an active card
I am trying to create a client and instruct that client to use Rails and Stripe. The client is being created in Stripe, but I keep getting an error Cannot charge a customer that has no active card
when trying to make a charge.
I'm following the stripe instructions as a Rails newbie so I'm not sure where to go from here. Any help would be greatly appreciated.
Rails code:
def process_payment
customer = Stripe::Customer.create email: email,
card: card_token
Stripe::Charge.create customer: customer.id,
amount: level.price*100,
description: level.name,
card: card_token,
currency: 'usd'
end
def create
@registration = Registration.new registration_params.merge(email: stripe_params["stripeEmail"],
card_token: stripe_params["stripeToken"])
raise "Please, check registration errors" unless @registration.valid?
@registration.process_payment
@registration.save
redirect_to @registration, notice: 'Registration was successfully created.'
end
source to share
Try creating a board without a card_token. You don't need to specify the card a second time, since the card is tied to the client that you specify, though the parameter customer
.
customer = Stripe::Customer.create email: email,
source: card_token
Stripe::Charge.create customer: customer.id,
amount: level.price*100,
description: level.name,
currency: 'usd'
Also, pass card_token
through a parameter source
, not a deprecated parameter card
. Here is a blog post that talks about this change: https://stripe.com/blog/unifying-payment-types-in-the-api
More information: https://stripe.com/docs/api/ruby#create_customer and: https://stripe.com/docs/api#create_charge
source to share