medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
26k stars 2.61k forks source link

Cannot cancel order #5457

Open BorisKamp opened 1 year ago

BorisKamp commented 1 year ago

Using medusa 1.17.1 I cannot cancel an order. Whenever I call {{medusa-host}}/admin/orders/:id/cancel I get a 400 bad request back and see the following in my logs:

{
   "level":"error",
   "message":"An error occurred in cancelPayment:\nundefined\n",
   "stack":[
      {
         "columnNumber":15,
         "fileName":"/app/node_modules/@medusajs/medusa/dist/services/payment-provider.js",
         "functionName":"PaymentProviderService.throwFromPaymentProcessorError",
         "lineNumber":1051,
         "methodName":"throwFromPaymentProcessorError",
         "native":false,
         "typeName":"PaymentProviderService"
      },
      {
         "columnNumber":50,
         "fileName":"/app/node_modules/@medusajs/medusa/dist/services/payment-provider.js",
         "functionName":null,
         "lineNumber":681,
         "methodName":null,
         "native":false,
         "typeName":"PaymentProviderService"
      },
      {
         "columnNumber":23,
         "fileName":"/app/node_modules/@medusajs/medusa/dist/services/payment-provider.js",
         "functionName":"step",
         "lineNumber":48,
         "methodName":null,
         "native":false,
         "typeName":null
      },
      {
         "columnNumber":53,
         "fileName":"/app/node_modules/@medusajs/medusa/dist/services/payment-provider.js",
         "functionName":"Object.next",
         "lineNumber":29,
         "methodName":"next",
         "native":false,
         "typeName":"Object"
      },
      {
         "columnNumber":58,
         "fileName":"/app/node_modules/@medusajs/medusa/dist/services/payment-provider.js",
         "functionName":"fulfilled",
         "lineNumber":20,
         "methodName":null,
         "native":false,
         "typeName":null
      },
      {
         "columnNumber":5,
         "fileName":"node:internal/process/task_queues",
         "functionName":"process.processTicksAndRejections",
         "lineNumber":95,
         "methodName":"processTicksAndRejections",
         "native":false,
         "typeName":"process"
      }
   ],
   "timestamp":"2023-10-24 10:22:06"
}

I have multiple test orders from when we started with Medusa that I want to cleanup, however I can't.

Here's the payments array from one of the orders:

"payments": [
            {
                "id": "pay_01H936APP4XC99KTDWPER8GWXQ",
                "created_at": "2023-08-30T12:22:41.285Z",
                "updated_at": "2023-08-30T12:22:41.285Z",
                "swap_id": null,
                "cart_id": "cart_01H9362C42S6MDTR598BZM816Y",
                "order_id": "order_01H936AQ7751PAYDC2PWW0ZFD9",
                "amount": 19955,
                "currency_code": "eur",
                "amount_refunded": 0,
                "provider_id": "stripe",
                "data": {
                    "id": "pi_3NknPiHom7EScpqg0JKxzsQj",
                    "amount": 19955,
                    "object": "payment_intent",
                    "review": null,
                    "source": null,
                    "status": "succeeded",
                    "created": 1693398146,
                    "invoice": null,
                    "currency": "eur",
                    "customer": "cus_OIrkkfE5KmTFMU",
                    "livemode": false,
                    "metadata": {
                        "resource_id": "cart_01H9362C42S6MDTR598BZM816Y"
                    },
                    "shipping": null,
                    "processing": null,
                    "application": null,
                    "canceled_at": null,
                    "description": null,
                    "next_action": null,
                    "on_behalf_of": null,
                    "client_secret": "pi_3NknPiHom7EScpqg0JKxzsQj_secret_RpRxgJlvZYC6ZxEJofiTTLLkg",
                    "latest_charge": "py_3NknPiHom7EScpqg0Gddx4zz",
                    "receipt_email": null,
                    "transfer_data": null,
                    "amount_details": {
                        "tip": {}
                    },
                    "capture_method": "automatic",
                    "payment_method": "pm_1NknPqHom7EScpqgQTrwaq7V",
                    "transfer_group": null,
                    "amount_received": 19955,
                    "amount_capturable": 0,
                    "last_payment_error": null,
                    "setup_future_usage": null,
                    "cancellation_reason": null,
                    "confirmation_method": "automatic",
                    "payment_method_types": [
                        "card",
                        "bancontact",
                        "eps",
                        "giropay",
                        "ideal",
                        "p24",
                        "sofort",
                        "link",
                        "paypal"
                    ],
                    "statement_descriptor": null,
                    "application_fee_amount": null,
                    "payment_method_options": {
                        "eps": {},
                        "p24": {},
                        "card": {
                            "network": null,
                            "installments": null,
                            "mandate_options": null,
                            "request_three_d_secure": "automatic"
                        },
                        "link": {
                            "persistent_token": null
                        },
                        "ideal": {},
                        "paypal": {
                            "reference": null,
                            "preferred_locale": null
                        },
                        "sofort": {
                            "preferred_language": null
                        },
                        "giropay": {},
                        "bancontact": {
                            "preferred_language": "en"
                        }
                    },
                    "automatic_payment_methods": {
                        "enabled": true,
                        "allow_redirects": "always"
                    },
                    "statement_descriptor_suffix": null
                },
                "captured_at": "2023-08-30T12:22:43.386Z",
                "canceled_at": null,
                "metadata": null,
                "idempotency_key": null
            }
        ]

