Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Cannot refund multiple times from a single order #10842

Open
theosenoussaoui opened this issue Jan 6, 2025 · 1 comment
Open

[Bug]: Cannot refund multiple times from a single order #10842

theosenoussaoui opened this issue Jan 6, 2025 · 1 comment

Comments

@theosenoussaoui
Copy link

Package.json file

{
  "name": "medusa",
  "version": "0.0.1",
  "engines": {
    "node": ">=20"
  },
  "scripts": {
    "nukedb": "docker compose down -v && docker compose up -d && sleep 4",
    "build": "medusa build",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "medusa start",
    "dev": "medusa develop",
    "sync": "medusa db:sync-links",
    "migrate:prod": "yarn run migrate && yarn run sync",
    "start:prod": "medusa start",
    "seed:prod": "medusa exec ./src/scripts/seed.ts",
    "migrate": "medusa db:migrate",
    "generate": "medusa db:generate",
    "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",
    "add-user": "medusa user --email [email protected] --password admin",
    "typecheck": "tsc --noEmit",
    "lint": "eslint --fix",
    "setup:env": "cp .env.template .env",
    "setup:db": "medusa db:create --db medusa && yarn run migrate && yarn run sync && yarn run add-user",
    "setup:seed": "yarn run seed"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "2.1.3",
    "@medusajs/cli": "2.1.3",
    "@medusajs/core-flows": "2.1.3",
    "@medusajs/framework": "2.1.3",
    "@medusajs/js-sdk": "2.1.3",
    "@medusajs/medusa": "2.1.3",
    "@mikro-orm/core": "5.9.7",
    "@mikro-orm/knex": "5.9.7",
    "@mikro-orm/migrations": "5.9.7",
    "@mikro-orm/postgresql": "5.9.7",
    "@repo/eslint-config": "workspace:^",
    "@repo/typescript-config": "workspace:^",
    "awilix": "^8.0.1",
    "axios": "^1.7.7",
    "eslint": "^9.15.0",
    "minio": "^8.0.2",
    "pg": "^8.13.0",
    "slugify": "^1.6.6"
  },
  "devDependencies": {
    "@medusajs/test-utils": "2.1.3",
    "@medusajs/types": "2.1.3",
    "@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": "npm:[email protected]",
    "@types/react-dom": "npm:[email protected]",
    "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"
  }
}

Node.js version

v20.18.1

Database and its version

PgSQL 16.4.1

Operating system name and version

Archlinux

Browser name

Google Chrome

What happended?

  • I cannot make multiple refunds in a single order.

Expected behavior

  • I should be able to refund as many times as possible, as long as it doesn't exceed the original amount of the order.

Actual behavior

Here is the current refund issue I'm having :

  • I'm placing an order with a certain amount with more than one item.
  • I create a return for a certain item in the order after everything is fulfilled and delivered.
  • After the return has been created, I issue a refund.
  • Refund is processed successfully.

If I repeat this exact process for another item in the same order, the refund is not successfull, I'm faced with this error :

{
  message: 'Order does not have an outstanding balance to refund',
  name: 'Error',
  stack: 'Error: Order does not have an outstanding balance to refund\n' +
    '    at Object.<anonymous> (/home/kzm/documents/wizards/gaya-v2/node_modules/@medusajs/core-flows/src/payment/workflows/refund-payment.ts:32:13)\n' +
    '    at Object.invoke (/home/kzm/documents/wizards/gaya-v2/node_modules/@medusajs/workflows-sdk/src/utils/composer/helpers/create-step-handler.ts:72:67)\n' +
    '    at processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
    '    at async DistributedTransaction.handler (/home/kzm/documents/wizards/gaya-v2/node_modules/@medusajs/orchestration/src/workflow/workflow-manager.ts:214:16)\n' +
    '    at async stepHandler (/home/kzm/documents/wizards/gaya-v2/node_modules/@medusajs/orchestration/src/transaction/transaction-orchestrator.ts:827:20)\n' +
    '    at async Promise.allSettled (index 0)\n' +
    '    at async promiseAll (/home/kzm/documents/wizards/gaya-v2/node_modules/@medusajs/utils/src/common/promise-all.ts:27:18)\n' +
    '    at async TransactionOrchestrator.executeNext (/home/kzm/documents/wizards/gaya-v2/node_modules/@medusajs/orchestration/src/transaction/transaction-orchestrator.ts:965:7)\n' +
    '    at async executeNext (/home/kzm/documents/wizards/gaya-v2/node_modules/@medusajs/orchestration/src/transaction/transaction-orchestrator.ts:1013:14)\n' +
    '    at async TransactionOrchestrator.resume (/home/kzm/documents/wizards/gaya-v2/node_modules/@medusajs/orchestration/src/transaction/transaction-orchestrator.ts:1028:5)\n' +
    '⮑ sat /home/kzm/documents/wizards/gaya-v2/node_modules/@medusajs/core-flows/dist/payment/workflows/refund-payment.js: [refund-payment-workflow -> validate-refund-step (invoke)]',
  __isMedusaError: true,
  type: 'invalid_data',
  code: undefined,
  date: 2025-01-06T15:20:40.573Z
}

Link to reproduction repo

/

@sgirones
Copy link
Contributor

sgirones commented Jan 6, 2025

hey @theosenoussaoui any chance you can provide a video reproducing this issue? We are mainly wondering how you create the refund.

@sgirones sgirones self-assigned this Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants