Skip to main content
POST
https://api.hedgepayments.com/v1
/
v1
/
transactions
Process Payment
curl --request POST \
  --url https://api.hedgepayments.com/v1/v1/transactions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "amount": 123,
  "currency": "<string>",
  "method": "<string>",
  "paymentMethodId": "<string>",
  "sourceWalletId": "<string>",
  "destinationWalletId": "<string>",
  "description": "<string>",
  "metadata": {},
  "idempotencyKey": "<string>"
}
'
{
  "id": "<string>",
  "type": "<string>",
  "status": "<string>",
  "amount": 123,
  "currency": "<string>",
  "fee": 123,
  "netAmount": 123,
  "sourceWalletId": "<string>",
  "destinationWalletId": "<string>",
  "paymentMethodId": "<string>",
  "description": "<string>",
  "metadata": {},
  "createdAt": "<string>",
  "completedAt": "<string>"
}

Overview

Process a payment transaction using various payment methods including credit cards, bank transfers, cryptocurrency, or internal wallet transfers. This endpoint supports both one-time payments and authorizations. Powered by CoinFlow: This endpoint uses CoinFlow’s payment infrastructure for processing card, ACH, and crypto payments.

Authentication

Authorization: Bearer YOUR_API_KEY

Request Body

amount
number
required
Transaction amount in the smallest currency unit (cents for fiat, wei/lamports for crypto)Examples:
  • USD: 10000 = $100.00
  • EUR: 5000 = €50.00
  • SOL: 1000000000 = 1 SOL
  • USDC: 1000000 = 1 USDC (6 decimals)
currency
string
required
Three-letter currency code (ISO 4217) or crypto tickerSupported: USD, EUR, GBP, BTC, ETH, SOL, USDC, USDT
method
string
required
Payment method to useOptions:
  • card - Credit/debit card
  • ach - ACH bank transfer (US only)
  • wire - Wire transfer
  • wallet - Wallet-to-wallet transfer
  • crypto - Direct cryptocurrency payment
  • apple_pay - Apple Pay
  • google_pay - Google Pay
paymentMethodId
string
ID of a saved payment method (for card, ACH, bank transfers)Required for: card, ach, wallet methods when not using one-time tokens
sourceWalletId
string
Wallet ID to debit funds from (required for wallet-to-wallet transfers)
destinationWalletId
string
Wallet ID to credit funds to (required for wallet-to-wallet transfers)
description
string
Human-readable description of the transactionExample: "Order #12345 - Premium Subscription"
metadata
object
Custom key-value pairs to attach to the transactionExample:
{
  "orderId": "order_12345",
  "productId": "prod_premium_monthly",
  "customerId": "cust_abc123"
}
idempotencyKey
string
Unique key to prevent duplicate transactions (recommended for all requests)Example: "payment-order_12345-2025-11-18"

Request Examples

{
  "amount": 10000,
  "currency": "USD",
  "method": "card",
  "paymentMethodId": "pm_card_abc123",
  "description": "Premium Subscription - Monthly",
  "metadata": {
    "orderId": "order_12345",
    "plan": "premium_monthly"
  },
  "idempotencyKey": "payment-order_12345-2025-11-18"
}

Response

id
string
Unique transaction identifier
type
string
Transaction type: deposit, withdrawal, transfer_in, transfer_out, payment, refund, fee, adjustment
status
string
Current status: pending, processing, completed, failed, reversed, refunded, cancelled
amount
number
Transaction amount in smallest currency unit
currency
string
Currency code
fee
number
Processing fee charged
netAmount
number
Net amount after fees (amount - fee)
sourceWalletId
string
Wallet debited (if applicable)
destinationWalletId
string
Wallet credited (if applicable)
paymentMethodId
string
Payment method used
description
string
Transaction description
metadata
object
Custom metadata attached
createdAt
string
ISO 8601 creation timestamp
completedAt
string
ISO 8601 completion timestamp (null if not completed)

Response Examples

