Skip to main content
GET
/
transactions
/
reference
/
:reference
curl -X GET https://api.blnkfinance.com/transactions/reference/order-12345 \
  -H "Authorization: Bearer YOUR_API_KEY"
{
  "transaction_id": "txn_a1b2c3d4e5f6",
  "source": "bln_src123",
  "destination": "bln_dst456",
  "reference": "order-12345",
  "amount": 100.50,
  "precise_amount": "10050",
  "precision": 100,
  "currency": "USD",
  "description": "Payment for order #12345",
  "status": "APPLIED",
  "hash": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
  "allow_overdraft": false,
  "inflight": false,
  "created_at": "2024-01-15T10:30:00Z",
  "meta_data": {
    "customer_id": "cust_123",
    "order_id": "order-12345"
  }
}
Retrieve a transaction using its unique reference identifier. This is useful when you store your own reference IDs and need to look up the corresponding Blnk transaction.

Path Parameters

reference
string
required
The unique reference identifier assigned when creating the transaction (e.g., order-12345).

Response

Returns a complete transaction object. See Get Transaction for full field documentation.
transaction_id
string
Unique transaction identifier.
reference
string
The reference used to look up this transaction.
source
string
Source balance ID.
destination
string
Destination balance ID.
amount
number
Transaction amount in major currency units.
precise_amount
string
Transaction amount in minor units.
currency
string
Currency code.
status
string
Transaction status.
created_at
string
ISO 8601 creation timestamp.
See Get Transaction for all available fields.
{
  "transaction_id": "txn_a1b2c3d4e5f6",
  "source": "bln_src123",
  "destination": "bln_dst456",
  "reference": "order-12345",
  "amount": 100.50,
  "precise_amount": "10050",
  "precision": 100,
  "currency": "USD",
  "description": "Payment for order #12345",
  "status": "APPLIED",
  "hash": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
  "allow_overdraft": false,
  "inflight": false,
  "created_at": "2024-01-15T10:30:00Z",
  "meta_data": {
    "customer_id": "cust_123",
    "order_id": "order-12345"
  }
}
curl -X GET https://api.blnkfinance.com/transactions/reference/order-12345 \
  -H "Authorization: Bearer YOUR_API_KEY"

Error Responses

error
string
Error message describing what went wrong.

Common Errors

400 Bad Request - Missing Reference
{
  "error": "reference is required. pass reference in the route /ref/:reference"
}
Returned when the reference parameter is missing from the URL. 400 Bad Request - Not Found
{
  "error": "transaction not found with reference: order-12345"
}
Returned when no transaction exists with the specified reference.

Use Cases

Idempotent Transaction Creation

Check if a transaction already exists before creating a new one:
async function createIdempotentTransaction(transactionData) {
  const { reference } = transactionData;
  
  // Try to get existing transaction
  try {
    const existing = await fetch(
      `/transactions/reference/${reference}`
    ).then(r => r.json());
    
    // Transaction already exists
    console.log('Transaction already created:', existing.transaction_id);
    return existing;
  } catch (err) {
    // Transaction doesn't exist, create it
    return await fetch('/transactions', {
      method: 'POST',
      body: JSON.stringify(transactionData)
    }).then(r => r.json());
  }
}

Order Payment Reconciliation

Match your order system with Blnk transactions:
def reconcile_order_payment(order_id):
    # Build reference from order ID
    reference = f"order-{order_id}"
    
    # Fetch transaction
    response = requests.get(
        f'/transactions/reference/{reference}',
        headers={'Authorization': f'Bearer {API_KEY}'}
    )
    
    if response.status_code == 200:
        transaction = response.json()
        
        # Verify payment
        if transaction['status'] == 'APPLIED':
            print(f"Order {order_id} paid: {transaction['amount']} {transaction['currency']}")
            return True
        elif transaction['status'] == 'INFLIGHT':
            print(f"Order {order_id} payment pending")
            return False
        else:
            print(f"Order {order_id} payment failed")
            return False
    else:
        print(f"No payment found for order {order_id}")
        return False

Webhook Event Handling

