Skip to content

Instantly share code, notes, and snippets.

@callstack-bot
Created November 2, 2022 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save callstack-bot/3bae84b3a6a30b6ccb2b383641c158b1 to your computer and use it in GitHub Desktop.
Save callstack-bot/3bae84b3a6a30b6ccb2b383641c158b1 to your computer and use it in GitHub Desktop.
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