How to remove purchaseorder from orderrepository when payment fails?

Vote:
 

I have a thiry party payment gateway. When payment fails, i delete order reference from orderrepository. But purchnase order is still there in orderrepository. How to remove purchaseorder from orderrepository? My code is as shown below. purchnase order is showing line items.

if (paymentResponse.ResultCode != PaymentsResponse.ResultCodeEnum.Authorised)
{
_orderRepository.Delete(orderReference);

}
var purchaseOrders = _orderRepository.Load<IPurchaseOrder>(_customerContext.CurrentContactId)
                                             .OrderByDescending(x => x.Created)
                                             .ToList();

#206347
Aug 16, 2019 6:22
Vote:
 

Could you do 

_orderRepository.Load<IPurchaseOrder>(orderReference)

after you've deleted your order? Right now you're loading the customer's purchase orders, so if the customer had previous orders, you'll see them and not the one you deleted.

#206348
Aug 16, 2019 7:05
Vote:
 

_orderRepository.Delete(orderReference); is the correct code to delete the order, but only if you pass the correct orderReference. Where does your orderReference point to?

#206350
Aug 16, 2019 9:31
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.