Karthick
Karthick

Reputation: 443

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?

Upvotes: 3

Views: 504

Answers (2)

Aditya Parikh
Aditya Parikh

Reputation: 18

You can skip passing of customer while creating the charge as below:

Stripe::Charge.create(
 amount: amount_in_cents, 
 currency: currency_code,
 source: token,
 metadata: metadata
)

Upvotes: 0

karllekko
karllekko

Reputation: 7198

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
)

Upvotes: 1

Related Questions