I am implementing a payment method which allows reposting payments if not completed successfully at first.
The problem is that if the customer has more than one unpaid orders and try to repost the first of them,
after the payment is completed and redirect the customer at the /checkout/completed page, it always shows the last payment completed.
Moreover, this page is always available and always shows the last completed order.
Maybe we could add a parameter at the Completed() method at the CheckoutController so that from the payment we could pass the last order processed.
something like that:
public ActionResult Completed(int? orderid)
{
//validation
if ((_workContext.CurrentCustomer.IsGuest() && !_orderSettings.AnonymousCheckoutAllowed))
return new HttpUnauthorizedResult();
//model
var model = new CheckoutCompletedModel();
//Added
if(orderid !=null)
{
var o = _orderService.GetOrderById(orderid.Value);
if(o == null) throw new Exception("Order cannot be null");
model.OrderId = o.Id;
return View(model);
}
var orders = _orderService.GetOrdersByCustomerId(_workContext.CurrentCustomer.Id);
if (orders.Count == 0)
return RedirectToRoute("HomePage");
else
{
var lastOrder = orders[0];
model.OrderId = lastOrder.Id;
}
return View(model);
}