Skip to content

Batch payments not collecting platform fee  #182

@MantisClone

Description

@MantisClone

Problem

Batch payments only collect protocol fee, NOT platform fee. Platform is losing revenue on every batch transaction.

Affects both:

  • Batch payouts (creates new requests via requests array) - fee fields placed inside requests[] instead of body level
  • Batch invoice payments (pays existing requests via requestIds array) - fee fields not sent at all

Both use the same batchPay function calling POST v2/payouts/batch.

Root cause: batchPay endpoint doesn't place feePercentage and feeAddress at body level where the API expects them.

Proposed Solution

Move fee fields to body level (fixes both batch payouts and batch invoice payments):

// CURRENT (broken) - src/server/routers/payment.ts lines 60-74
const response = await apiClient.post("v2/payouts/batch", {
  requests: input.payouts?.map((payout) => ({
    ...
    feePercentage: process.env.FEE_PERCENTAGE_FOR_PAYMENT,  // ❌ Wrong location
    feeAddress: process.env.FEE_ADDRESS_FOR_PAYMENT,        // ❌ Wrong location
  })),
  requestIds: input.requestIds,  // ❌ No fee fields for this path
  payer: input.payer,
});

// FIXED
const response = await apiClient.post("v2/payouts/batch", {
  requests: input.payouts?.map((payout) => ({ ... })),  // No fee fields here
  requestIds: input.requestIds,
  payer: input.payer,
  ...(process.env.FEE_PERCENTAGE_FOR_PAYMENT && process.env.FEE_ADDRESS_FOR_PAYMENT && {
    feePercentage: process.env.FEE_PERCENTAGE_FOR_PAYMENT,  // ✅ Body level
    feeAddress: process.env.FEE_ADDRESS_FOR_PAYMENT,        // ✅ Body level
  }),
});

Considerations

  • Severity: CRITICAL - Revenue loss bug
  • Affected file: src/server/routers/payment.ts (lines 60-74)
  • Single payout (pay) is correct, only batchPay is broken
  • API schema reference: request-api/src/validation/schemas/pay.schema.ts (lines 343-414)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcritical

    Type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions