checkout_session_id- Extract from redirect URL (e.g.,fcs_01kbjcmbt5mhsmaggfqc1a4rns)- This ID is required for creating refunds
payment_intent_id- Flex’s internal payment IDlatest_charge- Charge IDstatus- Should becompletefor refunds
Primary Refund Endpoint
POST /v1/checkout/sessions//refund
This is the main refund endpoint for processing refunds on completed checkout sessions. Base URL:https://api.withflex.com (or your custom domain)
Authentication:
Request Format
Option 1: Line Item-Based Refund (Granular Control)
Refund specific products/prices with custom amounts:price instead of product
Option 2: Simple Amount-Based Refund
Refund a specific total amount without line item breakdown:Option 3: Full Refund
Refund the entire checkout session amount:Request Parameters
| Field | Type | Required | Description |
|---|---|---|---|
line_items | array | No | Specific line items to refund with amounts |
line_items[].product | string | One of | Product ID to refund (e.g., fprod_xxx) |
line_items[].price | string | product/price | Price ID to refund (e.g., fprice_xxx) |
line_items[].amount_to_refund | integer | No | Amount in cents for this item (omit for full item refund) |
amount | integer | No | Total amount to refund in cents (alternative to line_items) |
amount_tax | integer | No | Tax amount to refund in cents |
amount_shipping | integer | No | Shipping amount to refund in cents |
amount_discount | integer | No | Discount amount to refund in cents |
refund_metadata | object | No | Key-value pairs for tracking (order ID, reason, etc.) |
Success Response
Status Code:200 OK
refunds[].refund_id- Store this for tracking refund statusrefunds[].status- Current refund status (pending,succeeded,failed)refunds[].reference_id- Acquirer Reference Number (ARN) for bank tracking (populated later)refunds[].reference_status- Status of reference number (pending,available,unavailable)
Error Responses
Checkout Session Not Complete (422 Unprocessable Entity)
complete
Checkout Session Not Found (404 Not Found)
checkout_session_id or doesn’t belong to your account
Unauthorized (401 Unauthorized)
Authorization header
Refund Statuses
| Status | Description |
|---|---|
pending | Refund initiated, processing in progress |
requires_action | Additional action required (rare) |
succeeded | Refund completed, funds returned to customer |
failed | Refund failed (usually insufficient funds in connected account) |
canceled | Refund was canceled |
- Refund status updates to
succeededwithin minutes to hours - Funds appear in customer’s account within 5-10 business days (varies by bank)
Reference Numbers for Tracking
Flex provides reference numbers that can be used to track refunds with banks and payment networks.Reference Types
| Type | Description |
|---|---|
acquirer_reference_number | ARN - Most common, used for tracking with issuing banks |
system_trace_audit_number | Alternative tracking number for payment networks |
retrieval_reference_number | Used for dispute resolution and chargebacks |
Reference Status
| Status | Description |
|---|---|
pending | Reference number not yet available from payment network |
available | Reference number ready, can be provided to customer/bank |
unavailable | Payment network doesn’t provide this reference type |
Complete Workflow Examples
Example 1: Full Refund
Step 1: Customer completes payment You receive redirect after successful payment:Example 2: Partial Refund by Line Items
Scenario: Customer returns 1 of 3 items purchased Request:- Refunding only the yoga mat: $35.00
- Including proportional tax: $2.80
- Not refunding shipping (customer kept other items)
- Total refund: $37.80
Example 3: Partial Refund by Amount
Scenario: Price adjustment without item-level detail Request:- Refunding $20.00 difference due to price match
- No line item breakdown needed
- Metadata tracks the reason
Example 4: Multiple Partial Refunds
You can create multiple refunds for the same checkout session until the full amount is refunded. First refund: $50Secondary Refund API
Tracking and Listing Refunds
After creating a refund via the checkout session endpoint, use the secondary refund API to track status:GET /v1/refunds/
GET /v1/refunds (List Refunds)
Query Parameters:payment_intent- Filter by payment intent IDcheckout_session- Filter by checkout session IDstatus- Filter by status
PATCH /v1/refunds/ (Update Refund Metadata)
Update refund metadata or reason (does not change amount or status):Implementation Details
Automatic Handling by Flex
Flex automatically handles: ✅ Reverse Transfer - Funds are clawed back from the connected account (partner) ✅ Application Fee Retention - Flex keeps the platform fee (not refunded) ✅ Webhook Processing - Status updates via Stripe webhooks ✅ Charge Tracking - Records which charges were refunded inrefund_charge table ✅ Reference Number Retrieval - ARN and other tracking numbers populated when available
Partial Refund Behavior
- Can refund any amount up to the original charge amount
- Multiple partial refunds allowed until full amount refunded
- Track
amount_receivedvs total refunded to calculate remaining refundable amount
Tax, Shipping, and Discount Refunds
When refunding line items, you can specify component amounts:Best Practices
1. Store Checkout Session ID
Always save thecheckout_session_id after payment completion:
2. Verify Checkout Session Status
Before attempting refund, confirm the session is complete:3. Use Metadata for Tracking
Always include metadata to track refund context:4. Handle Refund Webhooks
Subscribe to Flex webhooks for automatic refund status updates: Event Types:refund.created- Refund initiatedrefund.succeeded- Refund completed successfullyrefund.failed- Refund failed
5. Track Remaining Refundable Amount
For multiple partial refunds, track the remaining amount:6. Save Reference Numbers
Store ARNs for customer support inquiries:7. Handle Errors Gracefully
Testing
Test Mode
Use test API keys (starting withsk_test_) to test refunds without affecting real money:
- Refunds complete instantly with
status: "succeeded" - No actual money movement
- Reference IDs still generated for testing
- Full webhook flow works
Test Credentials
For testing payments → refunds flow: Email:miguel@homefit.com Password: password
Create test API keys at: http://localhost:3001/partners/dashboard/developers
Troubleshooting
Problem: “Checkout session must be complete”
Cause: Trying to refund a checkout session that hasn’t been paid or is in progress Solution:- Check session status:
GET /v1/checkout/sessions/{id} - Ensure
status === "complete" - Wait for payment to finish if still processing
Problem: “checkout session does not exist”
Cause: Invalid checkout session ID or doesn’t belong to your account Solution:- Verify the
checkout_session_idis correct - Ensure you’re using the right API key (test vs. production)
- Check that the session belongs to your partner account
Problem: Refund shows “pending” for too long
Cause: Stripe processing delay or connected account issues Solution:- Wait up to 24 hours for normal processing
- Check Stripe dashboard for errors
- Verify connected account has sufficient balance
- Contact support if still pending after 24 hours
Problem: “Failed to create refund”
Cause: Stripe API error (usually insufficient funds in connected account) Solution:- Check connected account balance in Stripe dashboard
- Ensure partner account has funds to cover refund
- Review Stripe logs for specific error details
- Contact Flex support with
checkout_session_id
Problem: Reference ID not available
Cause: Payment network hasn’t provided ARN yet Solution:- Reference IDs typically appear within hours
- Check
reference_status- ifpending, wait - If
unavailable, payment network doesn’t provide this type - Poll
/v1/refunds/{refund_id}periodically for updates
API Endpoint Summary
| Endpoint | Method | Purpose |
|---|---|---|
/v1/checkout/sessions/{id}/refund | POST | Primary - Create refund for checkout session |
/v1/refunds | GET | List all refunds with filters |
/v1/refunds/{refund_id} | GET | Get single refund details |
/v1/refunds/{refund_id} | PATCH | Update refund metadata |
/v1/checkout/sessions/{id} | GET | Get checkout session details |
Common Use Cases
Use Case 1: Customer Service Full Refund
Use Case 2: Return Processing with Line Items
Use Case 3: Price Adjustment
Additional Resources
- Flex API Documentation: Contact your Flex account manager
- Stripe Refund Guide: https://stripe.com/docs/refunds
- Reference Numbers: https://support.stripe.com/questions/how-to-trace-a-refund-using-reference-numbers
- Webhooks Setup: Contact Flex support for webhook configuration
Support
For issues or questions about refunds:- Check this guide for common solutions
- Review Stripe dashboard for payment details
- Contact Flex support with:
checkout_session_idrefund_id(if refund was created)- Error messages
- Timestamp of the issue