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
问题:
回答1:
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
回答2:
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.
回答3:
I ran into issues doing this with existing libraries, so I wrote a better one. react-native-stripe allows you to collect credit card information, validate it using Stripe, and exchange it for a Stripe token, all using native code. Currently iOS only.