#tristanoneil_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1338895811899166801
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hello, one thing that may help is creating an onUnexpectedDisconnect handler so that your app can try to automatically reconnect when it gets disconnected.
I forget if connection tokens expire and am still looking into this. I think they may be consumed by the initial connection and you need to create a new one for the re-connect, but as far as I know I don't think we expire them and disconnect because of that.
https://docs.stripe.com/terminal/payments/connect-reader?terminal-sdk-platform=js&reader-type=internet#handling-disconnects
We have onUnexpectedReaderDisconnect defined which calls this.terminal.connectReader, passing the original reader. We do not create a new token though when onUnexpectedReaderDisconnect is called though since the token is created in the function passed to onFetchConnectionToken
it looks something like:
this.terminal = window.StripeTerminal.create({
onFetchConnectionToken: this.#createTerminalConnectionToken.bind(this),
onUnexpectedReaderDisconnect: this.#connectReader.bind(this),
});
async #createTerminalConnectionToken() {
return await fetch(this.terminalTokenApiUrl, {
method: 'POST',
})
.then((response) => response.json())
.then((data) => data.secret);
}
async #connectReader() {
const selectedReader = await this.#findReader();
if (!selectedReader && this.#isNewConnection()) {
alert(
"Reader not found, check that you've provided a serial number and that it's valid."
);
return;
}
await this.terminal.connectReader(selectedReader);
if (this.#isNewConnection()) {
alert(`Connected to reader: ${selectedReader.label}`);
localStorage.setItem('readerSerialNumber', selectedReader.serial_number);
}
}
Gotcha, and yes apologies I misremembered how the reconnect happens. Is you reconnect code not working when it is called?
I think it is, I guess I can probably try to reproduce by turning off and on the Stripe Terminal reader? I've just received some vauge reports of disconnected errors from users. I'm still in the information collection stage and am just trying to do some due dilligence that my implementation isn't way off.
Yep shutting down is a good way to simulate an unexpected disconnect. That is good context to know, from that code I would be a bit surprised if the disconnect happened but they aren't seeing one of those later two messages about the reader or new connection.
So connectReader is called but I think when terminal.ConnectReader is called it outputs "Could not communicate with the Reader. Please make sure your reader is online and on the same network as your device, and that the host https://192-168-1-23.vnwwriu3adohh3rejhqn.device.stripe-terminal-local-reader.net is resolvable by your DNS provider. See https://support.stripe.com/questions/terminal-connectivity-issues for more details." ... maybe it's possible that it's called too quickly before the reader has full started back up again?
Find help and support for Stripe. Our support site provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
Ah that could be it. Maybe it could make sense to schedule another reconnect attempt in a couple seconds?
Yea, that's what I'm thinking maybe make the reconnect function try to reconnect every 5 seconds or something up to a limit and then fail.
Hmmm. I'm now getting a warning of "Detected Authentication Error. There may be an issue with the connection token or the Reader might have been hot swapped."
This is also followed up with an error of "Unhandled Promise Rejection: Error: The POS is no longer authenticated."
Strangely enough even though this warning and error are logged it seems to reconnect just fine ๐ค
async #reconnectReader() {
const interval = setInterval(async () => {
console.log('Attempting to reconnect to reader...');
const connectedReader = await this.#connectReader();
if (connectedReader) {
clearInterval(interval);
}
}, 10000);
}
Did the trick
Huh, good job finding something that worked! I was having trouble finding further info aobut this in our docs