#yunakai-terminal
1 messages · Page 1 of 1 (latest)
Hi there! Posting your message in this thread:
I didn't notice you moved from IRC to discord
last Friday I posted a tech question there but no one answered and I was wondering why, lol
anyway, like I said in there
I am in the process of integrating Stripe Terminal (on top of our current Stripe integration)
I think I could manage to get it all done but I had a doubt about how to handle terminal connections
hi Soma!
I didn't notice you moved from IRC to discord
That happened a couple of years ago I think. We no longer actively monitor IRC, but now you are in the right place 🙂
yea, my bad
I didn't see the notification
anyway, let me put you in context
our scenario is basically a webpos so every time the page is loaded we initialize the whole POS
this means the terminal discovery and whatnot
so originally right after I get the terminal discovered I opened a connection and kept it alive during the whole session, which could mean that several transactions may happen
but after some thinking I came to the conclusion that I should open a connection to the terminal only every time Stripe is being selected as a payment method
meaning, I keep the discovered terminal all the time but open/close connections per transaction
I wonder if this is an expected flow and a best practice
are you using the JavaScript SDK? And which Terminal reader are you using?
correct, I'm using js sdk
currently I'm using the sim, however I should get the physical terminal soon
like today or tomorrow
sec, I forgot the model I got
BBPOS WisePOS
which, from my understanding, supports js sdk
thanks for the information, let me look into this.
after discussing with a colleague, we believe both options should work fine!
- it’s fine to cache/ ‘hold onto’ the discovered reader like that. It would only stop working if something changes like the reader getting a new IP address or falling off the network or being turned off, at which point you have to discover again.
- it’s also fine to connect once-per-transaction instead of connecting one and doing multiple transactions, I really don’t think it makes any difference, except maybe being a bit slower
if you don't mind I'll post some js code so you can see more or less what I mean
else if (this._mode === "terminal") {
if (_this._debug) {
console.debug("Stripe in terminal mode");
}
this._terminal = StripeTerminal.create({
onFetchConnectionToken: _this.fetchConnectionToken,
onUnexpectedReaderDisconnect: _this.unexpectedDisconnect
});
this.discoverTerminalReader();
if (_this._isValidHook(_this.stripePostinitHook)) {
_this.stripePostinitHook(_this);
}
if (_this._debug) {
_this._terminal.setSimulatorConfiguration({testCardNumber: '4242424242424242'});
}
this is basically the init method I use in our custom Stripe object when the page loads
whereas discoverTerminalReader looks like this:
this.discoverTerminalReader = function() {
var config = {};
if (_this._debug) {
config.simulated = true;
}
return _this._terminal.discoverReaders(config).then(function(discoverResult) {
if (discoverResult.error) {
console.log('Failed to discover: ', discoverResult.error);
return false;
} else if (discoverResult.discoveredReaders.length === 0) {
console.log('No available readers.');
return false;
} else {
// Just select the first reader here.
_this.terminalReader = discoverResult.discoveredReaders[0];
return true;
}
});
};
so any time the user selects card payment (Stripe) I make the connection
then disconnect if successful
what I noticed doing the other way around (keeping the connection alive)
is several requests stuck or taking so much time in the background
it didn't have any impact regarding performance, at least locally while testing
but it feels better to connect/disconnect
thanks for sharing the code! but like I said earlier both option should work.
is several requests stuck or taking so much time in the background
can you share more details about this?
unfortunately I can't I think, I made the changes already so now it behaves differently