0

I have a Squarespace app that has collected charges for customers, however Squarespace does not create customer objects, it just stores charges.

My goal: When a user makes a purchase, create a Customer object with a subscription plan attached so we can make recurring charges to the card.

I can pull up a list of charges via the stripe test API and each charge has a source in it that contains a card token. So to my understanding I should be able to create a customer and pass in the source or source Id and it will add the source to that customer.

Here's what my code looks like:

customer = Stripe::Customer.create(
  :email => customerEmail,
  :plan => customerPlanId,
  :source => charge[:source],
  :description => customerName
)

I'm doing this in the stripe sandbox. I can clearly see the card stored in the source object within the charge, however stripe throws the error:

`handle_api_error': No such token: card_19NXFMKm5fnTITnyYdk6shyj (Stripe::InvalidRequestError)

Thanks in advance!

thomallen
  • 1,926
  • 1
  • 18
  • 32

1 Answers1

0

When you create a customer with the source parameter, it should be a token ID ("tok_..."), not a card ID.

See this StackOverflow answer for more information: https://stackoverflow.com/a/34416413/5307473

Community
  • 1
  • 1
Ywain
  • 16,854
  • 4
  • 51
  • 67
  • Thank you for answering, that's definitely the issue. To my understanding, there is no way for me to get access to that token because it only happens during the charge process and is not stored. Is that correct? – thomallen Dec 06 '16 at 03:08
  • Sorry, I don't follow. Stripe tokens represent cards while hiding the PCI-sensitive information from you. You can use a card token either directly to create a charge, or to create a customer object (which you can in turn use to create charges without having to create a new token). – Ywain Dec 06 '16 at 16:35
  • I have no access to the token object during checkout because I use squarespace commerce. What I want to do is somehow get access to the token later on but the only thing I have access to is a list of charges. Is it possible to create tokens from charges? – thomallen Dec 08 '16 at 16:35
  • No, tokens are created directly from card information. You can't recreate a token from a past charge. – Ywain Dec 08 '16 at 16:42