#speakofthedevo

1 messages · Page 1 of 1 (latest)

crystal yachtBOT
north heart
#

Is it possible to do this with a precreated paymentLink or do I need to create a new paymentLink and include this infor in the metadata?

random hollow
north heart
#

Are there any issues with race conditions here? Like what if I have 2 customers going thru this process, Customer1 updates the paymentLink with their ID, then opens the page

Customer2 at a close time updates the paymentLink with their ID then opens the page

Will customer1's paymentLink no longer have the correct ID associated with them?

random hollow
#

Hmm, no. If you have 2 different customers who clicked on the Payment Link, each one would have their own session id which would look something like this, cs_ I highly recommend that you test this in your developer environment.

north heart
#

Would a safer route be to use the Checkout API?

random hollow
#

Payment Links use Checkout under the hood that is why a checkout session is created

north heart
#

Okay understood, so then I guess my question is really, does stripe.paymentLinks.update update the same paymentLink object?

#

If I call

const paymentLink = await stripe.paymentLinks.update(
  'plink_1MhiesDOt6FqucveASTM4if7',
  metadata: {
    user_id: "asdfjkahsdf"
  }
);

multiple times, it's going to keep updating the paymentLinks metadata field with the latest user_id right?

#

How can I be certain that when my webhook catches checkout.session.completed the metadata.user_id will correspond to the correct user that just paid?

random hollow
#

Yeah, it updated the payment link object.

#

Why are you making the same call multiple times?

#

When you update the payment link, plink_1MhiesDOt6FqucveASTM4if7 the metadata user_id: "asdfjkahsdf" will be attached to that payment link object.

north heart
#

I would be calling update for each customer that clicks the link

#

How would updating custom_field be any different than updating metadata if every customer would be calling paymentlink.update?

random hollow
#

That does not work this way.

north heart
#

and pass metadata in during the creation? So each checkout session would be unique

random hollow
#

With Payment Link each checkout session will be unique like if you were using the Checkout API. I think we are talking crossed each other.. Let's back up.

north heart
#

Sorry for the misunderstanding

random hollow
#

Would this user_id come from the end user or you?

north heart
#

What do you mean by that? It is NOT something the user provides on their own. When they click "submit", and database entry is added on the backend and that backend function returns a documentID (same thing as user_id in this example) I want to be able to send that ID to the paymentLink object so that it knows about that ID when the checkout session is completed and the webhook hits

random hollow
#

Ok, in this case, the Payment Link metadata will not work. If you set the metadata there, it would only be on the Payment Link object.

You want this metadata to be unique to each customer. So what would better fit in this case is Checkout, https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-metadata. When you create the Checkout, you pass the metadata. This metadats will contain what you passed when you created it so it's unique to what you pass there for each customer. I think we are not on the same page.

north heart
#

Understood. Checkout session it is. Sorry for so much back and forth, but thank you for the help