Skip to content

Instantly share code, notes, and snippets.

@vivekvardhanadepu
Created December 31, 2021 10:42
Show Gist options
  • Save vivekvardhanadepu/245c2dc064ec11e759a6e44ee044bfda to your computer and use it in GitHub Desktop.
Save vivekvardhanadepu/245c2dc064ec11e759a6e44ee044bfda to your computer and use it in GitHub Desktop.
react-native-stripe-terminal reader functionalities
import StripeTerminal from 'react-native-stripe-terminal';
// discovering Readers
StripeTerminal.discoverReaders(
StripeTerminalModule.DiscoveryMethodBluetoothScan, // discovery method
SIMULATED // 0 for real devices, 1 for simulated devices
)
.then((readers) => {
console.log("readers", readers);
})
.catch((error) => {
console.log(error)
});
// discoverReaders can function only when there is no reader connected
StripeTerminal.getConnectedReader()
.then((reader) => {
if (reader) {
console.log('already connected to', reader.serialNumber);
} else {
StripeTerminal.discoverReaders();
}
})
.catch((error) => {
console.log("getConnectedReader", error);
});
// connect to a reader
StripeTerminalModule.connectReader(
serialNumber,
locationId // optional
)
.then((reader) => {
console.log("connected to reader", reader.serialNumber);
})
.catch((e) => {
console.log("failed to connect", e);
});
// disconnect from a reader
StripeTerminalModule.disconnectReader()
.then(() => {
console.log('disconnected from reader successfully');
})
.catch((error) => {
console.log(error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment