Set up your integration
Set up a Stripe Terminal SDK or server-driven integration to accept in-person payments.
注意
Terminal’s React Native library is in public preview and in active development. Please report any issues you encounter to our github project.
注意
If you’re building an Apps on Devices integration (running your app on Stripe smart readers such as the S700), you’ll need to complete additional native Android setup steps after following this guide.
Getting started with the React Native SDK requires four steps:
- Install the SDK in your app.
- Configure your app.
- Set up the connection token endpoint in your app and backend.
- Initialize the SDK in your app.
Install the SDKClient-side
The React Native SDK is open source and fully documented. Internally, it makes use of native iOS and Android SDKs. Install the SDK by running:
Set up the connection token endpointServer-sideClient-side
Server-side
To connect to a reader, your backend needs to give the SDK permission to use the reader with your Stripe account, by providing it with the secret from a ConnectionToken. Your backend needs to only create connection tokens for clients that it trusts.
Obtain the secret from the ConnectionToken on your server and pass it to the client side.
注意
The secret from the ConnectionToken lets you connect to any Stripe Terminal reader and take payments with your Stripe account. Be sure to authenticate the endpoint for creating connection tokens and protect it from cross-site request forgery (CSRF).
Client-side
To give the SDK access to this endpoint, create a token provider single function that requests a ConnectionToken from your backend.
import { StripeTerminalProvider } from '@stripe/stripe-terminal-react-native'; const fetchTokenProvider = async () => { const response = await fetch(`{YOUR BACKEND URL}/connection_token`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, }); const { secret } = await response.json(); return secret; };
This function is called whenever the SDK needs to authenticate with Stripe or the Reader. It’s also called when a new connection token is needed to connect to a reader (for example, when your app disconnects from a reader). If the SDK can’t retrieve a new connection token from your backend, connecting to a reader fails with the error from your server.
注意
Do not cache or hardcode the connection token. The SDK manages the connection token’s lifecycle.
Initialize the SDKClient-side
To get started, pass in your token provider implemented in Step 3 to StripeTerminalProvider as a prop.
import { StripeTerminalProvider } from '@stripe/stripe-terminal-react-native'; function Root() { const fetchTokenProvider = async () => { const response = await fetch(`${API_URL}/connection_token`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, }); const { secret } = await response.json(); return secret; }; return ( <StripeTerminalProvider logLevel="verbose" tokenProvider={fetchTokenProvider} > <App /> </StripeTerminalProvider> ); }
As a last step, call the initialize method from useStripeTerminal hook.
注意
You must call the initialize method from a component nested within StripeTerminalProvider, not from the component that contains the StripeTerminalProvider.
After initialization completes, you can use other SDK methods such as discoverReaders, collectPaymentMethod, and confirmPaymentIntent. If you attempt to call these methods before initialization, you’ll receive the following error: “First initialize the Stripe Terminal SDK before performing any action.”
function App() { const { initialize } = useStripeTerminal(); useEffect(() => { initialize(); }, []); return <View />; }
SDK updates
Stripe periodically releases updates which can include new functionality, bug fixes, and security updates. Update your SDK as soon as a new version is available. The currently available SDKs are:
- Stripe Terminal Android SDK
- Stripe Terminal iOS SDK
- Stripe Terminal JavaScript SDK
- Stripe Terminal React Native SDK