#carrotfertilitysupport_api

1 messages ¡ Page 1 of 1 (latest)

uneven pelicanBOT
#

👋 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.

lucid quartzBOT
#

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.

marble flower
#

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.search to extract a unique employeeId value from the customer's metadata
    • update the customer with stripe.customers.update if they already exist
    • create the customer with stripe.customers.create if they don't exist
  • 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 the employeeId though) it will create duplicate customers even when that value we are checking (when using stripe.customers.search stays 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:

  1. trigger a an event with a new employee id
  2. see a customer created in stripe
  3. quickly trigger another event (use resend function) with that same employee id in the metadata but change the email and/or name
  4. see a duplicate customer created in stripe
lucid quartzBOT
daring portal
#

Give me some time to catch up that's a lot of text!

marble flower
#

deepest apologies, lol - i tried to format it more clearly outside of here before copying it in and it all went to hell

daring portal
#

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

marble flower
#

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

daring portal
#

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

marble flower
#

ah

daring portal
marble flower
#

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)?

daring portal
#

The real correct way is to track this in your own database internally. No other canonical way to avoid duplicate Customers otherwise.

marble flower
#

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)