#carrotfertilitysupport_api
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/1216852619658657862
đ 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.
- carrotfertilitysupport_api, 6 days ago, 26 messages
Additional info: We are working on a project (using AWS Serverless SAM) to create and send invoices to members. We are doing the following in an AWS Lambda that interacts with Stripe's API:
- Getting a customer using
stripe.customers.searchto extract a uniqueemployeeIdvalue from the customer's metadata- update the customer with
stripe.customers.updateif they already exist - create the customer with
stripe.customers.createif they don't exist
- update the customer with
- Creating an invoice
- Sending an invoice
This all works as intended however we've noticed that if we create a test event to trigger this lambda and send that event multiple times within a short amount of time (with changes to the data - NOT theemployeeIdthough) it will create duplicate customers even when that value we are checking (when usingstripe.customers.searchstays the same). If we wait a little over a minute or so, however, the update behavior works correctly and does not create additional dupes.
Question is: is this happening on Stripe's end? Is there some sort of delay behavior we should be implementing to prevent these duplicates from being created?
The flow to trigger this dupe behavior is:
- trigger a an event with a new employee id
- see a customer created in stripe
- quickly trigger another event (use resend function) with that same employee id in the metadata but change the email and/or name
- see a duplicate customer created in stripe
- Dupe example 1: https://dashboard.stripe.com/test/customers/cus_PigvWgtv4E3V2P
- Dupe example 2: https://dashboard.stripe.com/test/customers/cus_Pigv7wo7vqMcsC
Give me some time to catch up that's a lot of text!
deepest apologies, lol - i tried to format it more clearly outside of here before copying it in and it all went to hell
all good I think it's great, just taking over Discord so taking a few minutes to catch up but I'll be right back
Okay so we (Stripe) do not have any logic to de-duplicates Customers on any criteria. This is something your own code would fully own here when you call the Create Customers API yourself https://docs.stripe.com/api/customers/create
So if there are 2 separate Customers created it's because your code explicitly created those
I've been combing through our code and it does look like we are only creating a customer if the following function doesn't return any associate customer object from Stripe:async function getCustomer(employeeId, stripe) { console.log('searching for customer') const searchResult = await stripe.customers.search({ query: `metadata[\'employee_id\']:\'${employeeId}\'`, }); return searchResult.data ? searchResult.data[0] : null; }
and it will correctly update a customer if they already exist if we wait maybe a minute or so between separate requests to the api
The Search API is not real time though, did you realize that? You really can't rely on that API to do de-duplication in any way
ah
so that's probably the issue - i didn't implement that function so didn't do a deep dive on it
is there a better way/function for retrieving that data or is the search function the best approach (and we just need to do a more robust job on waiting for those results before taking any further action)?
The real correct way is to track this in your own database internally. No other canonical way to avoid duplicate Customers otherwise.
Ah, okay - that tracks with some of the stuff I was finding searching around about this. This is super helpful and I think answers my questions on this. Really appreciate your help! (and apologies again for the epic explainer lol)