I am trying to remove the payment step from Vendr.Checkout (as we only use one payment provider) by setting the payment method when a product is added to the cart. But Vendr complains that the payment method is not set when we get to the review step.
Can anyone help with the correct way to setting this?
[HttpPost]
public ActionResult AddToBasket(AddToBasketDto postModel)
{
try
{
using (var uow = _unitOfWorkProvider.Create())
{
var store = CurrentPage.GetStore();
var order = _sessionManager.GetOrCreateCurrentOrder(store.Id)
.AsWritable(uow)
.SetProperty("opayoOrderDescription", "Artwork")
.SetPaymentMethod(new Guid("436971b5-b711-42ed-8e56-f807f89c8620"))
.AddProduct(postModel.ProductReference, postModel.Quantity);
_orderService.SaveOrder(order);
uow.Complete();
}
}
catch (ValidationException ex)
{
...
}
return CurrentUmbracoPage();
}
What you have is fine, but it's likely because Vendr.Checkout has a series of event handlers to clear the selected payment / shipping method at various steps of the checkout flow so whilst your code is setting the payment method, these event handlers are likely clearing it
We don't currently have an API to remove handlers via Vendr but as Vendr's event registration API is a wrapper around Umbraco's API, you could probably create a composer that runs after VendrCheckouts and use Umbraco's API to remove the handlers
[ComposeAfter(typeof(VendrCheckoutComposer))]
public class Composer : IUserComposer
{
public void Compose(Composition composition)
{
composition.WithCollectionBuilder<EventHandlerCollectionBuilder<OrderProductAddingNotification>>()
.Remove<OrderProductAddingHandler>();
composition.WithCollectionBuilder<EventHandlerCollectionBuilder<OrderLineChangingNotification>>()
.Remove<OrderLineChangingHandler>();
composition.WithCollectionBuilder<EventHandlerCollectionBuilder<OrderPaymentCountryRegionChangingNotification>>()
.Remove<OrderPaymentCountryRegionChangingHandler>();
composition.WithCollectionBuilder<EventHandlerCollectionBuilder<OrderShippingCountryRegionChangingNotification>>()
.Remove<OrderShippingCountryRegionChangingHandler>();
composition.WithCollectionBuilder<EventHandlerCollectionBuilder<OrderShippingMethodChangingNotification>>()
.Remove<OrderShippingMethodChangingHandler>();
}
}
Obviously, in so doing this, you are removing some of Vendr Checkout's logic, so you'll need to test that the checkout flow calculations are what you expect them to be.
Correct way to use SetPaymentMethod
Hello,
I am trying to remove the payment step from Vendr.Checkout (as we only use one payment provider) by setting the payment method when a product is added to the cart. But Vendr complains that the payment method is not set when we get to the review step.
Can anyone help with the correct way to setting this?
What you have is fine, but it's likely because Vendr.Checkout has a series of event handlers to clear the selected payment / shipping method at various steps of the checkout flow so whilst your code is setting the payment method, these event handlers are likely clearing it
https://github.com/vendrhub/vendr-checkout/blob/dev/src/Vendr.Checkout/Composing/VendrCheckoutComposer.cs#L14-L30
We don't currently have an API to remove handlers via Vendr but as Vendr's event registration API is a wrapper around Umbraco's API, you could probably create a composer that runs after VendrCheckouts and use Umbraco's API to remove the handlers
Obviously, in so doing this, you are removing some of Vendr Checkout's logic, so you'll need to test that the checkout flow calculations are what you expect them to be.
Matt
Thanks Matt, that worked a treat.
is working on a reply...