Verify webhook events by looking up transactions:
app.post('/webhooks/order-created', async (req, res) => {
  const { orderId, amount, currency } = req.body;
  const reference = `webhook-order-${orderId}`;
  
  try {
    // Check if we already processed this webhook
    const existing = await getTransactionByReference(reference);
    
    console.log('Webhook already processed');
    res.json({ status: 'duplicate', transaction_id: existing.transaction_id });
  } catch (err) {
    // New webhook, create transaction
    const transaction = await createTransaction({
      reference,
      amount,
      currency,
      description: `Order ${orderId}`,
      source: 'customer_balance',
      destination: 'merchant_balance'
    });
    
    res.json({ status: 'created', transaction_id: transaction.transaction_id });
  }
});

Refund Processing

Create refund transactions linked to original payments:
def process_refund(original_reference, refund_amount):
    # Get original transaction
    original = get_transaction_by_reference(original_reference)
    
    if original['status'] != 'APPLIED':
        raise ValueError('Cannot refund non-applied transaction')
    
    # Create refund with linked reference
    refund_reference = f"{original_reference}-refund"
    
    # Check if refund already exists
    try:
        existing_refund = get_transaction_by_reference(refund_reference)
        return existing_refund
    except:
        pass
    
    # Create new refund
    refund = create_transaction({
        'reference': refund_reference,
        'amount': refund_amount,
        'currency': original['currency'],
        'description': f"Refund for {original_reference}",
        'source': original['destination'],  # Reverse the flow
        'destination': original['source'],
        'meta_data': {
            'original_transaction_id': original['transaction_id'],
            'refund_type': 'partial' if refund_amount < original['amount'] else 'full'
        }
    })
    
    return refund

Transaction Status Monitoring

Poll for transaction completion using reference:
async function waitForTransactionByReference(reference, timeoutMs = 30000) {
  const startTime = Date.now();
  
  while (Date.now() - startTime < timeoutMs) {
    try {
      const txn = await fetch(
        `/transactions/reference/${reference}`
      ).then(r => r.json());
      
      if (txn.status === 'APPLIED') {
        return { success: true, transaction: txn };
      }
      
      if (txn.status === 'REJECTED') {
        return { 
          success: false, 
          error: txn.meta_data?.blnk_rejection_reason || 'Transaction rejected'
        };
      }
      
      // Still processing, wait and retry
      await new Promise(resolve => setTimeout(resolve, 1000));
    } catch (err) {
      // Transaction doesn't exist yet, wait and retry
      await new Promise(resolve => setTimeout(resolve, 1000));
    }
  }
  
  return { success: false, error: 'Timeout waiting for transaction' };
}

// Usage
const result = await waitForTransactionByReference('order-12345');
if (result.success) {
  console.log('Transaction completed:', result.transaction);
} else {
  console.error('Transaction failed:', result.error);
}

Reference Best Practices

1. Use Descriptive Prefixes

Include the transaction type in the reference:
const references = {
  order: `order-${orderId}`,
  refund: `refund-${refundId}`,
  payout: `payout-${payoutId}`,
  subscription: `sub-${subscriptionId}-${period}`,
  transfer: `transfer-${transferId}`
};

2. Ensure Uniqueness

Combine multiple identifiers to guarantee uniqueness:
import uuid
from datetime import datetime

# Include timestamp
reference = f"order-{order_id}-{int(datetime.now().timestamp())}"

# Include UUID
reference = f"payment-{order_id}-{uuid.uuid4().hex[:8]}"

# Include customer ID
reference = f"txn-{customer_id}-{order_id}"

3. Keep References Readable

Avoid very long or cryptic references:
// Good
"order-12345"
"refund-order-12345"
"sub-abc123-2024-01"

// Avoid
"a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6"
"txn_2024_01_15_customer_abc_order_12345_payment_card_final_v2"

4. Document Reference Format

Maintain a reference format guide:
// Reference Format Documentation
type TransactionReference = 
  | `order-${string}`           // Customer order payments
  | `refund-${string}`          // Refund transactions
  | `payout-${string}`          // Seller payouts
  | `sub-${string}-${string}`   // Subscription charges
  | `fee-${string}`             // Fee transactions
  | `adjust-${string}`;         // Manual adjustments

Comparison: Get by ID vs Get by Reference

FeatureGet by IDGet by Reference
EndpointGET /transactions/:idGET /transactions/reference/:reference
Use whenYou have the Blnk transaction IDYou have your own reference ID
PerformanceSlightly faster (direct lookup)Fast (indexed lookup)
UniquenessGuaranteed unique (Blnk generated)Must ensure uniqueness
IdempotencyNot useful for idempotencyEnables idempotent requests

Build docs developers (and LLMs) love