Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make stripe payment without card saving

I have read most of the stripe payment things. They told that first add a card to the customer in stripe means save the card to the customer then make payment. But my requirement makes the payment using the card and no need to save the card details in the stripe.

Below see the code I have passed customer id and stripe token instead of a card id(card_****)

Stripe::Charge.create(
  amount: amount_in_cents, 
  currency: currency_code,
  customer: stripe_customer_id,
  source: stripe_token
)

But it throws an error

Getting Error as Customer cus_***** does not have a linked card with ID tok_*****

I have read the link Stripe Payment: Getting Error as Customer cus_***** does not have a linked card with ID tok_***** and It told if you are going use both params customer and source then the source should be card id(card_****). Is there any alternate solution how to use?

like image 370
Karthick Avatar asked Apr 18 '26 00:04

Karthick


1 Answers

If you don't want to use a customer you don't have to, just charge the payment token directly and omit the customer argument :

Stripe::Charge.create(
  amount: amount_in_cents, 
  currency: currency_code,
  source: stripe_token
)
like image 121
karllekko Avatar answered Apr 20 '26 20:04

karllekko