#josh-terminal-reactnative
1 messages ยท Page 1 of 1 (latest)
josh-terminal-reactnative
You want the acct_123 which is their Stripe Account id as you're using Direct Charges and making all requests on their account
Thank you. I am able to create the connection, retrieve the token, use the SDK to connect to a reader (which then flashes four times). I then create an order in my system and create a payment intent on my server, but when I call
collectPaymentMethod({ paymentIntentId: orderData.paymentIntent.id, skipTipping: true });
I get an error that says "InvalidRequiredParameter" "There is no associated PaymentIntent with ID ___" But I can see the payment intent on the connected account. What am I doing wrong?
Can you share the PaymentIntent id so I can look at it?
pi_3OHt3fKLtaCvVZSR1aDdT2jF
Okay so the PaymentIntent is on the connected account so that's right. The problem is the ConnectionToken is created on your platform
I wonder if you are mixing them up maybe as I see you create some on the connected account too
What about this one? pi_3OIFt3KLtaCvVZSR0L1Y4xS1
sorry this is just a PaymentIntent id with no more details. Earlier I was just confirming it was created right. As long as you
- Create the PaymentIntent on the connected account (you do)
- Create the ConnectionToken on the connected account
it will work
So what you need to debug here is be 100% sure you create the ConnectionToken on the right account
Ok, so I am seeing this in my logs: connectBluetoothRader error 'The locationId parameter to BluetoothConnectionConfiguration is required but was not provided.'
cc @static girder to take over for me
Do I need to provide a location id with the M2 reader and if so, does that need to be also specified when I create the ConnectionToken?
๐ hopping in here!
Hi @static girder !
Yes, a location ID does need to be provided when you connect to bluetooth readers (like the M2) - https://stripe.com/docs/terminal/payments/connect-reader?terminal-sdk-platform=react-native&reader-type=bluetooth#connect-reader
But you shouldn't need to provide it when creating the Connection Token
Ok, hold on, I pulled that out, I'll add that back in.
That's not it. I'm still getting the InvalidRequiredParameter. pi pi_3OIGAjKLtaCvVZSR1uMcT6Ef and connection id tml_FWWpbwRow8k8u6
What's the exact error you're getting? You mention InvalidRequiredParameter, but that's not the full error
Error: {code:"InvalidRequiredParameter",message:"There is no associated paymentIntent with id pi_3OIGAjKLtaCvVZSR1uMcT6Ef."}
This is coming from
const { paymentIntent, error } = await collectPaymentMethod({ paymentIntentId: orderData.paymentIntent.id, skipTipping: true });
Hmm... give me a few minutes to do some digging
I'm sure I am doing something wrong, just not sure what.
Are you 100% sure your connection code is correct? I'm not seeing any recent connection attempts calling connectBluetoothReader with location ID tml_FWWpbwRow8k8u6 . What's the serial number of the device you're working with?
STRM26138001682
I am not sure my connection code is correct. Hold on.
I see the issue I thik
Yeah, it looks like the location Id isn't getting passed in correctly when I attempt to connectBluetoothReader
You can temporarily try hardcoding it to see if that's the only issue (if it works with the hardcoded location ID then you know that you just have the one issue to go back and fix)
Oh good call
ok, I hard coded it and am recompiling
Ok, now I am getting 'connectBluetoothReader error', { code: 'ConnectionTokenProviderCompletedWithError',
message: 'Connecting to the reader failed because the app completed fetchConnectionToken with an error.' }
Something must be wrong in your token provider as well - you'll likely want to add some logging client+server side to make sure your server is being hit correctly and that client-side you're correctly handling what you get back
Just based on the recent logs on your account I think you're server calls are going through right, so my guess would be the issue is in your react native code somewhere
I think I have an idea, I've been recreated the location every time, and I notice it is returning different ids.
I'm guessing I should just call await stripe.terminal.locations.create once per location and stash it in my DB?
Generally yes, you shouldn't keep creating locations but that's likley not related to the connection token error you're currently getting
Here's the connect code:
const handleConnectBluetoothReader = async (id, location) => {
console.log("connecting reader", id);
console.log("location", location);
const { reader, error } = await connectBluetoothReader({
reader: id,
locationId: 'tml_FWW1AwS7CTvbQK',
});
if (error) {
console.log('connectBluetoothReader error', error);
return;
}
console.log('Reader connected successfully', reader);
};
fetchTokenProvider = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (stripeConnection) resolve(stripeConnection);
}, 300);
});
}
async function getStripeConnection() {
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()
setStripeResponse(respdata);
if (respdata.connectionToken) {
console.log("got the stripe connection", respdata.connectionToken);
setStripeConnection(respdata.connectionToken);
}
if (respdata.location) {
console.log("got the location", respdata.location);
setLocation(respdata.location);
}
});
}
and in the view
<StripeTerminalProvider logLevel='verbose' tokenProvider={fetchTokenProvider}>
Are you not actually returning hte connection token secret in your function?
I'm using Firebase/Firestore. I save a document to Firestore, and then Cloud Functions makes the request to get the token.
Yeah, but the token provider expects the secret, not the full connection token.
And I'm not understanding why your provider is returning a promise, and not just the resolved secret
Oh I see.
So I was using a promise because I use Firebase on the backend. I was submitting a document to Firestore, which kicks off a function to get the connection token.
I need to wait for onSnapshot to return with the token.
That was the issue, thank you. It started installing the update and ran into an issue there that looks to be my fault.
๐ glad I could help!
I need to head out, but my teammate is around if anything else comes up
Thanks you so much!
Ok, I got it to connect to the reader successfully and it ran an update, and now I mam back to the 'there is no associated paymentIntent' error
Sorry to hear. Catching up and will get back to you shortly
Thank you
Can you send your current code for how you are creating the connection token and the payment intent?
Sure
.document("stripeRequests/{requestId}")
.onCreate(async (snapshot, context) => {
const req = (await snapshot.ref.get()).data();
snapshot.ref.update({status: "starting"});
if (req.task == "getStripeConnectionToken") {
const stripe = require("stripe")(stripeKey);
// Get the location for the reader
const location = await stripe.terminal.locations.create({
display_name: "The Crane Theater",
address: {
line1: "2303 Kennedy St NE Unit 120",
city: "Minneapolis",
state: "MN",
country: "US",
postal_code: "55413",
}}, {
stripeAccount: "acct_****",
});
// Get the connection token
const connectionToken = await stripe.terminal.connectionTokens.create({stripeAccount: "acct_*****"});
console.log("connection token", connectionToken);
snapshot.ref.update({connectionToken: connectionToken, status: "success", location: location});
}
});
And have you double checked to confirm that the account IDs on those match the account ID you are passing when creating the Payment Intent?
Yes, I believe they are.
HI ๐
I'm stepping in as my colleague @steep geode has to go. Can you please confirm that the Stripe account used in all cases matches?
Yes, it should be the same accout
Can you share the ID of the request that returns the there is no associated payment intent error?
It will start with req_
Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
req_LqKF6QAQ8Fgv6P
Thanks, looking
Okay so that Payment Intent exists on the Connected Account acct_1HCEhOKLtaCvVZSR. What account are you using to create the connection token?
acct_1HCEhOKLtaCvVZSR, it is currently hard coded
const connectionToken = await stripe.terminal.connectionTokens.create({stripeAccount: "acct_1HCEhOKLtaCvVZSR"});
Okay so, stepping back, you said you get an error about "no assciated paymentIntent". Where does that occur? The request you shared creates a payment intent but I'm not seeing where the error occurs
Yeah, so I create that PaymentIntent on the server, and then pass it to the client (React Native SDK on iOS).
I then call const { paymentIntent, error } = await collectPaymentMethod({ paymentIntentId: orderData.paymentIntent.id, skipTipping: true });
and that's where the error comes from
Okay, I've got a better picture of what's going on here.
So, in the RN code, do you currently log the paymentIntentID value prior to calling collectPaymentMethod?
Yeah, the line right before is
console.log("Payment Intent ID: ", orderData.paymentIntent.id);
and you are getting a pi_XXXXXX looking value?
Okay and how are you initializing the React Native SDK? What Publishable Key are you using? Wait... this is the connection token, correct?
Correct
Okay and did you log the connection token you used with pi_3OIIfDKLtaCvVZSR157fFmDp?
It is the secret key on the server
If you could log both a Payment Intent ID and a connection token used in the same attempt and share them here that would be helpful
Is the one associated with that pi
Sorry that looked like a live key, so I deleted it
We never share API keys. Only Stripe Object IDs
Oh wait, I might have jumped the gun there. Here's an example of what the connection token secret looks like pst_test_my0Ta77WIFJD2zdPEnQXjiS
pst_live_YWNjdF8xSENFaE9LTHRhQ3ZWWlNSLHlMYzBraEJDcG5aNm5OYmxJNE9kOVNiZmdGaWFYR2Y_00CYoL2h8Q
Sorry, I should switch back to the test account.
Well the Connection token is useless to anyone who doesn't have your API keys so now that I'm clear on that I'm not concerned
But our Publishable API keys start with pk_live_xxxx and that looked pretty close to me
Cool
Alright that is also looking good. And the reader you are using is registered at the location you are providing?
Oh wait.
That's it, thank you.
So, my back end code has been generating a new location ID every time. That's got to be the issue. I'll fix that.
OH Yeah you need to use one specific location ID and the physical reader needs to be registered at that location.
If I've already registered the reader to a location, do I need to disconnect and re-register it?
Oh, I suppose I could use the same ID.
Yeah, that's what I will do.
You can try that location ID. As long as it's a location associated with the Connected Account where all of this is happening
Ok, I'll try that and report back. It might be tomorrow. Should I open a new thread if I run into issues?
Sure, we close threads after some period of inactivity but you are welcome to post in the main channel with a summary of your current state
Awesome, thanks for your help.