cookedcarrots
cookedcarrots

Reputation: 7

EXPO REACT-NATIVE STRIPE PAYMENT 'expo-payments-stripe': How to use a token created?

I can generate a token with the createTokenWithCardAsync function, but then I don't know how to use the token to go through with the payment process.

Would anyone know which functions are in the 'expo-payments-stripe'? The actual stripe functions like stripe.customers.create() or stripe.charges.create() do not work. So far I just know of 2 functions compatible with that package, the one I mentioned above and createTokenWithCardFormAsync...

Ultimately I would like to attach the token to a customer so that they don't need to put their card details everytime they want to purchase something.

Also at the moment of token creation I do not charge any money, just want to 'keep' their info just like uber does.

thanks!

Upvotes: 0

Views: 362

Answers (1)

hmunoz
hmunoz

Reputation: 3331

Customer creation and Charge creation on Stripe is a secret-key only function, therefore cannot be done on your client-side (your mobile app which can only use your publishable key).

Therefore, the flow here is:

  1. Create a Token on your app (as you are)

  2. Post the token to your backend endpoint

  3. Your backend endpoint (written in say, node using stripe-node) calls stripe.customers.create() with the Token ID, attaching the Token to the Customer

  4. Charge creation later also has to happen server-side, not client-side.

Upvotes: 1

Related Questions