Last active
April 25, 2021 14:28
-
-
Save thenishchalraj/29e5ddb010f77dc012c1b0b2dd5d6b27 to your computer and use it in GitHub Desktop.
A react native component that shows integration of stripe (tipsi-stripe) consists of a dialog that shows up when a button is clicked.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { View, Text, TouchableOpacity } from 'react-native' | |
import stripe from 'tipsi-stripe' | |
const YourCard = () => { | |
// initialize stripe | |
stripe.setOptions({ | |
publishableKey: 'pk_test_publishableUniqueKey' | |
}) | |
// show the dialog to fill card details | |
const stripeCardDialog = () => { | |
return stripe.paymentRequestWithCardForm() | |
.then((stripeTokenInfo) => { | |
console.log("[SUCCESS] Stripe Token ID: ", stripeTokenInfo.id) | |
// do anything with the Stripe Token Info, like sending some data server | |
}) | |
.catch((error) => { | |
console.log("[ERROR] User Cancelled the action") | |
// show a toast with the error if needed | |
}) | |
} | |
// view which will trigger the dialog | |
return ( | |
<View> | |
<TouchableOpacity onPress={() => stripeCardDialog()}> | |
<View> | |
<Text>Add Card</Text> | |
</View> | |
</TouchableOpacity> | |
</View> | |
) | |
} | |
export default YourCard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Click here to go to the blog where this was used, better explanation of how to integrate stripe in android with React Native, also Java and Kotlin code included.
Re-tweet on Twitter.
Share on LinkedIn.