-
-
Save callstack-bot/3bae84b3a6a30b6ccb2b383641c158b1 to your computer and use it in GitHub Desktop.
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, Button, Text, Image } from "react-native"; | |
import { useStripeIdentity } from "@stripe/stripe-identity-react-native"; | |
// brand logo that needs to be passed to Stripe Identity hook | |
import logo from "./assets/{{YOUR_BRAND_LOGO}}.png"; | |
// simplified example of fetch function for Stripe Identity | |
// it can be replaced with more robust implementation that handles error handling, analytics, etc. | |
// other fetching libraries like Axios can be used as a replacement for native fetch() | |
const fetchVerificationSessionParams = async () => { | |
try { | |
const data = await fetch( | |
`${YOUR_SERVER_BASE_URL}/create-verification-session`, | |
{ | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json" | |
} | |
} | |
); | |
const json = await data.json(); | |
return json; | |
} catch (e) { | |
return {}; | |
} | |
}; | |
// options needed to make correct request to Stripe Identity | |
const fetchOptions = async () => { | |
const response = await fetchVerificationSessionParams(); | |
return { | |
sessionId: response.id, | |
ephemeralKeySecret: response.ephemeral_key_secret, | |
brandLogo: Image.resolveAssetSource(logo) | |
}; | |
}; | |
function VerifyScreen() { | |
// hook provided by Stripe Identity SDK allows API consumers to get important states and values without too much work from their side. | |
const { status, present, loading } = useStripeIdentity(fetchOptions); | |
return ( | |
<View> | |
<Button title="Verify" disabled={loading} onPress={present} /> | |
<Text>Status: {status}</Text> | |
</View> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment