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 36 posts 150 karma points
    Nov 14, 2022 @ 15:20
    anh-duc-le
    0

    Order moves from NEW to ERROR before being finalized

    Umbraco 10 (But issue existed in 9 too)

    I have this bit of code where a customer can exchange a voucher code on our website and in the backend we basically translate it into a Vendr order and finalize it with a Vendr Zero Checkout transaction.

    It works fine with one small exception, the order gets the status Error before it is moved to Processing.

    Do you have any pointers as to why it would start from the Error status instead of the New status?

    enter image description here


    I have included the important code bits that connect with Vendr here:

    This bit of code populates the shopping cart order lines and then finalizes the order.

    this.shoppingCartService.ClearCurrentOrder();
    
    using (var scope = this.scopeProvider.CreateScope())
    {
        foreach (var code in request.CampaignCodes)
        {
            await this.RedeemCodeAsync(voucherCampaign.CardData, code);
        }
    
        scope.Complete();
    }
    
    var order = this.orderUpdateService.FinalizeOrderWithCheckoutZeroValue(request.EmailAddress, request.FirstName, request.LastName);
    

    The .ClearCurrentOrder() method does the following:

    this.vendrApi.Uow.Execute(uow =>
    {
        var store = this.vendrApi.GetStore(Constants.StoreAlias);
    
        this.vendrApi.ClearCurrentOrder(store.Id);
    
        uow.Complete();
    });
    

    The .RedeemCodeAsync() method in the foreach verifies the voucherCode and then calls an .AddToCart() method that adds a product to the shopping cart

    this.vendrApi.Uow.Execute(uow =>
    {
        var properties = new Dictionary<string, string>
        {
            { Constants.OrderLineKey, this.keyGenerationService.GenerateKey(KeySize) },
            { Constants.PropertyAlias.UnitPricePropertyAlias, giftCardData.Amount.ToString(NumberFormatInfo.InvariantInfo) },
            { Constants.PropertyAlias.DeliveryMethodPropertyAlias, giftCardData.Delivery },
            { Constants.PropertyAlias.GiftCardDataPropertyAlias, data },
            { Constants.PropertyAlias.ThemePropertyAlias, giftCardData.Theme },
        };
    
        if (!string.IsNullOrWhiteSpace(code))
        {
            properties.Add(Constants.PropertyAlias.CampaignCodePropertyAlias, code);
        }
    
        var store = this.vendrApi.GetStore(Constants.StoreAlias);
    
        order = this.vendrApi
            .GetOrCreateCurrentOrder(store.Id)
            .AsWritable(uow)
            .AddProduct(productReference, giftCardData.Theme, qty, properties);
    
        var orderNumber = order.OrderNumber;
    
        this.vendrApi.SaveOrder(order);
    
        uow.Complete();
    });
    

    And finally I call the .FinalizeOrderWithCheckoutZeroValue() method to complete the order.

    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();
    });
    
  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Nov 14, 2022 @ 15:53
    Matt Brailsford
    1

    What is the actual value of the order?

    The only thing I can think of off the top of my head is we have some code that looks for "payment inconsistancy", ie, your ammount captured via the payment provider != the order transaction amount and so Vendr will class this as an error.

  • anh-duc-le 36 posts 150 karma points
    Nov 15, 2022 @ 10:49
    anh-duc-le
    0

    Ah right, that makes perfect sense. Thanks for the pointer, now I know where to fix it when I have the time for it :)

    enter image description here

Please Sign in or register to post replies

Write your reply to:

Draft