Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use Stripe (stripe.js) and react-native

I'm trying to find a good approach to using stripe with react-native. Preferably one that doesn't involve sending credit card details to my own backend or storing my stripe private key in the application. Any ideas welcome! thanks

like image 754
Irfy Avatar asked Dec 25 '15 23:12

Irfy


2 Answers

I have not implemented this in React Native personally yet. In the app I am working on this will be ported over in the next few days but here is how we do it in the current app without any dependency on third party libraries and how we will implement in React Native as well. This is obviously just a concept that can be used anywhere you can make a HTTP call.

Make a POST call to https://api.stripe.com/v1/tokens with a 'Authorization' header with the value Bearer {PUBLISHABLE_AUTH_TOKEN}. In the body (x-www-form-urlencoded) put:

card[name]={NAME_ON_CARD}&card[number]={CARD_NUMBER}&card[exp_month]={CARD_EXP_MONTH}&card[exp_year]={CARD_EXP_YEAR}&card[cvc]={CARD_CVC}

The response will be a JSON object that contains (among other things) an id field. This id field is what you will reference the card when making transactions so this ID needs sent to your server and stored. This ID can be stored without worry of PCI compliance.

More Info: https://stripe.com/docs/api#tokens

like image 131
rmevans9 Avatar answered Oct 20 '22 18:10

rmevans9


I recommend: https://github.com/tipsi/tipsi-stripe

I was able to successfully connect React Native and Stripe to create a customer and add a card and save the tokens to my back end.

like image 35
Beau Smith Avatar answered Oct 20 '22 16:10

Beau Smith