#RGRTHAT
1 messages · Page 1 of 1 (latest)
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
Can you share the actual query string?
@near spindle are u there?
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.
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}\'`
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?
but it seems like stripe.customer.search will only search for platform customers? and not customers attached to connected accounts?
they didnt, but i passed the object wrong. Now i see in dashboard that the metadata is saved
Oh...Oh oh oh
When i console.log the query it looks like so ```js
name:'buyer' AND metadata['connected_account_id']:'acct_1LkrA8RPUOjoLmAA'
You want to search the Connect accounts Customers? Sorry that wasn't clear
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
Sorry I'm still not 100% clear on this situation. Does the Customer record exist on your account or not?
👋 stepping in as Snufkin needs to step away
Did you figure this out @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
Search data takes time to propogate
We do not recommend using it for Read then Write
We mention that in our API Ref: https://stripe.com/docs/api/customers/search
So newly created Customers will not be Searchable immediately
How am I supposed to check if customer alreadyExist so that i dont create a new customer for every single paymentIntent?
currently every paymentIntent I clone my platform customer into a connected account customer
Or, you list customers
The standard route would be to use your own database for this though
in my database i would need a array of customer ids then
cuz the customer will have 1 id per connected account
I mean yeah there are various ways to store the data
damn this got more complicated then i thought
cant i just create 1 customer every single paymentIntent? just give a fuck
Sure, you can.
i see that stripe detect that its the same customer anyways
Just won't really be clean
same metadata, same paymentMethod, etc
When you say "detect" you mean via the related payments?
Yeah that won't really help you if you are trying to do reporting/analysis in the future
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
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
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?
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
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
Let's back up a sec. You are using Direct Charges with cloning, right?
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?
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
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
How do u search the connected Account A specifically?
You make the request on the Connected Account using the Stripe Account header: https://stripe.com/docs/connect/authentication#stripe-account-header
Wow thats smart
That would work i guess