Logo
API ReferenceWithdraws

Cancel Withdraw

Cancels a withdraw that is in a cancellable status. Only withdraws in pending or processing status can be cancelled.

Endpoint

POST /api/v1/withdraws/{withdraw_id}/cancel

Authentication

This endpoint requires HMAC Integration Authentication.

Path Parameters

ParameterTypeRequiredDescription
withdraw_idstringYesThe UUID of the withdraw to cancel

Example Request

import crypto from 'crypto';

const API_KEY = process.env.PAYMENT_API_KEY!;
const API_SECRET = process.env.PAYMENT_API_SECRET!;

async function cancelWithdraw(withdrawId: string) {
  const method = 'POST';
  const path = `/api/v1/withdraws/${withdrawId}/cancel`;
  const body = '';
  const timestamp = Date.now().toString();

  const message = `${timestamp}.${body}`;
  const signature = crypto
    .createHmac('sha256', API_SECRET)
    .update(message)
    .digest('hex');

  const response = await fetch(`https://api.example.com${path}`, {
    method,
    headers: {
      'X-API-Key': API_KEY,
      'X-Timestamp': timestamp,
      'X-Signature': `sha256=${signature}`,
    },
  });

  const result = await response.json();

  if (result.success) {
    console.log('Withdraw cancelled:', result.data.id);
    console.log('Status:', result.data.status);
    return result.data;
  } else {
    console.error('Error:', result.error);
    throw new Error(result.error.message);
  }
}

// Cancel withdraw
const withdraw = await cancelWithdraw('660e8400-e29b-41d4-a716-446655440001');

Response

Success Response (200 OK)

{
  "success": true,
  "data": {
    "id": "660e8400-e29b-41d4-a716-446655440001",
    "amount": "1000.00",
    "currency": "THB",
    "status": "canceled",
    "referenceId": "payout-12345",
    "destinationType": "bank_account",
    "bankAccountNumber": "1234****7890",
    "bankAccountName": "John Doe",
    "bankCode": "004",
    "destinationId": null,
    "description": "Payout for order #12345",
    "metadata": {
      "order_id": "12345"
    },
    "paidAt": null,
    "canceledAt": "2024-01-01T00:10:00.000Z",
    "createdAt": "2024-01-01T00:00:00.000Z",
    "updatedAt": "2024-01-01T00:10:00.000Z"
  }
}

Error Responses

Withdraw Not Found (404)

{
  "success": false,
  "error": {
    "code": "RESOURCE_NOT_FOUND",
    "message": "Withdraw not found"
  }
}

Withdraw Cannot Be Cancelled (400)

{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Withdraw cannot be cancelled because it has already been completed"
  }
}

Cancellation Rules

Important

Only withdraws in pending or processing status can be cancelled. Withdraws that are paid, failed, or canceled cannot be cancelled.

Cancellable Statuses

  • pending - Withdraw can be cancelled
  • processing - Withdraw can be cancelled (if provider supports it)

Non-cancellable Statuses

  • paid - Withdraw has already been completed
  • failed - Withdraw has already failed
  • canceled - Withdraw is already cancelled

See Also

On this page