#josh-c_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/1299004833965150239
๐ 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.
- josh-c_code, 7 hours ago, 54 messages
Do I need to register the reader on the server side first? The code above is running in my iOS app.
I am using Connect with Direct payments, if that helps
Hi ๐ based on your code it looks like you're using bluetooth reader. If that's the case then no, you don't need to register the reader.
Ok, that's what I thought. Why am I getting this error?
Can you elaborate on what the error you're seeing is? I saw you said you're seeing CompletedWithError, but I'm not seeing what error is being thrown by the token provider.
Connecting to the reader failed because the app completed fetchConnectionToken with an error
Connection token is pst_test_YWNjdF8xTUx0bWxSOEV2Qk1xYjUzLGJ3RTZ0bDRXVWN1MGxVVTE2R3BIaVVCbXF3MXdKeDY_00gLPiV1Ys
I see Connection Tokens being generated, are they being returned to your app? Have you tried logging out what you're getting back in the app to make sure it's the same as what is being generated when you hit our API?
Yeah, I am displaying the returned connection token and location ID on my Connect Readers screen currently
Can you share your code for your connection token endpoint, as well as your client-side token provider?
Yeah, here's the token endpoint:
exports.stripeAccessRequested = functions.firestore
.document("stripeRequests/{requestId}")
.onCreate(async (snapshot, context) => {
const req = (await snapshot.ref.get()).data();
snapshot.ref.update({status: "starting"});
const user = await getUser(req.userId);
if (req.task == "getStripeConnectionToken") {
const stripe = require("stripe")(stripeKey);
// Get the connection token
const connectionToken = await stripe.terminal.connectionTokens.create({stripeAccount: user.stripeAccount});
console.log("connection token", connectionToken);
// Changed
snapshot.ref.update({connectionToken: connectionToken, status: "success", location: stripeTerminalLocation, stripeAccount: user.stripeAccount});
}
});
the location ID was created with back end code but is currently hard coded as a configuration variable. The Stripe account ID is retrieved from the user's account record in our Firestore DB.
The corresponding locationID and accountID are retrieved when the user authenticates to the app and stored in a useContext hook:
async function getStripeConnection(user:User) {
console.log("Submitting Stripe connection request...");
const req = {
userId: user!.uid,
task: "getStripeConnectionToken",
status: "submitted"
};
var reqRef = await addDoc(collection(db, "stripeRequests"), req);
onSnapshot(reqRef, (snapshot) => {
const respdata = snapshot.data();
console.log("setting stripe key", respdata);
if (respdata!.connectionToken) {
setStripeKey(respdata!.connectionToken.secret);
setLocation(respdata!.location);
router.push("/home");
}
}
const fetchTokenProvider = useCallback(async (): Promise<string> => {
console.log("fetching token", stripeKey);
if (!stripeKey) {
return '';
}
}, []);
const fetchTokenProvider = useCallback(async (): Promise<string> => {
console.log("fetching token", stripeKey);
if (!stripeKey) {
return '';
}
return stripeKey;
}, []);
oh wait, now it looks like it might be updating my reader?
I'm not too familiar with firebase/firestore, but I'm not readily seeing where you're returning the Connection Token you got. If you're seeing it client-side I guess you are though.
Where in the fetchTokenProvider function are you hitting your token endpoint?
So the way Firestore works is it only fires when a document is created updated or deleted. I create a stripeRequest document and then attach an onSnapshot listener when the user logs in, and then I stash the connection token in my AppContext
fetchTokenProvider is then returning that stored token
Hm, does fetchTokenProvider fetch a new connection token every time it's called, or does it keep returning the one you stored?
keeps returning the stored token
That's not correct behavior, the function should get a brand new connection token every time it runs.