Gathering detailed insights and metrics for @stripe/stripe-terminal-react-native
Gathering detailed insights and metrics for @stripe/stripe-terminal-react-native
Gathering detailed insights and metrics for @stripe/stripe-terminal-react-native
Gathering detailed insights and metrics for @stripe/stripe-terminal-react-native
React Native SDK for Stripe Terminal
npm install @stripe/stripe-terminal-react-native
v0.0.1-beta.23
Published on 18 Nov 2024
v0.0.1-beta.22
Published on 27 Sept 2024
v0.0.1-beta.21
Published on 13 Sept 2024
v0.0.1-beta.20
Published on 24 Jul 2024
v0.0.1-beta.19
Published on 11 Jun 2024
v0.0.1-beta.18
Published on 06 May 2024
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
111 Stars
468 Commits
50 Forks
11 Watching
36 Branches
71 Contributors
Updated on 28 Nov 2024
Minified
Minified + Gzipped
TypeScript (56.08%)
Kotlin (19.76%)
Swift (17.17%)
JavaScript (2.82%)
Objective-C (1.24%)
Ruby (1.09%)
Java (1%)
Objective-C++ (0.43%)
Shell (0.38%)
C (0.03%)
Cumulative downloads
Total Downloads
Last day
1.4%
969
Compared to previous day
Last week
3.9%
4,967
Compared to previous week
Last month
-2.3%
22,297
Compared to previous month
Last year
265.5%
151,292
Compared to previous year
2
27
Stripe Terminal enables you to build your own in-person checkout to accept payments in the physical world. Built on Stripe's payments network, Terminal helps you unify your online and offline payment channels. With the Stripe Terminal React Native SDK, you can connect to pre-certified card readers from your React Native app and drive a customized in-store checkout flow.
Note: The below docs are not yet available and will be released as we near open beta
Get started with our 📚 integration guides and example project, or 📘 browse the SDK reference.
Updating to a newer version of the SDK? See our release notes.
7.9.0
and above.
Alternatively use the plugin-transform-typescript
plugin in your project.The React Native SDK includes an open-source example app, which you can use to familiarize yourself with the SDK and reader before starting your own integration.
To build the example app from source, you'll need to:
yarn bootstrap
from the root directory to build the SDK.example-app
folder and run yarn install
to install all example app dependencies..env.example
to .env
, and set the URL of the Heroku app you just deployed.yarn ios
or yarn android
depending on which platform you would like to build.1yarn add @stripe/stripe-terminal-react-native
or
1npm install @stripe/stripe-terminal-react-native
To initialize Stripe Terminal SDK in your React Native app, use the StripeTerminalProvider
component in the root component of your application.
First, create an endpoint on your backend server that creates a new connection token via the Stripe Terminal API.
Next, create a token provider that will fetch connection token from your server and provide it to StripeTerminalProvider as a parameter. Stripe Terminal SDK will fetch it when it's needed.
1// Root.tsx 2import { StripeTerminalProvider } from '@stripe/stripe-terminal-react-native'; 3 4function Root() { 5 const fetchTokenProvider = async () => { 6 const response = await fetch(`${API_URL}/connection_token`, { 7 method: 'POST', 8 headers: { 9 'Content-Type': 'application/json', 10 }, 11 }); 12 const { secret } = await response.json(); 13 return secret; 14 }; 15 16 return ( 17 <StripeTerminalProvider 18 logLevel="verbose" 19 tokenProvider={fetchTokenProvider} 20 > 21 <App /> 22 </StripeTerminalProvider> 23 ); 24}
As a last step, simply call initialize
method from useStripeTerminal
hook.
Please note that initialize
method must be called from a nested component of StripeTerminalProvider
.
1// App.tsx 2function App() { 3 const { initialize } = useStripeTerminal(); 4 5 useEffect(() => { 6 initialize(); 7 }, [initialize]); 8 9 return <View />; 10}
Stripe Terminal SDK provides dedicated hook which exposes bunch of methods and props to be used within your App. Additionally, you have access to the internal state of SDK that contains information about the current connection, discovered readers and loading state.
1// PaymentScreen.tsx 2 3import { useStripeTerminal } from '@stripe/stripe-terminal-react-native'; 4 5export default function PaymentScreen() { 6 const { discoverReaders, connectedReader, discoveredReaders } = 7 useStripeTerminal({ 8 onUpdateDiscoveredReaders: (readers) => { 9 // access to discovered readers 10 }, 11 onDidChangeConnectionStatus: (status) => { 12 // access to the current connection status 13 }, 14 }); 15 16 useEffect(() => { 17 const { error } = await discoverReaders({ 18 discoveryMethod: 'bluetoothScan', 19 simulated: true, 20 }); 21 }, [discoverReaders]); 22 23 return <View />; 24}
In case your app uses React Class Components
you can use dedicated withStripeTerminal
Higher-Order-Component.
Please note that unlike the hooks approach, you need to use event emitter to listen on specific events that comes from SDK.
Here you can find the list of available events to be used within the event emitter.
Example:
1// PaymentScreen.tsx 2 3import { 4 withStripeTerminal, 5 WithStripeTerminalProps, 6 CHANGE_CONNECTION_STATUS, 7 Reader, 8} from '@stripe/stripe-terminal-react-native'; 9 10class PaymentScreen extends React.Component { 11 componentDidMount() { 12 this.discoverReaders(); 13 const eventSubscription = props.emitter.addListener( 14 CHANGE_CONNECTION_STATUS, // didChangeConnectionStatus 15 (status: Reader.ConnectionStatus) => { 16 // access to the current connection status 17 } 18 ); 19 } 20 async discoverReaders() { 21 this.props.discoverReaders({ 22 discoveryMethod: 'bluetoothScan', 23 simulated: true, 24 }); 25 } 26} 27 28export default withStripeTerminal(PaymentScreen);
See the contributor guidelines to learn how to contribute to the repository.
No vulnerabilities found.
No security vulnerabilities found.