{
  "id": "txn_9x8y7z6a5b4c",
  "type": "payment",
  "status": "completed",
  "amount": 10000,
  "currency": "USD",
  "fee": 320,
  "netAmount": 9680,
  "paymentMethodId": "pm_card_abc123",
  "description": "Premium Subscription - Monthly",
  "metadata": {
    "orderId": "order_12345",
    "plan": "premium_monthly"
  },
  "createdAt": "2025-11-18T22:30:00Z",
  "completedAt": "2025-11-18T22:30:02Z"
}

Code Examples

import { HedgePayments } from '@hedgepayments/sdk';

const hedge = new HedgePayments(process.env.HEDGE_API_KEY);

async function processPayment() {
  try {
    const transaction = await hedge.transactions.create({
      amount: 10000, // $100.00
      currency: 'USD',
      method: 'card',
      paymentMethodId: 'pm_card_abc123',
      description: 'Premium Subscription',
      metadata: {
        orderId: 'order_12345',
        customerId: 'cust_abc'
      },
      idempotencyKey: `payment-${Date.now()}`
    });

    if (transaction.status === 'completed') {
      console.log('Payment successful:', transaction.id);
      // Fulfill order
    } else {
      console.log('Payment pending:', transaction.status);
      // Wait for webhook
    }

    return transaction;
  } catch (error) {
    if (error.code === 'INSUFFICIENT_FUNDS') {
      console.log('Payment declined - insufficient funds');
    } else if (error.code === 'CARD_DECLINED') {
      console.log('Card declined by issuer');
    }
    throw error;
  }
}

Payment Methods Comparison

MethodProcessing TimeSettlementFeesReversibleGeographic
CardInstantT+1 to T+3~2.9% + $0.30Yes (chargebacks)Global
ACH1-3 daysT+3 to T+5~1%Yes (returns)US only
Wire1-3 daysSame day$25 flatNoGlobal
WalletInstantInstant0%NoGlobal
Crypto5-60 minInstantNetwork feesNoGlobal
Apple PayInstantT+1 to T+3~2.9% + $0.30YesGlobal
Google PayInstantT+1 to T+3~2.9% + $0.30YesGlobal

Error Codes

CodeHTTPDescriptionAction
INSUFFICIENT_FUNDS402Not enough balanceAdd funds or use different payment method
CARD_DECLINED402Card issuer declinedContact card issuer or try different card
INVALID_PAYMENT_METHOD400Payment method not valid for currencyUse supported method
PAYMENT_METHOD_NOT_FOUND404Payment method ID doesn’t existVerify payment method ID
AMOUNT_TOO_SMALL400Below minimum amountIncrease amount (min $0.50)
AMOUNT_TOO_LARGE400Exceeds limitsSplit into multiple transactions
DUPLICATE_TRANSACTION409Idempotency key already usedUse unique key or retrieve existing
RATE_LIMIT_EXCEEDED429Too many requestsImplement backoff

Webhooks

Transaction events trigger webhooks:
{
  "event": "transaction.completed",
  "data": {
    "id": "txn_abc123",
    "amount": 10000,
    "currency": "USD",
    "status": "completed",
    "completedAt": "2025-11-18T22:30:02Z"
  }
}

Best Practices

1. Always Use Idempotency Keys

// Generate unique key per attempt
const idempotencyKey = `payment-${orderId}-${Date.now()}`;

const transaction = await hedge.transactions.create({
  amount: 10000,
  currency: 'USD',
  idempotencyKey // Prevents duplicate charges
});

2. Handle Async Payments

Some methods (ACH, wire) are asynchronous:
const transaction = await hedge.transactions.create({ ... });

if (transaction.status === 'processing') {
  // Don't fulfill order yet
  // Wait for webhook notification
  console.log('Payment pending, estimated:', transaction.estimatedCompletion);
} else if (transaction.status === 'completed') {
  // Instant payment - fulfill immediately
  fulfillOrder(orderId);
}

3. Implement Retry Logic

async function processPaymentWithRetry(data, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await hedge.transactions.create(data);
    } catch (error) {
      if (error.code === 'RATE_LIMIT_EXCEEDED' && i < maxRetries - 1) {
        await sleep(Math.pow(2, i) * 1000); // Exponential backoff
        continue;
      }
      throw error;
    }
  }
}

Support

Questions? Contact us: