#ranran-event-casting

1 messages ยท Page 1 of 1 (latest)

timid basaltBOT
north aspen
#

@light veldt do you have an Event id evt_123?

#

ranran-event-casting

light veldt
north aspen
#

Sure, can you share that exact Event id here so I can have a look?

light veldt
north aspen
#

Are you using the CLI? Are you sure you get the correct version of the Event? I assume the Event you get has the wrong API version

light veldt
#

Although the previous tests that I performed already receiving the answers from the development environment gave me the same problem.

north aspen
#

If you log what you get, check the exact API version I assume you get the wrong version of the Event on your endpoint

light veldt
north aspen
#

Where do you see that exactly though? Sorry I don't see your computer so I need you to try and be explicit and explain exactly what you're getting, how you are debugging

light veldt
north aspen
#

Ah perfect thanks, so you do get the correct information. So what's the issue? What error do you get when calling ConstructEvent exactly?

#

or is that picture right after that call?

light veldt
#
var stripeEvent = EventUtility.ConstructEvent(
    json,
    Request.Headers["Stripe-Signature"], 
    webhook_secret
);

// OKEY

if (stripeEvent.Type == Events.InvoicePaymentSucceeded) // OKEY
{
    var stripeInvoice = stripeEvent.Data.Object as Stripe.Invoice; // ERROR - Here is the problem

    // stripeInvoice.BillingReason -> null Exception 
}
#

Despite receiving a correct response that line of code does not assign any value to my stripeInvoice variable.

north aspen
#

Yeah I assume you have something on the Invoice object that isn't compatible with that version of stripe-dotnet (which is 4 years old).

#

Unfortunately I'm not sure what that is. When you get that error you should see a clearer exception/problem

light veldt
#

I have tried to catch an exception in that line but it does not jump any.

I understand that it could be a problem with the version and that updating to the latest version v41.24.0 should solve it.

#

I understand that there must be some page where you can find out according to the API version which version of stripe-dotnet or other implementations can be used.
Although I have not been lucky enough to find it.

north aspen
#

I don't think the API version per se is the issue here. More likely that this is really old and you have something on the Invoice resource preventing the compatibility. Is there a reason you're using such an old version of the library?

#

(I'm trying to see if I can repro but will take a bit of time)

light veldt
#

It is an inherited project in which at this moment I have had to make changes in this part.

Before updating the package I wanted to see if I had made a mistake, but I guess I'll have to update .

north aspen
#

for what it's worth I tried your exact code and it works fine for me

#

var stripeEvent = EventUtility.ParseEvent(json, true);

Console.WriteLine(stripeEvent.Id);


if (stripeEvent.Type == Events.InvoicePaymentSucceeded)
{
    var stripeInvoice = stripeEvent.Data.Object as Stripe.Invoice; // Dont work

        Console.WriteLine(stripeInvoice.Id);

    // stripeInvoice.BillingReason -> null
}```
#

I copy-pasted the exact raw JSON from the Event (and replaced all the " with ') and it works fine and prints the Invoice id as expected

#

Can you try logging the .Id like I did?

light veldt
#

One moment, I'll try it now

#

mmm it worked for me

#

I don't understand why

The problem seems to be in EventUtility.ConstructEvent.

north aspen
#

๐Ÿ˜… I thought you said that worked fine? I'm confused

light veldt
#
var json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync();

var stripeEventJSon = EventUtility.ParseEvent(json, true);

if (stripeEventJSon.Type == Events.InvoicePaymentSucceeded)
{
    var stripeInvoicev2 = stripeEvent.Data.Object as Stripe.Invoice;

    var id = stripeInvoicev2.Id; // Has value and i can access
}
#

With that now my variable stripeInvoicev2 gives me access to the properties and their values as expected

north aspen
#

Sure but earlier I asked explicitly if ConstructEvent worked and you said yes right?

light veldt
#

I'm actually using ConstructEvent elsewhere
in which I have a I have a cast as follows

var session = stripeEvent.Data.Object as Session;

and it works

north aspen
#

Hum this is really strange

north aspen
#

especially if you say it's the same exact JSON

light veldt
#

Exactly.

Maybe some kind of bug that they fixed in some later version of stripe-dotnet than the one I'm using.

timid basaltBOT
north aspen
#

maybe but ConstructEvent is supposed to just be checking the signature + ParseEvent

#

I still think upgrading is a better path forward but I really don't see how the ConstructEvent could succeed but then the cast would fail

light veldt
#

I think I have it

#
public static Event ConstructEvent(string json, string stripeSignatureHeader, string secret, long tolerance = 300, bool throwOnApiVersionMismatch = true);
public static Event ConstructEvent(string json, string stripeSignatureHeader, string secret, long tolerance, long utcNow, bool throwOnApiVersionMismatch = true);
public static Event ParseEvent(string json, bool throwOnApiVersionMismatch = true);
public static void ValidateSignature(string json, string stripeSignatureHeader, string secret, long tolerance = 300);
public static void ValidateSignature(string json, string stripeSignatureHeader, string secret, long tolerance, long utcNow);
#

the parameter "throwOnApiVersionMismatch".

tepid sky
#

๐Ÿ‘‹ stepping in as koopajah needed to step away

#

Sounds like you have a mismatch of pinned SDK version vs. Event API Version, is that right?

light veldt
#

I don't know what happened

#

I have retested the way I had it.
A whole afternoon with that problem and now it works.
( In fact in the form that koopajah asked me to test, I had a bug that basically kept using the variable that ConstructEvent returns to me to do the casting )

tepid sky
#

Hmm odd

#

But glad it is working...

light veldt
#

Yes, it started working after trying the other way, using EventUtility.ParseEvent.
It is really strange.
Thank you very much for your time and support and sorry for the inconvenience.