Back to shopping cart when payment fails

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
Good morning,

When payment fails, you shopping cart is finished and now it is placed as an order.

What we want is shopping cart not mark as finished if payment fails, for example sermepa or paypal payment.

I found that in OrderProcessingService I can avoid executing this method "MoveShoppingCartItemsToOrderItems" in method "PlaceOrder" if payment methong is Paypal or Sermepa. This way, if payment fails user's shopping cart is not finished and user can change or remove items.

If payment method doesn't fail, I can call "MoveShoppingCartItemsToOrderItems" in returning page, as the same time it is mark as paid.

Do you think it is a good idea? Is there a way to do this without coding?

Thank you for your time!
4 years ago
Well, I don't think there is any way to achieve this without customizing the code.
The redirection or the post-process payment method will create an order first on the order table and also saves the items to the OrderItems table before it redirects to the payment method's payment processing page. And once the payment is handled the payment status of the order is updated.
You need to be careful and consider several things before implementing the logic you have come with
1) By the implementation, you will have order recorded on the order table without any order items associated with the order in case if the payment fails.
2) What if the customer added new products on the cart before they submitted and made the payment information once they are redirected to the payment page. The newly added items may move to the OrderItems table which is not correct.
3) Will the nopcommerce architecture allows processing the payment that has no order items?

I think the better alternative will be to copy the items to the order item table(not move but copy) but not remove those from the shopping cart until the payment status is going to be set as paid.
Once the payment status is set as paid then you can remove those items from the shopping cart.
4 years ago
sanju.dahal741 wrote:
Well, I don't think there is any way to achieve this without coding.
I think the better alternative will be to copy the items to the order item table(not move but copy) but not remove those from the shopping cart until the payment status is going to be set as paid.
Once the payment status is set as paid then you can remove those items from the shopping cart.


Many thanks!!

I will try to find out how i can achieve this, but I think your idea is better.
4 years ago
Thank you for your advice sanju.dahal741.

I have just implemented and it seems to work as expected.

I have excluded shoppingcart removing from MoveShoppingCartItemsToOrderItems  method and also _productService.AdjustInventory depending on paymentmethod selected.

Then if payment result is OK, I remove shopping cart and execute _productService.AdjustInventory. If payment failed, shopping cart is still present and I delete order created.
4 years ago
That's great to hear.
Cheers!!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.