#RGRTHAT

1 messages · Page 1 of 1 (latest)

mild yachtBOT
pallid vault
#

the customer i try to search for is a customer attached to a connected account

#

My query doesnt find the customer attached to connected account

near spindle
#

Can you share the actual query string?

pallid vault
#

@near spindle are u there?

near spindle
#

Sorry there are multiple people asking questions

#

So you are saying the customer you create does not contain the metadata you are searching for?

#

The error messages are lacking context so it's hard for me to understand what is is that is going wrong here.

pallid vault
#

I try to use ```js
stripe.customer.search to find a customer that is attached to a connected account

#
`name:\'${req.user.name}\' AND metadata[\'connected_account_id\']:\'${service.stripe_account_id}\'`
near spindle
#

Right.. and I think you said that when you look at the customer in question, their record doesn't appear to have the metadata you expect, right?

pallid vault
#

but it seems like stripe.customer.search will only search for platform customers? and not customers attached to connected accounts?

pallid vault
near spindle
#

Oh...Oh oh oh

pallid vault
#

When i console.log the query it looks like so ```js
name:'buyer' AND metadata['connected_account_id']:'acct_1LkrA8RPUOjoLmAA'

near spindle
#

You want to search the Connect accounts Customers? Sorry that wasn't clear

pallid vault
#

Right before a paymentIntent, I clone a platform customer & create a paymentMethod, and add that to a paymentIntent

#

but i dont want to create a new customer every paymentintent, so i have a conditional

#

so i need to check if a customer already exist, where fks name is equal to customer name, and then where connected_account_id is equal to the connected account

near spindle
#

Sorry I'm still not 100% clear on this situation. Does the Customer record exist on your account or not?

fast pasture
#

👋 stepping in as Snufkin needs to step away

#

Did you figure this out @pallid vault ?

pallid vault
#

im trying

#

10 sec

#
let query = `metadata["connected_account_id"]:"${service.stripe_account_id}"`;

        console.log("query", query);

        const alreadyExist = await stripe.customers.search({
          query,
        });
```The first payment it doesnt fint it ofcourse. 2nd time it still dont find the customer when querying
#
metadata["connected_account_id"]:"acct_1LkrA8RPUOjoLmAA"
#

Wierd it cant find back the customer that is newly created

fast pasture
#

Search data takes time to propogate

#

We do not recommend using it for Read then Write

#

So newly created Customers will not be Searchable immediately

pallid vault
#

How am I supposed to check if customer alreadyExist so that i dont create a new customer for every single paymentIntent?

fast pasture
#

You store this information in your own database

#

And check against your database

pallid vault
#

currently every paymentIntent I clone my platform customer into a connected account customer

fast pasture
#

Or, you list customers

#

The standard route would be to use your own database for this though

pallid vault
#

in my database i would need a array of customer ids then

#

cuz the customer will have 1 id per connected account

fast pasture
#

I mean yeah there are various ways to store the data

pallid vault
#

damn this got more complicated then i thought

#

cant i just create 1 customer every single paymentIntent? just give a fuck

fast pasture
#

Sure, you can.

pallid vault
#

i see that stripe detect that its the same customer anyways

fast pasture
#

Just won't really be clean

pallid vault
#

same metadata, same paymentMethod, etc

fast pasture
#

When you say "detect" you mean via the related payments?

pallid vault
#

i would like it clean, but when things get messy like this idk what to do..

#

yup

fast pasture
#

Yeah that won't really help you if you are trying to do reporting/analysis in the future

pallid vault
#

also when i look in payments, the customer_id is replaced with the email

#

so it seems to collerate the new customers all the time

fast pasture
#

I would recommend either listing Customers to check if one has already been created with that email

#

Or storing it in your own database and checking against that

#

And maintaining one Customer record per actual customer for the Connected Account

#

But overall this is completely up to you

pallid vault
#

i dont think u understand. Cuz say I have 100 connected accounts or 1000s

#

1 account on my website will then have 100s or 1000s of connected customer ids

#

because each customer needs to be attached to the connected account

#

so therefore i cant just check for email

#

cuz it will be 1000s of customers with same email

#

i need to check 2 props. Email & connected account id in metadata

#

but as u cant fetch customers in real time apperently, this will be tricky.

#

@fast pasture u see?

fast pasture
#

You can "fetch" customers in real time

#

You list them instead of Search them

#

However, if you have many customers then this will take time as you have to use pagination

#

Which is why it is recommended to store this in your own database and query that instead

pallid vault
#

email is unique identifier for the website account, but as 1 account will have multiple customer_ids. I id per connected account they interact with. If i use the list query, then i will first have to query based on email, and then filter based on metadata value

fast pasture
#

Let's back up a sec. You are using Direct Charges with cloning, right?

pallid vault
#

yup

#

i use connected accounts

#

connected account paymentintent

fast pasture
#

Okay and what you want to accomplish is that when someone comes to your site and wants to pay Connected Account A, you want to check whether that person already has a Customer on your platform (and know if they have any saved payment methods) and whether they have a Customer on Connected Account A already (and any saved payment methods), correct?

pallid vault
#

Yes

#

Exactly

#

Originally when a user create account on my website they get a simple platform customer

#

Then at every paymentIntent i clone this customer and attach to paymentMethod and attach to a connect account A

fast pasture
#

Okay and why does metadata matter here, exactly? If you don't want to store this in your database, then you just make two Customer List requests: one on your platform with that email, and one on Connected Account A with that email.

#

You actually don't need to paginate at all

#

And it should be pretty fast

#

Since you are just going to use email as the identifier

pallid vault
#

How do u search the connected Account A specifically?

fast pasture
pallid vault
#

That would work i guess