#dobezilla_code

1 messages · Page 1 of 1 (latest)

coarse marlinBOT
#

👋 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/1488528296252669982

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

placid stratus
#

Hey there, can you share a widened snippet of code and which specific SDK versions you went from/to?

proper valve
#

Hi yes it's this:
private async Task<(bool, ResponseVM)> HandleStripeEvent(string json, string webhookSecret)
{
ResponseVM responseVM = new();
var stripeEvent = EventUtility.ConstructEvent(json, Request.Headers["Stripe-Signature"], webhookSecret);
//var stripeEvent = EventUtility.ParseEvent(json);
bool sendSysAdminEmail = false;
switch (stripeEvent.Type)
{
//The customer has successfully authorized the payment by submitting the Checkout form.
case EventTypes.CheckoutSessionCompleted:
responseVM = await HandleCheckoutSessionCompleted(stripeEvent);
break;
//The customer’s payment succeeded.
case EventTypes.CheckoutSessionAsyncPaymentSucceeded:
responseVM = await HandleCheckoutPaymentSucceeded(stripeEvent);
break;
//The payment was declined, or failed for some other reason.
case EventTypes.CheckoutSessionAsyncPaymentFailed:
responseVM = await HandleCheckoutPaymentFailed(stripeEvent);
break;
case EventTypes.InvoicePaymentSucceeded:
responseVM = await HandleInvoicePaymentSucceeded(stripeEvent);
break;
case EventTypes.InvoicePaymentFailed:
//notify customer and connected account holder
responseVM = await HandleInvoicePaymentFailed(stripeEvent);
break;
}
_logger.LogInformation(responseVM.Message);
return (sendSysAdminEmail, responseVM);
}

#

and then this
private async Task<ResponseVM> HandleInvoicePaymentSucceeded(Event stripeEvent)
{
_logger.LogInformation($"Starting {nameof(HandleInvoicePaymentSucceeded)} in {nameof(StripeWebHookController)}");
var responseVM = new ResponseVM();
if (stripeEvent.Data.Object is Invoice invoice && !string.IsNullOrEmpty(invoice.SubscriptionId))
{
responseVM.IsSuccess = true;
if (stripeEvent.Livemode)
{
var expirationDateRequest = new ExpirationDateUpdateRequestVM
{
StripeSubscriptionId = invoice.SubscriptionId,
ExpirationDate = DateTime.UtcNow.AddMonths(1)
};
responseVM = await _repository.UpdateExpirationDate(expirationDateRequest);
}
responseVM.Message += $" {nameof(HandleInvoicePaymentSucceeded)} completed successfully.";
}
_logger.LogInformation(responseVM.Message);
return responseVM;
}

placid stratus
#

Thanks

#

What SDK version are you moving from and what version are you using now?

proper valve
#

from 47.4.0 to 51.0.0 - these were the nuget package versions

placid stratus
#

ok and what exactly is the compile/type error you're hitting now?

proper valve
#

'Invoice' does not contain a definition for 'SubscriptionId' and no accessible extension method 'SubscriptionId' accepting a first argument of type 'Invoice' could be found (are you missing a using directive or an assembly reference?)

coarse marlinBOT
placid stratus
#

ok so its an issue with invoice.SubscriptionId not stripeEvent.Data.Object correct?

proper valve
#

yes - can't find info about removing subscriptionId on the invoice object in any of the changelogs

placid stratus
#

It's not removed, invoices still have a subscription reference when applicable

proper valve
placid stratus
#

Apparently i am mistaken -- rereading, bear with me

#

ah right, its not removed, but it have been moved into a parent hash because this now accounts for other potential "parent" objects like quotes etc

proper valve
#

invoice.Parent.SubscriptionDetails.SubscriptionId - I found it!!!! Thank You!!

placid stratus
#

NP!

proper valve
#

Have great day!

#

As it happens the only other error I'm getting is on file upload, which has now broken, but the example in the docs is as I have it in my code, which has been fine up to this point:
private async Task<string> UploadLogo(byte[] imageBytes)
{
using var stream = new MemoryStream(imageBytes);

var options = new FileCreateOptions
{
    File = stream,
    Purpose = FilePurpose.BusinessLogo
};
var service = new FileService();
var upload = await service.CreateAsync(options);
return upload.Id;

}

whereupon I now get this: Cannot implicitly convert type 'System.IO.MemoryStream' to 'Stripe.MultipartFileContent'

the docs I'm looking at are here
https://docs.stripe.com/file-upload

A guide for uploading files securely to Stripe for dispute evidence, KYC documents, and other purposes.

jovial wing
#

hi there, I'm taking over for synthrider as they had to step away. can you tell me what line in your code is throwing that error?

proper valve
#

yes it's on the FileCreateOptions, saying that the File property (File = stream) cant be converted to a multipartFileContent

jovial wing
#

the example in the doc you linked looks like this to me:

var filename = "/path/to/a/file.jpg";
using (FileStream stream = System.IO.File.Open(filename, FileMode.Open))
{
    var options = new FileCreateOptions
    {
        File = stream,
        Purpose = FilePurpose.DisputeEvidence,
    };
    Stripe.File upload = client.V1.Files.Create(options);
}

have you tried it using this Filestream example instead of using MemoryStream?

proper valve
#

yes I tried that it said the same thing about a filestream as well

jovial wing
#

hmm ok, looking into it. it's been awhile since I used .NET but I'm going to try to implement this and see if I can figure it out

proper valve
#

actually this looks like it might work
var mpfc= new MultipartFileContent
{
Data = stream,
Name = "logo.png",
Type = "image/png"
};
var options = new FileCreateOptions
{
File = mpfc,
Purpose = FilePurpose.BusinessLogo
};

jovial wing
#

was just about to suggest that, based on what Claude is telling me 😄