#linqisnice_docs

1 messages ¡ Page 1 of 1 (latest)

winged pierBOT
#

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

lyric valleyBOT
#

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.

grizzled sphinx
#

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

rare ruin
#

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?

grizzled sphinx
#

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)

rare ruin
grizzled sphinx
#

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?

rare ruin
#

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.

grizzled sphinx
#

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

rare ruin
#

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.

grizzled sphinx
#

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?

rare ruin
#

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

grizzled sphinx
#

hmm okay sec

#

are you sure it's a string?

#

its a complex type, not jsut a string

rare ruin
#

Can you access PaymentIntent.Amount for example?

grizzled sphinx
#

yes

rare ruin
#

And can you print the full metadata?

grizzled sphinx
#

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

rare ruin
rare ruin
grizzled sphinx
#

let me see if i can fix that

#

ill download ngrok and try it out real quick sec

rare ruin
#

You don't need that even. You can use Stripe CLI: stripe listen

grizzled sphinx
#

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

rare ruin
grizzled sphinx
#

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

rare ruin
grizzled sphinx
#

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

rare ruin
#

I see this event is sent to your local listener.

rare ruin
grizzled sphinx
#

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?

rare ruin
# grizzled sphinx

What I see here is that there's both IDs but not actual objects, as I suspected. You need to fetch them separately.

grizzled sphinx
#

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

grizzled sphinx
#

ahh that works! thanks a lot!!

rare ruin
#

Happy to help.