#wise_fox_58361
1 messages ยท Page 1 of 1 (latest)
Hello wise_fox_58361, we'll be with you shortly! 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.
โข wise_fox_58361, 20 hours ago, 5 messages
Hi, let me help you with this.
I would suggest preserving the token unless you need to refresh it.
Ok thanks. How long does the token last for?
Actually, you only need it when you're about to ask your customer to pay, you can fetch it at that point.
I am not sure that is true as we need to initialise the SDK first, then discover the readers, and then take the payment.
So the user needs to get the token when initialising the SDK.
The token I am talking about is the token returned by the fectTokenProvider function
See below:
import React from 'react';
import { StripeTerminalProvider } from '@stripe/stripe-terminal-react-native';
import WithTapToPayAndroidCheck from './WithTapToPayAndroidCheck.js';
import { apiHelper } from '../services/ApiHelper';
import { captureException, addBreadcrumb } from '@sentry/react-native';
const StripeTerminalProviderWrapper = ({ children }) => {
const fetchTokenProvider = async () => {
try {
const response = await apiHelper('stripe/connection-token', 'POST').then((response) => response.json())
console.log("Stripe response", response)
return response.token
} catch (error) {
console.log('StripeTerminalProviderWrapper response', error);
addBreadcrumb({
message: 'Unable to get Stripe Token',
});
captureException(error);
}
}
return (
<StripeTerminalProvider logLevel="verbose" tokenProvider={fetchTokenProvider}>
<WithTapToPayAndroidCheck>
{children}
</WithTapToPayAndroidCheck>
</StripeTerminalProvider>
)
};
export default StripeTerminalProviderWrapper;
If you use the StripeterminalProvider, it will fetch it when it needs to: https://stripe.com/docs/terminal/payments/setup-integration?terminal-sdk-platform=react-native#initialize
We are doing the same thing as the documenation. I guess the bit that I was maybe confused by is whether the SDK is reinitialised everytime the fetchTokenProvider is called?
I thought it might be?
I don't know exactly. Is it causing any issues? You can probably see when network requests are made in your devtools
I am getting the following errors after I do one successful donation:
- {"code": "NotConnectedToReader", "message": "No reader is connected. Connect to a reader before trying again."}
- {"code": "SessionExpired", "message": "Expired API Key provided: pss_test_YW*********************************************************************_******7uvj"}
I am running this on a mac simulartor iphone.
When I check if the reader is connected by checking connectedReader with the useStripeTerminal(), it shows that I have do have a reader connected.
This error is returned when I am calling the retrievePaymentIntent
I dont believe I see this on Android or when connected to a physical terminal but have not doubled checked that since I have modified the code
The code that I modified should not be created this issue.
I am about to create a production build to see if the issue is caused due to it being on a simulator / staging.
๐ stepping in here as vanya needs to step away
๐
Hmm yeah checking on a non-simulator seems worthwhile. However I'm also confused. At what point are you calling retrievePaymentIntent exactly?
I do that at the point of payment.
So I run the intialise SDK right at the beginning after a user has logged in.
Then allow them to connect to a discoveredReader, either localMobile or terminal.
Then allow them to take a payment at which point I call the retrievePaymentItent
Oh you use retrievePaymentIntent to get the ID and then pass that to collectPaymentMethod?
And at that point is when the error occurs?
const _retrievePaymentIntent = async (clientSecret) => {
const { paymentIntent, error } = await retrievePaymentIntent(clientSecret);
if (error) {
navigation.navigate('ModalStack', { screen: 'DonationErrorModal', params: { error: 'DONATION_FAILED', message: error.code } }); <--- This is where I see the error
dispatch(donationInitiationFailed(error))
} else if (paymentIntent) {
navigation.navigate('ModalStack', { screen: 'PaymentProcessingScreen' });
await _collectPaymentMethod(paymentIntent.id);
}
};
The error code is NotConnectedToReader (or something similar) returned by stripe. If I log 'connectedReader' just before this error message, its says there is a connected reader.
That is why I thought it could be related to the token being fetched every time I changed screen...
There was some sort of mismatch.
You are using Tap to Pay here, yes?
Yup
For iPhone
Small bit of context, code was working well for Android and Terminal and I have not seen this error message before. I have not retested those yet though scenarios / enviroments. Since updating the npm package number and allowing iOS to use tap on phone
No, I did see this section in the docs though.
The reason why I did not use that yet was I would expecte connectedReader to return null if it had disconnected.
Will happily add this function in for a quick test though.
Yeah that was going to be my recommendation
Having that in place may help us debug when the disconnect occurs and why
Cool. I may go do some further investigation. I will:
- add the above function in
- Try on a real device
- If the error is still being scene try on Android and with a physical terminal as well (which both used to be fine)