Copied to clipboard

Flag this post as spam?

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

  • Kenni Rau 8 posts 109 karma points
    Mar 05, 2021 @ 13:38
    Kenni Rau

    Finalize an order created programmatically without payment

    I'm trying to finalize an order created programmatically without payment, but I get the following exception when trying to save the order:

    System.InvalidOperationException: 'Cannot edit order as it is, or has been processed for payment.'

    I can that on the order IsFinalized = false, IsFinalizing = true, FinalizedDate = {3/5/2021 1:29:56 PM} and _originalState.FinalizedDate = null

    Here is the code:

    var shippingCountryId = order.ShippingInfo.CountryId.HasValue
                            ? order.ShippingInfo.CountryId.Value
                            : order.PaymentInfo.CountryId.Value;
                        var shippingMethod = VendrApi.Instance.GetShippingMethodsAllowedIn(shippingCountryId).FirstOrDefault();
                        var paymentMethods = VendrApi.Instance.GetPaymentMethodsAllowedIn(order.PaymentInfo.CountryId.Value);
                        var zeroValuePaymentMethod = paymentMethods.FirstOrDefault(x => x.Alias == VendrCheckoutConstants.PaymentMethods.Aliases.ZeroValue);
                        order.Finalize(order.TotalPrice, Guid.NewGuid().ToString("N"), PaymentStatus.Authorized);
  • Matt Brailsford 3020 posts 15702 karma points MVP 7x c-trib
    Mar 05, 2021 @ 13:49
    Matt Brailsford

    Hi Kenni

    My guess is that there might be some code running elsewhere, either in your codebase or within Vendr that runs in reaction to an order save event. The problem is, as soon as Finalize is called, any modifications to the order will be blocked as you aren't allowed to modify anything from this point on that would require a recalculation.

    Simplest option would probably be to break up the update / finalize into their own units of work so that you can ensure anything that modifies the order is completely done in the first unit of work, and the finalize is called on it's own after this point.

    Alternatively, you can try and pinpount the code that is trying to modify the order after Finalize is called and see if that can be moved / triggered prior to the method call.

    Hope that helps


Please Sign in or register to post replies

Write your reply to: