#ajay-terminal
1 messages · Page 1 of 1 (latest)
hello @slender grail, how are you displaying that your devices are online/offline?
i.e. what is the code snippet you're running to discover whether a reader is online/offline?
partial code looks like below
connectReaderHandler: function () {
var selectedReader = null;
this.discoveredReaders.forEach((value,index ) => {
console.log(index);
console.log(value.label);
console.log(value.status);
if (value.id == defaultDevice) {
selectedReader = this.discoveredReaders[index];
}
});
console log show status is online even if that device is switched off
my guess here is that you may be storing previous state / discoveredReaders without "re-discovering" upon page load. I'd suggest adding logs / breakpoints to your code and walking through them to figure out where exactly the issue is occurring
I am making my google chrome refresh page
Also try with hard refresh too
but still same
but after some time that device list shows its offline
hmmmm, i'm not sure off the top of my head what is the expected speed that it's supposed to show offline. Sorry to redirect you but can you write in to Stripe Support and let them know that it's taking a couple of minutes to show offline and if that's expected?
Already chat with support
they said maybe issue is that I am testing from India (not stripe support here)
but I have checked with my US client too
he too facing same issue
my question is does that stripe device shows realtime online offline?
gimme a second, let me check in with someone else to see if they can help
Hi @slender grail let me help you on this
So when the readers are offline, and you can still get the reader array after calling terminal.discoverReaders(config) ?
yes
aint it terminal.discoverReaders(config) just return you list of all readers? either its online or offline
if all readers are offline, it will return an error.
can you share with me the code on how you use terminal.discoverReaders(config)?
full code function
connectReaderHandler: function () {
var selectedReader = null;
var defaultDevice = document.getElementById('hdnDefaultDeviceId').value;
this.discoveredReaders.forEach((value,index ) => {
console.log(index);
console.log(value.label);
console.log(value.status);
if (value.id == defaultDevice) {
selectedReader = this.discoveredReaders[index];
}
});
if(selectedReader) {
if(selectedReader.status=="online") {
console.log(selectedReader);
this.terminal
.connectReader(selectedReader)
.then(function (connectResult) {
if (connectResult.error) {
console.log("Failed to connect: ", connectResult.error);
this.message = 'Failed to connect stripe device';
} else {
console.log("Connected to reader: ", connectResult.label);
console.log("terminal.connectReader", connectResult);
this.collectPayment();
}
}.bind(this));
}
else {
alert('Check your device is on and status is online');
this.message = 'Check your device is on and status is online';
}
}
else {
alert('No device found');
this.message = 'No device found';
}
}
AND ALSO
discoverReaderHandler: function () {
var config = { simulated: false };
this.terminal.discoverReaders(config).then(function (discoverResult) {
if (discoverResult.error) {
console.log("Failed to discover: ", discoverResult.error);
} else if (discoverResult.discoveredReaders.length === 0) {
console.log("No available readers.");
} else {
this.discoveredReaders = discoverResult.discoveredReaders;
console.log("terminal.discoverReaders", discoverResult.discoveredReaders);
this.connectReaderHandler();
}
}.bind(this));
},
I'd assume there's just some lag involved here. The readers ping Stripe periodically to notify they they are online and discoverable so until enough time elapses for when they 'should have' pinged they would be discoverable , I'd assume
it's pretty minor, I think and it's just something you have to work with, it's how this works
When do you call the discoverReaderHandler() ? discoveredReaders array may not be the most not up-to-date state that reflects the statuses of the readers.
initialize: function () {
this.terminal = StripeTerminal.create({
onFetchConnectionToken: this.fetchConnectionToken,
onUnexpectedReaderDisconnect: this.unexpectedDisconnect,
});
console.log(this.terminal);
if(this.terminal) {
this.discoverReaderHandler();
}
}
yeah it's nothing to do with your code, it's just what I said above
then how can I use this code
if(selectedReader.status=="online")
as reader is switched off but response shows its online?
it is just temporary, it would be marked as offline after a little while
if you try connecting to the reader and get an error (because for example it's turned off) you just ask the cashier to e.g. select a different reader to connect to, or check the reader they want to use is turned on and charged, etc etc