mollie / magento2

Mollie Payments for Magento 2
https://www.mollie.com
Other
102 stars 53 forks source link

Restore cart if payment has failed or user has canceled or used the back button #484

Closed joggienl closed 2 years ago

joggienl commented 2 years ago

I've got a question regarding a couple of failure situations. The frontend is a react application that is using the magento2 graphql api, so we have configured a PWA storefront url in magento2 for mollie.

The use cases are about payment, and in particular action a customer takes on the mollie payment page.

The last two situations will redirect the user back to the configured PWA url. The first situation does not. I do think that technically a user is in an "open" state for the first situation.

Either way, since a user has started the payment flow, the user also triggered the "placeOrder" mutation of Magento2. So all situations lead to an "empty cart", which means that the user needs to re add all items to cart.

Are there any (common) ways on how to handle this (like, can we configure this) or is the more common flow to remember the state of the cart in the browser and in those situations re-create-the cart manually and re-add everything? I know that it is possible to do the latter, but I am curious how this is solved more generally (if even possibly)...

Curious to get some more input!

Frank-Magmodules commented 2 years ago

HI @joggienl ,

Thank you for opening this issue. We have an endpoint for this, but it was missing from the GraphQL documentation. 
We updated it so you can find it here: https://github.com/mollie/magento2/wiki/GraphQL-integration#resetting-the-cart

You can call this endpoint when the user gets redirected from Mollie and the transaction has a failed status. 
This call will then re-activate the cart for you.

We are closing this issue now but please feel free to reopen the issue if this still occurs.

joggienl commented 2 years ago

Hello @Frank-Magmodules !

Thanks for this response!

It sounds greats to have that endpoint. Unfortunately it doesn't work, or I don't know how I should use it. I hope that you can help me out with this call!

I've walked through the process of adding items to cart, doing checkout and going to payment. When I cancel the payment and when I get back to the webshop, which cart_id should I pass? I suppose the old one. But if I pass it the old cart_id it responded back with The cart isn't active. (which is correct, but was the idea I guess).

What is the idea of what will happen? Is it trying to re-activate the old cart_id (and am I missing a configuration for that somewhere)? Or will it create a new cart_id and should I grab the new cart_id from the result?

Thanks!

*edit with example

mutation {
  mollieRestoreCart(input: {cart_id: "cart-id-that-just-got-canceled-order"}) {
    cart {
      id
      total_quantity
    }
  }
}

output:

{
  "errors": [
    {
      "message": "The cart isn't active.",
      "extensions": {
        "category": "graphql-no-such-entity"
      },
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "mollieRestoreCart"
      ]
    }
  ],
  "data": {
    "mollieRestoreCart": null
  }
}

We are using mollie module v1.30.0 for what it is worth

joggienl commented 2 years ago

We've updated our mollie module to the latest version, the result is the same. If I try this mutation it gives me an error that "the cart isn't active". Seems like a bug then?