What else would you need to debug?

chemicalkosek commented 1 year ago

In stripe you cannot cancel payments if they are captured:

https://stripe.com/docs/refunds#cancel-payment

Scyks commented 1 year ago

Could you maybe explain how to deal with canceled orders? In several countries customers could cancel the order even in a later state. Normally you would then cancel the order and refund the money.

Currently I don't see a way of declaring the order as canceled - If that's happening - i end up with dangling Orders in my Store.

Is there any plan of changing the way of how an order is canceled?

BorisKamp commented 1 year ago

Yeah I second that, I have dead order which I cannot remove because of a stripe payment for example. But the stripe payment was a test payment in this case. So we need a way to cancel those orders.

ssoonmi commented 1 year ago

Would refunding the payment of the order solve this? https://docs.medusajs.com/modules/orders/admin/manage-orders#refund-payment

Scyks commented 1 year ago

Would refunding the payment of the order solve this? https://docs.medusajs.com/modules/orders/admin/manage-orders#refund-payment

I tried that also, the payment is going back to the customer but the order stays open and there is no way to close/cancel.

You cannot cancel refunded orders.

The only way I see at the moment is to change the status manually on the db.

BorisKamp commented 1 year ago

Any update for this guys?

nicolama-dev commented 11 months ago

Upvote for this - this is a must have.

BorisKamp commented 10 months ago

As a workaround for now I cancel the order straight from the database. In the order table set the status field to either canceled or archived, this does the trick and breaks nothing, I can confirm.

This should be fairly easy to implement in the cancel order endpoint tho. I think medusa needs to implement a force paramater that we can send along, if true, always set the order to canceled, no matter the other statusses (payment status with stripe for example).

Same for the archive order endpoint.

bqst commented 6 months ago

Same issue here

NicolasGorga commented 1 month ago

Hey any updates on this? Seems to be a really big hole if i am understanding this correctly.

I have a flow where the Seller can choose to Accept or Decline a paid order. In the later case, the order would need to be cancelled (deleteing item reservations and other logic) and refunding to the customer. With current setup it seems one is exclusive of the other: you cannot cancel an order with refunds and you cannot refund a canelled order

@BorisKamp have you found anything or has the Medusa team reached out to you?

BorisKamp commented 1 month ago

@BorisKamp have you found anything or has the Medusa team reached out to you?

hey! Well I still cancel them manually in my database. But it should be pretty easy to create a custom endpoint for this using the order repo.

it would be nice to get a reply from one of the medusa team members tho, to verify that what I state up here, indeed does not break anything. @shahednasser

ddanninger commented 1 week ago

Same problem here. Would be great to have a solution. Highly uncomfortable if in production mode ...

NicolasGorga commented 1 week ago

Any update on this? Would be available to work on this if we got some input from somebody from the Medusa team about the best way to handle this...