#Antriksh
1 messages ยท Page 1 of 1 (latest)
๐ Thanks for reaching out
Please give couple of minutes while analyzing this
Sure. Thanks
Are you doing Step3 without disconnecting/unregistering the reader ?
Yes I am connecting to the reader and doing multiple payments.
yeah, but at step 3 why you want to rediscover an already discovered reader before? you said Now, when doing this process again when I try to discover readers again
I'm not seeing why you want to rediscover the reader again, sorry not sure I'm following your senario 100%
I am doing this again, because when we repeat this process (Doing second payment after first successful one), we need to show updated list of ONLINE readers, which comes on discovery.
So, to show live ONLINE readers, we do discover readers before each payment.
Ah ok I see now, you don't need to rediscover reader before each payments. You just monitor the function onUnexpectedReaderDisconnect to see if a reader has been disconnected or not, otherwise you keep in your integration the reader AS online
You pass the callback function when doing the StripeTerminal.create
https://stripe.com/docs/terminal/payments/setup-integration?terminal-sdk-platform=js#initialize
Ok, but what if I discovered the online readers and then after sometime one specific reader comes online. How will we know that reader has come online and we can use it ?
This is the case where we have multiple readers and they can be ONLINE anytime AFTER our web-app has loaded.
Sorry for my late reply
In order to discover a reader, are you creating a new StripeTerminal ?
No, using the same StripeTerminal todiscover
In order to discover readers you are following this link, right so?
https://stripe.com/docs/terminal/payments/connect-reader
Yes, I am just calling terminal.discoverReaders with same StripeTerminal created initially.
Should this call the fetchToken callback everytime ?
My flow --
Discover online reader -> Connect reader (only if not connected) -> Collect payment -> Process payment -> Repeat.
On repeat the generate_pos_rpc_session gives that redeem error, but readers still get discovered.
You mean the onFetchConnectionToken?
yes
Yeah, that's need by the SDK in order to connect to the reader.
So, why is it not doing same for discover readers ? And that generate_pos_rpc_session fails for token redemption.
I think you need to provide more details about your integration and code, can you prepare a sample project that reproduce this issue so that we can analyze further ?
See, this is the issue I get on discovery.
On your sample app, you can try these steps -
- Discover readers
- Connect reader
- Collect and process payment
- Discover readers again.
It should show an error in console.
๐ taking over for my colleague. Let me catch up.
sorry discord is super busy now, will be with you shortly
AFAIK you don't have to rediscover readers once you have already established a connection to one
So, how do we get readers which came online after connecting to one another reader ?
you should keep track of the ids of the readers that you are connected to at a given point
My issue is here, If I have 2 readers, I switched ON
only 1 readser
connected to it and payment done,
Now if i switched 2nd reader ONLINE, how to know that it is ONLINE now, without refreshing page ?
Don't I need to rediscover for that ?
yes but the problem you described and the error that you got wasn't from discovery it was from trying to use an already used connection token
yes, but that request went when I did discoverReader, SDK should call the fetchToken itself ? And this happens only if I collect payment and then try again. If I try reader connect and then do discovery, the fetchToken callback gets called.
the SDK will call fetchToken when it needs to automatically, such as if doesn't have a token yet or the one it had expired.
Correct, so if SDK is giving this error , then it need a new token ? Right ? It should have called it ?
I would imagine so
can you share full code, such as the implementation of the fetchConnectionToken function and confirm that you have a backend server set up which you've written code in that function to call to get a new token?
//Load Stripe terminal SDK and create session.
async setUpTerminal() {
const StripeTerminal = await loadStripeTerminal();
this.terminalSession = StripeTerminal.create({
onFetchConnectionToken: this.fetchConnectionToken,
onUnexpectedReaderDisconnect: this.unexpectedDisconnect,
});
}
//Get stripe secret token for terminal connection.
async fetchConnectionToken(): Promise<string> {
const headers = new Headers();
headers.set('Accept', 'application/json, text/plain');
headers.set('Content-Type', 'application/json;charset=UTF-8');
let options = {
method: 'GET',
headers: headers
};
return fetch(`${configStore.get('baseUrl')}/api/Terminal/${configStore.get('dealerId')}/ConnectionToken`, api.addAuthHeader(options))
.then((response) => {
return response.json();
})
.then((data) => {
return data.secret;
});
}
This is what I do on my web-app load.
call setUpTerminal method.
On initial discovery,
On discovery after collect payment -
ack. As my colleagues mentioned I don't think we really expect you to be trying to discover/connect again when you're already connected to a reader, that's not how I built my integration when I did this. Probably it causes an issue.
maybe try calling https://stripe.com/docs/terminal/references/api/js-sdk#disconnect after the payment and then doing the discovery process again.
Ohk. yeah I can try doing that, disconnecting after each payment and then discovery.
Because I want to show updated ONLINE readers everytime I go for Payment, for which new discovery is necessary.