#yoyosaur_code
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/1387166015116283964
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- yoyosaur_error, 6 days ago, 25 messages
useEffect(() => {
const initStripe = async () => {
try {
await initialize();
try {
const reader = await getConnectedReader();
if (reader) return;
} catch (error) {
console.error("Error getting connected, finding reader");
}
const {error} = await discoverReaders({
discoveryMethod: "handoff",
});
if (error) {
console.error("Error discovering readers:", error);
}
} catch (error) {
console.error("Error initializing Stripe:", error);
}
};
This is my attempt at dealing with a potential connected reader.
This is what's passed into my use affect
}, [initialize, discoverReaders, getConnectedReader, isLoadingStripe, isProcessingPayment]);
TI's related to #1384958805913112609 message
Basically, becuase of the initialization order we're getting something weird:
ERROR First initialize the Stripe Terminal SDK before performing any action
ERROR Error getting connected, finding reader
ERROR First initialize the Stripe Terminal SDK before performing any action
ERROR Error initializing Stripe: [Error: First initialize the Stripe Terminal SDK before performing any action]
That's my erorr log, but it's incorrect because this is inside the stripe terminal provider and should only startup once the terminal provider is initialized
hey, I was reviewing the previous thread
Awesome. Let me know anything else I can provide. The issue I'm worried about is twofol:
- A bit hard to develop, because when I do a hotreload of my code it can't connect to the reader, because the reader is already connected.
I can handle this with internal state and get around it, butit's clearly causing some issues given I have a connected reader.
I'm thinking I can check to see if there's a connected reader in the discoveredReaders.
Can you share more code from your component where youre initializing, eg the useStripeTerminal hook and then the components that follow?
And then in particular have you narrow down exactly what step triggers the error you see?
Yeah
onUpdateDiscoveredReaders: async (readers) => {
if (readers.length > 0) {
const currentReader = readers[0];
setReaderInfo({
name: currentReader.label ?? currentReader.id,
serialNumber: currentReader.serialNumber,
stripeTerminalId: currentReader.id,
});
try {
const reader = await getConnectedReader();
if (reader) return;
} catch (error) {
console.error("Error getting connected, finding reader");
}
await connectReader({reader: currentReader}, "handoff");
setIsLoadingStripe(false);
}
},
This is the inside of my useStripeTerminal
In the earlier code, the error pops up as soon as the app starts, every time.
Here are the logs from the app starting up
LOG [Stripe terminal]: didChangeOfflineStatus {"reader": undefined, "sdk": {"networkStatus": "unknown", "offlinePaymentAmountsByCurrency": {}, "offlinePaymentsCount": 0}}
ERROR First initialize the Stripe Terminal SDK before performing any action
ERROR Error getting connected, finding reader
ERROR First initialize the Stripe Terminal SDK before performing any action
ERROR Error initializing Stripe: [Error: First initialize the Stripe Terminal SDK before performing any action]
ERROR First initialize the Stripe Terminal SDK before performing any action
LOG [Stripe terminal]: didChangeConnectionStatus discovering
I want to add:
I moved the try/catch to the inside of onUpdateDiscoveredReaders because of this issue.
Maybe that's correct behavior but it's not indicated in the stripe docs if so.
Hmm parts of what you're showing me appear to be from different guides. For example, I don't see use of initialize in our App-on-Devices integration guide at all. You said apps on devices up top, but is that what you're doing here, or are you using the reader as a standalone device from another mobile device?
Can you point me to which integration docs you're following for this so I am looking at the same thing as you?
https://docs.stripe.com/terminal/features/apps-on-devices/build
const { discoverReaders, connectReader, discoveredReaders } =
useStripeTerminal({
onUpdateDiscoveredReaders: (readers) => {
// After the SDK discovers a reader, your app can connect to it.
},
});
useEffect(() => {
const fetchReaders = async () => {
const { error } = await discoverReaders({
discoveryMethod: 'handoff',
});
}
fetchReaders();
}, [discoverReaders]);
const { reader, error } = await connectReader({reader}, 'handoff');
if (error) {
console.log('connectReader error:', error);
return;
}
console.log('Reader connected successfully', reader);
I had this before but without the call to initialize it was not calling discover at all.
Notably if I don't call initialize, I cannot connect at all.
const initStripe = async () => {
console.log("Initializing Stripe");
try {
const {error} = await discoverReaders({
discoveryMethod: "handoff",
});
if (error) {
console.error("Error discovering readers:", error);
}
} catch (error) {
console.error("Error initializing Stripe:", error);
}
};
This function
Yields these logs:
LOG appStage auth
ERROR First initialize the Stripe Terminal SDK before performing any action
ERROR Error initializing Stripe: [Error: First initialize the Stripe Terminal SDK before performing any action]
ERROR First initialize the Stripe Terminal SDK before performing any action
LOG Initializing Stripe
ERROR First initialize the Stripe Terminal SDK before performing any action
ERROR Error initializing Stripe: [Error: First initialize the Stripe Terminal SDK before performing any action]
Oh interesting
Something different happening?
I'm trying to get the discover effect to be very simple.
It seems to take a considerable amount of time, which is fine, but this is working well:
onUpdateDiscoveredReaders: async (readers) => {
//now my block of reader stuff is large, but handles the already connected reader
console.log("Updating discovered readers");
try {
const reader = await getConnectedReader();
if (reader) {
setReaderInfo({
name: reader.label ?? reader.id,
serialNumber: reader.serialNumber,
stripeTerminalId: reader.id,
});
console.log("Reader found, setting loading to false");
setIsLoadingStripe(false);
return;
}
} catch (error) {
console.error("Error getting connected, finding reader");
}
if (readers.length > 0) {
const currentReader = readers[0];
setReaderInfo({
name: currentReader.label ?? currentReader.id,
serialNumber: currentReader.serialNumber,
stripeTerminalId: currentReader.id,
});
await connectReader({reader: currentReader}, "handoff");
setIsLoadingStripe(false);
}
},
});
// new streamlined effect
useEffect(() => {
const initStripe = async () => {
console.log("Initializing Stripe");
try {
await initialize();
const {error} = await discoverReaders({
discoveryMethod: "handoff",
});
if (error) {
console.error("Error discovering readers:", error);
}
} catch (error) {
console.error("Error initializing Stripe:", error);
}
};
initStripe();
}, [discoverReaders]);
I'm still getting
ERROR First initialize the Stripe Terminal SDK before performing any action
And to be clear you did this step https://docs.stripe.com/terminal/features/apps-on-devices/build?terminal-sdk-platform=react-native#configure-your-application with Android-specific code?
Also asking a colleague who mentioned you might be missing the entire Terminal SDK initialization which comes from this part of the guide https://docs.stripe.com/terminal/payments/setup-integration?terminal-sdk-platform=react-native#initialize
So did you do that too @stray sand ?
This I've followed yes
The android specific code is missing let me add that in and see if I continue to get the intialze errors. Interestingly, I've not needed to use the application overall though.
Gotcha. If you are still stuck I unfortunately won't be able to help. I don't know that product at all as it's quite complex mobile development so contacting our support team for 1:1 help will likely yield better results in that case