Playground API
DocsStatsBlogStudio
Documentation Tree
Technical BlogFeature Deep Dives
  • Introduction
  • Quickstart
    5 min
  • How It Works
  • Recipes & Cookbooks
  • Platform Comparisons
  • Real-World Showcase
  • Interactive Studio
    Studio
  • GraphiQL IDE
    IDE
  • Session Quotas & Activity
  • Network Chaos Simulator
  • Atomic Sandbox Reset
  • Overview & Models
    Hub
  • Users Resource
  • Posts Resource
  • Comments Resource
  • Todos Resource
  • Custom Collections
    Custom
  • Multipart File Uploads
    Upload
  • Dynamic SVG Avatars
    SVG
  • Image Thumbnails
    CDN
  • Relational Filtering
  • Full-Text Search
  • Dynamic Sorting
  • Offset Pagination
  • Cursor Pagination
    Scroll
  • CSV & Excel Export & Import
    IO
  • Custom Collections
    CRUD
  • Overview & Architecture
    Hub
  • JWT Auth Flow
  • Refresh Token Rotation
    Mutex
  • RBAC Permission Matrix
    Roles
  • Expiry Simulation
  • Clock Skew Drift
  • Password Recovery Loop
  • Dual-Mode Sandboxing
  • GraphiQL IDE
    IDE
  • Relational Queries
  • Stateful Mutations
  • Realtime Subscriptions
  • Overview & Flowcharts
    Hub
  • Hosted Checkout
    Stripe
  • Payment Intents API
  • 3DS Challenge Modal
    Modal
  • Customers Vault
  • Charges & Refunds
  • Test Cards Catalog
  • Overview & Channels
    Hub
  • Virtual Email Mailbox
    Mailtrap
  • Virtual SMS Terminal
    Phone
  • In-App Notifications
  • Message Dispatcher
  • Realtime Studio
    Studio
  • Native WebSocket (/ws)
  • Socket.io Gateway
  • Presence & Echo Bot
  • Server-Sent Events (SSE)
    SSE
  • Analytics Telemetry
  • Webhook Subscriptions
  • HMAC SHA-256 Signatures
  • Delivery Logs
  • Manual Retry Simulator
  • Network Latency Delay
  • HTTP Status Codes
  • Rate-Limit Simulator
    429
  • Flaky Network & Jitter
    Chaos
  • Session Quotas & Activity
  • JSON Snapshots
    JSON
  • Headless CI/CD Testing
    CI
  • Mobile QR Code Sync
  • System Metrics & Health
  • Atomic Sandbox Reset
  • Official TypeScript SDK
  • Multi-Language Generators
  • DevTools Extension
  • OpenAPI 3.1 Spec
    JSON
  • Postman Collection v2.1
  • Bruno Collection
  • Insomnia Workspace
  • TypeScript .d.ts
    .d.ts
  • AI Prompt Rules
    Rules
  • Context Index (llms.txt)
  • Full Schema (llms-full.txt)
  • Manifest (product.json)
  • All Feature Articles
    Blog
  • React CRUD Without Backend
    Deep Dive
  • Why Static APIs Fail
  • Mocking Stateful Auth
  • WebSockets & SSE Guide
Technical Blog
Articles

In-depth articles explaining stateful mock APIs, WebSockets, payments, and frontend resilience.

Read Articles
PreviousCustomers Vault
NextTest Cards Catalog
Mock Commerce & Billing

Direct Charges & Refunds API

Execute single-step charges without client-side tokenization, and issue full or partial refunds against settled transactions. Includes automatic ledger recalculations, status transitions (partially_refunded vs refunded), and webhook dispatching.

Partial Refund CalculatorAPI ConsolesCode Recipes

Interactive Partial Refund Simulator

Slide to adjust the refund amount and inspect ledger updates and terminal status tags in real time.

Refund Amount Slider$30.00 USD
Ledger State
Original Charged:$80.00
Amount to Refund:-$30.00
Remaining Net:$50.00
Resulting Status:partially_refunded

Interactive API Consoles

Execute direct card transactions and refund requests against your isolated visitor sandbox.

1. Direct 1-Step Card Charge

Process Direct Charge

POST
response.json
1
{
2
// Click "Send" above to execute this request against the live server.
3
}

2. Issue Full or Partial Refund

Issue Refund Against Payment Intent

POST
response.json
1
{
2
// Click "Send" above to execute this request against the live server.
3
}

3. List All Processed Refunds

List Sandbox Refunds

GET
response.json
1
{
2
// Click "Send" above to execute this request against the live server.
3
}

Production Integration Recipes

Safe idempotency patterns and customer service refund workflows.

Idempotent Refund Helper (Node.js)

javascript
1
import axios from 'axios';
2
3
// Safely refund an order with duplicate-click protection
4
export async function refundOrder(paymentIntentId, amountCents, reason = 'requested_by_customer') {
5
const idempotencyKey = rf_${paymentIntentId}_${amountCents};
6
7
try {
8
const res = await axios.post(
9
'https://playground.nileslabs.com/api/v1/payments/refunds',
10
{
11
payment_intent: paymentIntentId,
12
amount: amountCents,
13
reason,
14
},
15
{
16
headers: { 'Idempotency-Key': idempotencyKey },
17
}
18
);
19
20
console.log('Refund successful:', res.data.id, 'Status:', res.data.status);
21
return res.data;
22
} catch (err) {
23
console.error('Refund failed:', err.response?.data?.error?.message);
24
throw err;
25
}
26
}

Automated Refund Worker (Python)

python
1
import requests
2
3
def issue_partial_refund(intent_id: str, amount_cents: int, reason: str = "requested_by_customer"):
4
url = "https://playground.nileslabs.com/api/v1/payments/refunds"
5
headers = {"Idempotency-Key": f"ref_{intent_id}_{amount_cents}"}
6
payload = {
7
"payment_intent": intent_id,
8
"amount": amount_cents,
9
"reason": reason
10
}
11
12
response = requests.post(url, json=payload, headers=headers)
13
response.raise_for_status()
14
15
data = response.json()
16
print(f"Issued refund {data['id']} for {data['amount']} cents")
17
return data