Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • anh-duc-le 38 posts 152 karma points
    Nov 07, 2022 @ 13:48
    anh-duc-le
    0

    U10 - Vendr 3.0.3 - SendFinalizedOrderEmail throws empty To array exception

    After our upgrade to Umbraco 10 and Vendr 3.0.3 we've been getting the following error when finalizing an order from within the backend code.

    System.AggregateException: AsyncHelper.RunSync method threw an exception. (Value cannot be an empty array. (Parameter 'to'))
     ---> System.ArgumentException: Value cannot be an empty array. (Parameter 'to')
       at Umbraco.Cms.Core.Models.Email.EmailMessage.ArgumentIsNotNullOrEmpty(String[] arg, String argName)
       at Umbraco.Cms.Core.Models.Email.EmailMessage..ctor(String from, String[] to, String[] cc, String[] bcc, String[] replyTo, String subject, String body, Boolean isBodyHtml, IEnumerable`1 attachments)
       at Vendr.Extensions.MailMessageExtensions.ToEmailMessage(MailMessage message)
       at Vendr.Umbraco.Mail.UmbracoEmailSender.SendAsync(MailMessage message)
       at Vendr.Core.Pipelines.Email.Tasks.SendEmailTask.<>c__DisplayClass3_0.<Execute>b__0()
       at Vendr.Common.Helpers.AsyncHelper.<>c__DisplayClass1_0.<<RunSync>b__0>d.MoveNext()
       --- End of inner exception stack trace ---
       at Vendr.Infrastructure.Resiliency.PollyExecutionStrategyBase.Execute[TResult](Func`1 operation, Func`1 verifySucceeded)
       at Vendr.Core.Services.EmailTemplateService.SendEmail[TModel](EmailTemplateReadOnly emailTemplate, TModel model, String toEmailAddress, String languageIsoCode)
       at Vendr.Core.Services.EmailTemplateService.SendEmail(EmailTemplateReadOnly emailTemplate, OrderReadOnly order)
       at Vendr.Core.Events.Notification.Handlers.Order.SendFinalizedOrderEmail.Handle(OrderFinalizedNotification evt)
    

    We use the following code for finalizing an order from the backend:

    OrderReadOnly? order = null;
    
    var store = this.vendrApi.GetStore(Constants.StoreAlias);
    
    var currentOrder = this.vendrApi
        .GetOrCreateCurrentOrder(store.Id);
    
    this.vendrApi.Uow.Execute(uow =>
    {
        var writableOrder = currentOrder.AsWritable(uow);
    
        var properties = new Dictionary<string, string>
        {
            { Vendr.Core.Constants.Properties.Customer.EmailPropertyAlias, emailAddress },
            { Vendr.Core.Constants.Properties.Customer.FirstNamePropertyAlias, firstName },
            { Vendr.Core.Constants.Properties.Customer.LastNamePropertyAlias, lastName },
        };
    
        writableOrder.SetProperties(properties);
    
        var paymentMethod = this.vendrApi.GetPaymentMethod(store.Id, paymentMethodAlias);
        writableOrder.SetPaymentMethod(paymentMethod);
    
        order = writableOrder.InitializeTransaction(this.orderNumberGenerator);
        writableOrder.Finalize(0, currentOrder.TransactionInfo.TransactionId, PaymentStatus.Captured);
    
        this.vendrApi.SaveOrder(writableOrder);
    
        uow.Complete();
    }
    

    What do I need to change to not get that error anymore?

    This bit of code is used in a userflow where we've been fine with not sending order confirmation emails in the past. It did not send emails, but it also did not complain in the logs about it.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Nov 07, 2022 @ 14:41
    Matt Brailsford
    0

    I guess it depends how your Order Confirmation email is setup as I'm assuming it's this that is failing.

    It would suggest there is no to address being passed to it, so you'd either need to configure a to address in your email template settings, or ensure it's "Send to customer" option is checked which should then fetch the email address from the order object

  • anh-duc-le 38 posts 152 karma points
    Nov 07, 2022 @ 16:11
    anh-duc-le
    0

    Yeah that is the odd thing, the template configs seem to be fine.

    Send to Customer is enabled

    Could it be that the order gets finalized and tries to send out the order confirmation email before the customer email property is saved on the order?

    writableOrder.Finalize(0, currentOrder.TransactionInfo.TransactionId, PaymentStatus.Captured);
    
    this.vendrApi.SaveOrder(writableOrder);
    

    The issue only exists when I try to finalize an order through the above code bit.

    Orders finalized through the default checkout flow are totally fine.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Nov 08, 2022 @ 10:18
    Matt Brailsford
    100

    Hmmm, it should be fine really.

    I've had a look through our codebase and I've made a small change that could affect this, but I'm not 100% positive it is the issue at hand.

    If you are able, we have a Vendr 3.0.5-beta0001 on our unstable NuGet feed at https://nuget.outfield.digital/unstable/vendr/v3/index.json If you could try that and see if it changes anything that would be realy useful.

  • anh-duc-le 38 posts 152 karma points
    Nov 08, 2022 @ 13:01
    anh-duc-le
    0

    Yes! After updating to 3.0.5-beta0001 it no longer throws the exception in the logs.

    It also doesn't send the confirmation email, but that is fine as that is how it ran before the update. :)

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Nov 08, 2022 @ 13:07
    Matt Brailsford
    0

    Interesting.

    Thanks for confirming 👍

  • anh-duc-le 38 posts 152 karma points
    Nov 08, 2022 @ 13:08
    anh-duc-le
    0

    Do you have any indication on when we can expect 3.0.5 to get a stable release?

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Nov 08, 2022 @ 13:09
    Matt Brailsford
    0

    I only just released 3.0.4 today so it'll be at least a week while I wait to see if any other issues pop up.

    You should be fine to use the beta for the time being though as that is the first bug fix in that build so should be as stable as the current 3.0.4 release.

  • Frans Lammers 57 posts 400 karma points c-trib
    Nov 15, 2023 @ 13:09
    Frans Lammers
    0

    This is an old subject, but I would like to reopen it, since we do get the same errormessage at each OrderConfirmation we send. In Umbraco 10.5.1 and Vendr 3.0.11.

    The OrderConfirmations are getting send and to the right address, so there is nothing going wrong in the process, but these errors really are clogging up our logs.

    Is there anything I can do to stop these messages from showing up?

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Nov 15, 2023 @ 14:13
    Matt Brailsford
    0

    If your emails are being sent, but the error is still being logged, it sounds like it is a different issue as the original post was about not providing an to address and so that's the reason for the error.

    I would advise you to raise this on the Umbraco Commerce issue tracker (noting in the issue that you are seeing it in Vendr) and provide replication steps and a full error log https://github.com/umbraco/Umbraco.Commerce.Issues/issues

  • Frans Lammers 57 posts 400 karma points c-trib
    Nov 15, 2023 @ 14:20
    Frans Lammers
    0

    Thank you, I will do so

Please Sign in or register to post replies

Write your reply to:

Draft