Does vendr allow to programmatically change an order that has already been finalized?
We have an order placed by the customer, at the checkout we go to the gateway to reserve the value of the order, but it may happen that not all items have been delivered.
In that case we just need to capture the value of what was delivered and change the order to the amount charged and the items that were delivered.
We are thinking of:
1 - We change the finalized order
2 - At the time of checkout we do not finalize the order and keep it in the cart to be able to change
3 - Cancel the previous order and create a new one
We would like to understand before starting the structure of the project if these paths are valid.
ps: We are creating a custom payment provider on vendr (onpay)
Currently finalized orders are final. You can change some things like properties and customer details, but not anything that would affect the price. We are looking at better refund options to allow partial refunds of an order which I think would be the right thing to do here but we currently only allow refunding the entire order.
I guess the option you choose depends on the flow you need. You could go option 2 and capture on a payment gateway the customers payment details and store some kind of token on the order then create a custom button in the back office or something to trigger the capture against the stored credentials. Vendr does allow editing carts, but we don’t have a way yet in the backoffice to mark a cart as paid so this would need to be custom.
My gut says you’d have most luck with either option 2 or 3 as option 1 would require hacking the order outside of Vendrs API.
We will use option 2, but our customer asked for unit testing this order change method.
We have been looking at the umbraco documentation "https://our.umbraco.com/Documentation/Implementation/Unit-Testing/index-v8", but for vendr we are not able to use the VendrAPI(inside unit test project), so we can test the method.
Any suggestion/example?
ex:
IVendrApi vendrApi = VendrApi.Instance;//Umbraco instance is null
using (var uow = vendrApi.Uow.Create())
{
var order = vendrApi.GetOrder(orderId)?
.AsWritable(uow);
IVendrApi is an interface so can it not be mocked? Also, IVendrApi is within the DI container so you should only use the singleton accessor in situations where you can’t inject it.
Sorry for the previous post, It was a little confused and not objective.
Thank you for your help.
We are trying to test the "changeorderitems" method, for that we tried to create a mock of the vendr order... as it doesn't have a constructor we tried to use the create method.
From what we can understand, we need to mock UnitOfWork, and that's where our confusion is. How we can create one object order so we can test it?
Ex:(we are getting object ot set, we suspect it is because of the mock ao unitofwork)
GrntKo.Core.Models.Products.ProductSnapshot productSnapshotA = new Core.Models.Products.ProductSnapshot("Product A", "Product A", "A", 10M, new Guid("6ae57f51-ed1d-485d-a5fe-017ef7d77187"));
GrntKo.Core.Models.Products.ProductSnapshot productSnapshotB = new Core.Models.Products.ProductSnapshot("Product B", "Product B", "B", 15M, new Guid("6ae57f51-ed1d-485d-a5fe-017ef7d77187"));
Mock<IUnitOfWork> unit = new Mock<IUnitOfWork>();
Order order = Order.Create(unit.Object, new Guid("ca0b66cb-1da3-458a-b7f5-017ef7ce257f"), "en-gb", new Guid("6ae57f51-ed1d-485d-a5fe-017ef7d77187"), new Guid("5b32dea4-712f-419f-a3e3-017ef7ce2977"), new Guid("0f5b1ede-3898-4ade-bbe7-017ef7ce2ae2"));
order.AddProduct(productSnapshotA, 1, new Dictionary<string, string>(), string.Empty, string.Empty, new List<string>());
order.AddProduct(productSnapshotB, 2, new Dictionary<string, string>(), string.Empty, string.Empty, new List<string>());
Change finalized order
Hi,
Does vendr allow to programmatically change an order that has already been finalized?
We have an order placed by the customer, at the checkout we go to the gateway to reserve the value of the order, but it may happen that not all items have been delivered.
In that case we just need to capture the value of what was delivered and change the order to the amount charged and the items that were delivered.
We are thinking of:
We would like to understand before starting the structure of the project if these paths are valid.
ps: We are creating a custom payment provider on vendr (onpay)
Thanks
Hi Nelson,
Currently finalized orders are final. You can change some things like properties and customer details, but not anything that would affect the price. We are looking at better refund options to allow partial refunds of an order which I think would be the right thing to do here but we currently only allow refunding the entire order.
I guess the option you choose depends on the flow you need. You could go option 2 and capture on a payment gateway the customers payment details and store some kind of token on the order then create a custom button in the back office or something to trigger the capture against the stored credentials. Vendr does allow editing carts, but we don’t have a way yet in the backoffice to mark a cart as paid so this would need to be custom.
My gut says you’d have most luck with either option 2 or 3 as option 1 would require hacking the order outside of Vendrs API.
Hope this helps
Hi,
We will use option 2, but our customer asked for unit testing this order change method.
We have been looking at the umbraco documentation "https://our.umbraco.com/Documentation/Implementation/Unit-Testing/index-v8", but for vendr we are not able to use the VendrAPI(inside unit test project), so we can test the method.
Any suggestion/example?
ex: IVendrApi vendrApi = VendrApi.Instance;//Umbraco instance is null
using (var uow = vendrApi.Uow.Create()) { var order = vendrApi.GetOrder(orderId)? .AsWritable(uow);
}
Thanks for your help
IVendrApi is an interface so can it not be mocked? Also, IVendrApi is within the DI container so you should only use the singleton accessor in situations where you can’t inject it.
Hi,
Sorry for the previous post, It was a little confused and not objective. Thank you for your help.
We are trying to test the "changeorderitems" method, for that we tried to create a mock of the vendr order... as it doesn't have a constructor we tried to use the create method. From what we can understand, we need to mock UnitOfWork, and that's where our confusion is. How we can create one object order so we can test it?
Ex:(we are getting object ot set, we suspect it is because of the mock ao unitofwork)
Thanks
Hi Nelson,
I'm not sure what you mean by
changeorderitems
method as there is no method of that name. Or are you refering to theAddProduct
method?For details on the Unit of Work and how to create one, you should review the docs at https://vendr.net/docs/core/2.1.0/umbraco-v9/key-concepts/unit-of-work/
Hope this helps
Matt
is working on a reply...