medusajs / medusa

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

[Bug]: unable to refund amount for an order with captured payment #10392

Closed usamaadev closed 1 day ago

usamaadev commented 1 day ago

Package.json file

{
  "name": "medusa-starter-default",
  "version": "0.0.1",
  "description": "A starter for Medusa projects.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "build": "medusa build",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "medusa start",
    "dev": "medusa develop",
    "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
    "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "latest",
    "@medusajs/cli": "latest",
    "@medusajs/framework": "latest",
    "@medusajs/medusa": "latest",
    "@mikro-orm/core": "5.9.7",
    "@mikro-orm/knex": "5.9.7",
    "@mikro-orm/migrations": "5.9.7",
    "@mikro-orm/postgresql": "5.9.7",
    "awilix": "^8.0.1",
    "medusa-fulfillment-manual": "^1.1.41",
    "pg": "^8.13.0"
  },
  "devDependencies": {
    "@medusajs/test-utils": "late0st",
    "@mikro-orm/cli": "5.9.7",
    "@swc/core": "1.5.7",
    "@swc/jest": "^0.2.36",
    "@types/jest": "^29.5.13",
    "@types/node": "^20.0.0",
    "@types/react": "^18.3.2",
    "@types/react-dom": "^18.2.25",
    "jest": "^29.7.0",
    "prop-types": "^15.8.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2",
    "vite": "^5.2.11"
  },
  "engines": {
    "node": ">=20"
  }
}

Node.js version

v20.9.0

Database and its version

PostgreSQL 17.0

Operating system name and version

Ubuntu 22.04.4 LTS

Browser name

No response

What happended?

When attempting to process a refund on an order with a captured payment, the system throws the following error:

Order does not have an outstanding balance to refund

Steps to Reproduce:

  1. Place an order and capture the payment successfully.
  2. Attempt to issue a refund for the captured payment.
  3. Observe the error.

Expected behavior

The refund should process without errors, allowing the amount to be returned to the customer.

Actual behavior

The system blocks the refund process and shows the error message: Order does not have an outstanding balance to refund.

Additional Context:

image

Link to reproduction repo

Cloned new with 2.0.7

carlos-r-l-rodrigues commented 1 day ago

Hi @usamaadev, thanks for the post, but this is an intended validation. In order to create a refund, the Order balance has to be below 0, meaning an item was returned, or something else edited. We might revisit this behavior in the future, but we'll keep it as it is for now, considering it has some accounting implications that make this trickier than it seems to be.