3

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?

Javier Menéndez Rizo
  • 2,138
  • 3
  • 12
  • 22
Karthick
  • 433
  • 1
  • 10
  • 25
  • When you collect a customer’s payment information, a Stripe token is created. This token can only be used once, but that doesn’t mean you have to request your customer’s card details for every payment. – ray Jan 21 '19 at 06:35
  • If you do not save card information, then you have to provide detail every time you make payment. – ray Jan 21 '19 at 06:36
  • 1
    @ray, I agree your point but I have to know who has made payment so in this case, I have to send the stripe token with customer id as well right. Pls check the link https://stackoverflow.com/questions/34415987/stripe-payment-getting-error-as-customer-cus-does-not-have-a-linked-card. I was not able to send the stripe token with customer id and if I do it then it throws an error. – Karthick Jan 21 '19 at 07:04
  • Hi @Karthick, When creating charge, it is required that customer param is used Together with a card/src id "Saved" to the customer record. Saying that, there are two ways to create a charge: Firstly, create charge with the token without using customer; Secondly, save the token (AKA the card) to the customer, and then call the the charge create function with cust_id and source id. – wsw Jan 21 '19 at 09:44

1 Answers1

1

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
)
karllekko
  • 5,648
  • 1
  • 15
  • 19