#linqisnice_docs
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/1222832625878831207
đ 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.
- linqisnice_best-practices, 10 hours ago, 11 messages
- linqisnice_docs, 13 hours ago, 32 messages
- linqisnice_best-practices, 16 hours ago, 24 messages
- linqisnice_best-practices, 17 hours ago, 13 messages
- linqisnice_docs, 23 hours ago, 21 messages
- linqisnice_docs, 1 day ago, 64 messages
and 7 more
I'm doing this to set the metadata of the paymentintent, as my understanding was all checkout sessions (wehave both payment link and embedded) hav a metadata field
public async Task<StripePaymentLink> CreatePaymentLink(IEnumerable<StripeProduct> products, CurrencyCode currency, string connectedAccountId, string orderId)
{
var options = new PaymentLinkCreateOptions
{
TransferData = new PaymentLinkTransferDataOptions
{
Destination = connectedAccountId
},
LineItems = await CreatePaymentLinkLineItems(products, currency, connectedAccountId),
OnBehalfOf = connectedAccountId,
PaymentIntentData = new PaymentLinkPaymentIntentDataOptions
{
Metadata = new Dictionary<string, string>
{
{
"InternalOrderId", orderId
}
}
}
};
var paymentLink = await new PaymentLinkService().CreateAsync(options);
return new StripePaymentLink(paymentLink.Id, paymentLink.Url);
}
then I try to retrieve it as you regularly would in the webhook
if(session.PaymentIntent.Metadata.TryGetValue("InternalOrderId", out var id) && int.TryParse(id, out var val))
{
DoSomething();
}
but it throws an exception, and when i check the event in the dashboard it says there's no metadata at all in teh json request
Hi, let me help you with this.
From your code I see that you don't use Stripe Checkout, but Payment Links.
What are you actually trying to do and where do you expect to see the metadata field?
What webhook event are you listening to?
the payment link generates a checkout session, no?
i listen for stripe checkout.session.completed
and it does trigger the event
what i'm trying to do: customers pay our connected partners either via payment link or embedded c heckout session.
Ineed the webhook to associate that payment with an order in my system
listening to Events.CheckoutSessionCompleted
as both carry an underlying paymentintent, i'v ebeen told by another stripe dev, and that the metadata field should be retrievable from session.PaymentIntent.Metadata.TryGetValue("InternalOrderId", out var id)
Yes, but there's no way to set metadata on those Checkout Sessions. You either have to fetch a related Payment Link, or PaymentIntent (if you used payment_intent_data).
so there's no uniform way when creating both an embedded checkout session and payment link to relate it to an order in ym system?
i have to check if the chjeckout session* has a paymentintent or paymentlink in the webhook and relate that to what is saved in the ordeR?
If you listen to checkout.session.completed it always carries the Checkout Session object, and from it you can access the attached PaymentIntent.
For both one-off Checkout Sessions, and sessions generated by Payment Links.
Yes, and i'm setting the metadata of the paymentintent
yet its not there in the request
PaymentIntentData = new PaymentLinkPaymentIntentDataOptions
{
Metadata = new Dictionary<string, string>
{
{
"InternalOrderId", orderId
}
}
}
i do this for both paymentlink and one off checkout sessions
and then I check
session.PaymentIntent.Metadata.TryGetValue("InternalOrderId", out var id)
"cs_test_b1sxH6l1k5XLOzd8Y8OjaRtxE87Nsik5w9S0sQBcqRgt9IYnv0Rb7kXpyz",
metadata is empty
Are you expanding the PaymentIntent property? Otherwise, it's just the PaymentIntent ID as a string.
Because I can see the metadata on the PaymentIntent object.
Expanding it where? when checking its metadata or creating it?
this is the one off checkout session
var options = new SessionCreateOptions
{
LineItems = await CreateSessionLineItems(products, currency, connectedAccountId),
UiMode = "embedded",
Mode = "payment",
ReturnUrl = $"{_baseUriProvider.GetBaseUri(BaseUriOptions.Anigma)}/return?session_id={{CHECKOUT_SESSION_ID}}",
PaymentIntentData = new SessionPaymentIntentDataOptions
{
OnBehalfOf = connectedAccountId,
TransferData = new SessionPaymentIntentDataTransferDataOptions
{
Destination = connectedAccountId
},
Metadata = new Dictionary<string, string>
{
{
"InternalOrderId", orderId
}
}
}
};
and payment link
var options = new PaymentLinkCreateOptions
{
TransferData = new PaymentLinkTransferDataOptions
{
Destination = connectedAccountId
},
LineItems = await CreatePaymentLinkLineItems(products, currency, connectedAccountId),
OnBehalfOf = connectedAccountId,
PaymentIntentData = new PaymentLinkPaymentIntentDataOptions
{
Metadata = new Dictionary<string, string>
{
{
"InternalOrderId", orderId
}
}
}
};
i'm expecting that i can just check the sessions paymentintents metadata to get the orderId,but that doesnt seem to work
so what should I be doing here to relate both of these to an order in the same webhook?
When you receive the checkout.session.completed event, it contains the Checkout Session object. However, its payment_intent property is just a string. You need to fetch the full PaymentIntent object to access its metadata
You can just fetch the PI object by ID: https://docs.stripe.com/api/payment_intents/retrieve
hmm okay sec
are you sure it's a string?
its a complex type, not jsut a string
Can you access PaymentIntent.Amount for example?
yes
And can you print the full metadata?
I have a bit of an issue, haven't set up remote logging yet and I'm not sure how to include metadata in a CLI stripe trigger request, is that possible?
is there a way to get the paymentintent underlying the payment link upon creating the paymentlink? if so i coudl just save the paymentintent id to the order isntead and use that instead of metadata
sec
let me see if ic an retrieve the session manually and print the paymentintent metadata instead
If you set up a local listener, you will get events from actual Test mode events forwarded to your local instance.
I guess the question is if you're getting it in the webhook event payload
ah ok thanks
are u sure that will work? i've tested my webhooks like this before, but that doesn't trigger my actually flow where i programmatically set the metadata of hte payment intent
how would i emulate that in the CLI?
I know i can hit a breakpoint but won't it be with just "test" data
Are you creating those Payment Links in Test mode? You should receive every Test mode event via this CLI tool
Test mode, but I'm generating the payment links programmatically, and then i'm paying via the actual link wtih test card
this won't hit my breakpoints locally
but im running the cli now
not entirely sure what to do now to hit the local breakpoint
i assume i can trigger one of the failed events here from the cli?
using the session id
Could youy please share an example event? It must hit your local listener too.
evt_1OzFlmGPWwmX339ck0wlbVJe
I want to retrigger this event, this was created from an actual payment link in test mode, not via the CLI
i want to hit a breakpoint so i can see if theres any metadata. But i think a better solution would be some other way to just relate an ORDER in my system to a stripe checkout
i did try stripe event resend evt_1OzFlmGPWwmX339ck0wlbVJe in the cli, but i get the wrong secret
maybe just using ParseEvent will work
I see this event is sent to your local listener.
What's the exact error you're seeing?
yes and it sohuld be the same event triggered by the payment link, right? so i can debug and see if theres metadata as i expect it to be in the paymentintent object?
so ok the paymentintent is null
i see tehres a paymentintentId, is it possible to get that when the payment link is first created?
and save that to the order?
or do i need to save both the payment link id and paymentintent id to the order depending on if it was a one off checkout or payment link generated checkout?
What I see here is that there's both IDs but not actual objects, as I suspected. You need to fetch them separately.
u mean like this?
var paymentIntent = stripeEvent.Data.Object as PaymentIntent;
ah nvm i understand what u mean, use the stripe API to fetch it
using the id
ahh that works! thanks a lot!!
Happy to help.