#josh-terminal-reactnative

1 messages ยท Page 1 of 1 (latest)

fathom skiffBOT
wintry steppe
#

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

opal cloud
#

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?

wintry steppe
#

Can you share the PaymentIntent id so I can look at it?

opal cloud
#

pi_3OHt3fKLtaCvVZSR1aDdT2jF

wintry steppe
#

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

opal cloud
#

What about this one? pi_3OIFt3KLtaCvVZSR0L1Y4xS1

wintry steppe
#

sorry this is just a PaymentIntent id with no more details. Earlier I was just confirming it was created right. As long as you

  1. Create the PaymentIntent on the connected account (you do)
  2. 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

opal cloud
#

Ok, so I am seeing this in my logs: connectBluetoothRader error 'The locationId parameter to BluetoothConnectionConfiguration is required but was not provided.'

wintry steppe
#

cc @static girder to take over for me

opal cloud
#

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?

static girder
#

๐Ÿ‘‹ hopping in here!

opal cloud
#

Hi @static girder !

static girder
opal cloud
#

Ok, hold on, I pulled that out, I'll add that back in.

fathom skiffBOT
opal cloud
#

That's not it. I'm still getting the InvalidRequiredParameter. pi pi_3OIGAjKLtaCvVZSR1uMcT6Ef and connection id tml_FWWpbwRow8k8u6

static girder
#

What's the exact error you're getting? You mention InvalidRequiredParameter, but that's not the full error

opal cloud
#

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 });

static girder
#

Hmm... give me a few minutes to do some digging

opal cloud
#

I'm sure I am doing something wrong, just not sure what.

static girder
#

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?

opal cloud
#

STRM26138001682

#

I am not sure my connection code is correct. Hold on.

#

I see the issue I thik

static girder
#

๐Ÿ‘

#

any luck?

opal cloud
#

Yeah, it looks like the location Id isn't getting passed in correctly when I attempt to connectBluetoothReader

static girder
#

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)

opal cloud
#

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.' }

static girder
#

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

opal cloud
#

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?

static girder
#

Generally yes, you shouldn't keep creating locations but that's likley not related to the connection token error you're currently getting

opal cloud
#

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);
};
static girder
#

Can you share your token provider code instead?

opal cloud
#

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}>

static girder
#

Are you not actually returning hte connection token secret in your function?

opal cloud
#

I'm using Firebase/Firestore. I save a document to Firestore, and then Cloud Functions makes the request to get the token.

static girder
#

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

opal cloud
#

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.

static girder
#

๐Ÿ‘ glad I could help!

#

I need to head out, but my teammate is around if anything else comes up

opal cloud
#

Thanks you so much!

opal cloud
#

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

steep geode
#

Sorry to hear. Catching up and will get back to you shortly

opal cloud
#

Thank you

steep geode
#

Can you send your current code for how you are creating the connection token and the payment intent?

opal cloud
#

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});
  }
});
fathom skiffBOT
steep geode
#

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?

opal cloud
#

Yes, I believe they are.

shy dove
#

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?

opal cloud
#

Yes, it should be the same accout

shy dove
opal cloud
#

req_LqKF6QAQ8Fgv6P

shy dove
#

Thanks, looking

#

Okay so that Payment Intent exists on the Connected Account acct_1HCEhOKLtaCvVZSR. What account are you using to create the connection token?

opal cloud
#

acct_1HCEhOKLtaCvVZSR, it is currently hard coded

#

const connectionToken = await stripe.terminal.connectionTokens.create({stripeAccount: "acct_1HCEhOKLtaCvVZSR"});

shy dove
#

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

opal cloud
#

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

shy dove
#

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?

opal cloud
shy dove
#

and you are getting a pi_XXXXXX looking value?

opal cloud
#

Yes pi_3OIIfDKLtaCvVZSR157fFmDp

#

was the latest one I tried

shy dove
#

Okay and how are you initializing the React Native SDK? What Publishable Key are you using? Wait... this is the connection token, correct?

opal cloud
#

Correct

shy dove
#

Okay and did you log the connection token you used with pi_3OIIfDKLtaCvVZSR157fFmDp?

opal cloud
#

It is the secret key on the server

shy dove
#

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

opal cloud
#

Is the one associated with that pi

shy dove
#

Sorry that looked like a live key, so I deleted it

#

We never share API keys. Only Stripe Object IDs

opal cloud
#

Yes, sorry.

#

What would the connection token look like?

shy dove
#

Oh wait, I might have jumped the gun there. Here's an example of what the connection token secret looks like pst_test_my0Ta77WIFJD2zdPEnQXjiS

opal cloud
#

pst_live_YWNjdF8xSENFaE9LTHRhQ3ZWWlNSLHlMYzBraEJDcG5aNm5OYmxJNE9kOVNiZmdGaWFYR2Y_00CYoL2h8Q

#

Sorry, I should switch back to the test account.

shy dove
#

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

opal cloud
#

Cool

shy dove
#

Alright that is also looking good. And the reader you are using is registered at the location you are providing?

opal cloud
#

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.

shy dove
#

OH Yeah you need to use one specific location ID and the physical reader needs to be registered at that location.

opal cloud
#

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.

shy dove
#

You can try that location ID. As long as it's a location associated with the Connected Account where all of this is happening

opal cloud
#

Ok, I'll try that and report back. It might be tomorrow. Should I open a new thread if I run into issues?

shy dove
#

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

opal cloud
#

Awesome, thanks for your help.