medusajs / medusa

Building blocks for digital commerce
https://medusajs.com
MIT License
24.65k stars 2.43k forks source link

404 after completing an order #4577

Closed imprakharshukla closed 3 months ago

imprakharshukla commented 1 year ago

Bug report

Describe the bug

Medusa store redirects to 'http://localhost:8000/order/confirmed/cart_xxxx....' after the completion of the order. Hence, the cart doesn't convert into an order despite running the completeCheckout mutation.

I am using the razorpay plugin for medusa (https://github.com/SGFGOV/medusa-payment-razorpay)

System information

Medusa version (including plugins):

    "@medusajs/admin": "6.0.3",
    "@medusajs/cache-inmemory": "1.8.8",
    "@medusajs/cache-redis": "1.8.8",
    "@medusajs/event-bus-local": "1.9.6",
    "@medusajs/event-bus-redis": "1.8.9",
    "@medusajs/medusa": "1.12.3",
    "body-parser": "1.20.2",
    "cors": "^2.8.5",
    "dotenv": "16.3.1",
    "express": "4.18.2",
    "medusa-file-spaces": "^1.3.7",
    "medusa-fulfillment-manual": "1.1.38",
    "medusa-interfaces": "^1.3.7",
    "medusa-payment-manual": "1.0.24",
    "medusa-payment-razorpay": "^3.0.2",
    "medusa-plugin-algolia": "^0.2.19",
    "typeorm": "0.3.17"

Node.js version: v20.2.0 Database: Postgres (supabase) Operating system: MacOS 13.2.1 Browser (if relevant): Arc

Steps to reproduce the behavior

  1. Select the product and checkout, filling all the details. Since I am using the razorpay, so fill the test cards and complete the checkout.
  2. When the payment is complete, storefront redirects to a confirm page with a cart id instead of an order id, and the order is not created in the database.

Expected behavior

Order should have been created in the database and the redirect URL should contain the order ID starting with order_xxx.., instead of a cart id cart_xxx...

Screenshots

If applicable, add screenshots to help explain your problem

Code snippets

Checkout-Context- https://gist.github.com/imprakharshukla/3b3b819aa32da89051dae410b6a0137f payment-button: - https://gist.github.com/imprakharshukla/4150620a3a32b5a62bffd0477a0925b2

Additional context

Server Logs- https://gist.github.com/imprakharshukla/96d03fde9ddbb535b52c87147148948c Frontend Logs- https://gist.github.com/imprakharshukla/3cea82e6929bfe746823133c5b7ecb5f Frontend Console output- https://gist.github.com/imprakharshukla/d63e4d54d7c0ab0646ba11236875552e

I am using the razorpay plugin for medusa (https://github.com/SGFGOV/medusa-payment-razorpay)

Naveen0903 commented 11 months ago

Documentation seems to be incorrect here. The callback url should be: callback_url: ${process.env.MEDUSA_BACKEND_URL}/razorpay/hooks

Mehmo21 commented 8 months ago

Hello, i have the same issue. In my case i dont use the razorpay plugin. My package version:

"dependencies": { "@medusajs/admin": "7.1.6", "@medusajs/cache-inmemory": "^1.8.9", "@medusajs/cache-redis": "^1.8.9", "@medusajs/event-bus-local": "^1.9.7", "@medusajs/event-bus-redis": "^1.8.10", "@medusajs/file-local": "^1.0.2", "@medusajs/medusa": "1.18", "@tanstack/react-query": "4.22.0", "babel-preset-medusa-package": "^1.1.13", "body-parser": "^1.19.0", "cors": "^2.8.5", "dotenv": "16.0.3", "express": "^4.17.2", "medusa-file-supabase": "^0.0.1", "medusa-fulfillment-manual": "^1.1.38", "medusa-interfaces": "^1.3.7", "medusa-payment-manual": "^1.0.24", "medusa-payment-paypal": "^6.0.2", "medusa-payment-stripe": "^6.0.5", "medusa-plugin-mailjet": "^0.0.6", "prism-react-renderer": "^2.0.4", "typeorm": "^0.3.16" }

piereligio commented 8 months ago

Getting the same exact issue, on PayPal (and probably also Stripe) plugin. In both cases isn't happening all the time, but about once every 6 transactions. On PayPal it causes the payment to go through but remain on hold state (on stripe seems to cause the payment to fail directly and thus not even trying to create the order, but I am not sure. I didn't receive reports about this, so I'm speculating), falling in this scenario. I think it always has to do with the 404 errors I get on the webhooks, even though I pointed them as written in manual (I set up the webhook as https://mybackenddomain.url/paypal/hooks ) . I am using basically same versions of @Mehmo21 , except for medusa that is 1.17.3.

piereligio commented 7 months ago

Uh, somehow I fixed the issue (no failed order since Jan 23), with an edit that I did, which in theory shouldn't have effect on this, but well, maybe it did. I wanted to get an email when the order did fail, with all the data accessible to the storefront in that situation. I did two things, actually:

  1. In the storefront, /src/lib/context/checkout-context.tsx , onPaymentCompleted. Here I added a condition under which it would send me the email using a my API:
    const onPaymentCompleted = () => {
    complete(undefined, {
      onSuccess: ({ data }) => {
        resetCart()
        if (data && data.id && data.id.includes("cart_")) {
          fetch(`/api/error/report`, {
            method: 'POST',
            headers: {'Content-Type': 'application/json'},
            body: JSON.stringify(data)
          });
        }
        push(`/order/confirmed/${data.id}`)
      },
    })
    }
  2. Stripe would constantly send me alerts that their webhook wasn't work, so I disabled it (but I am not entirely sure on when I did this).
suganyasai1026 commented 5 months ago

@imprakharshukla is the issue is resolved , i am too facing the same issue

WoodlegDev commented 3 months ago

I too get 404 Error from PayPal Webhooks