Complete Payment Flow: From Checkout to Settlementβ
This guide demonstrates the complete payment lifecycle with Walley, from checkout initialization to settlement. It shows you how to build a robust integration that handles every stage of a successful transaction.
Prerequisitesβ
Before implementing this flow, ensure you have:
- Walley merchant account with API credentials
- Access to Merchant Hub for webhook configuration (if using Approach B in Phase 2, see below)
Complete payment flowβ
The full payment lifecycle involves five key phases, each with specific merchant-side integrations:
Choose your integration approachβ
Choose how you'll receive order notifications and obtain the orderId for order management:
- Approach A: Notification Callback - Simple callback integration. Receive
privateIdvia GET request, then fetchorderIdusing Get Checkout Information API. - Approach B: Webhook Subscription - Event-driven integration. Receive
orderIddirectly in webhook payload, no additional API call needed.
Both approaches support the same retry mechanism. See sections below for implementation details.
Phase 1: Purchaseβ
Create a checkout session to get a publicToken for rendering the checkout iframe and a privateId for order tracking.
Request:
POST /checkouts HTTP/1.1
Host: api.uat.walleydev.com
Authorization: Bearer bXlVc2VybmFtZTpmN2E1ODA4MGQzZTk0M2VmNWYyMTZlMDE...
{
"storeId": 123,
"countryCode": "SE",
"reference": "ORDER-2024-12345",
"merchantTermsUri": "https://example.com/terms",
"notificationUri": "https://example.com/api/walley/notify",
"cart": {
"items": [
{
"id": "PROD-001",
"description": "Wireless Headphones",
"unitPrice": 999.00,
"quantity": 1,
"vat": 25.0
}
]
}
}
Response:
{
"data": {
"privateId": "6f4a9bc3-8d2e-4f1a-9b7c-3e8d2f1a9b7c",
"publicToken": "public-SE-7f1b3d2a2a73d348dfbd17d3965ff1458c249f84c695eac1"
}
}
Use publicToken to render the checkout iframe. See Initialize Checkout API for all options.
Phase 2: Receive Order Informationβ
Approach A: Notification Callback + Get Checkout Informationβ
Step 1: Receive notification
GET /api/walley/notify?privateId=6f4a9bc3-8d2e-4f1a-9b7c-3e8d2f1a9b7c HTTP/1.1
Host: example.com
Respond with 200 OK. See Notification Callback for details.
Step 2: Get Checkout Information
GET /checkouts/6f4a9bc3-8d2e-4f1a-9b7c-3e8d2f1a9b7c HTTP/1.1
Host: api.uat.walleydev.com
Authorization: Bearer bXlVc2VybmFtZTpmN2E1ODA4MGQzZTk0M2VmNWYyMTZlMDE...
Extract data.order.orderId from the response to use for order management. See Get Checkout Information API for complete response details
Approach B: Webhook Subscription (walley:order:created)β
Subscribe to walley:order:created event in Merchant Hub to receive orderId directly in webhook payload - no additional API call needed.
Example webhook payload:
{
"Type": "walley:order:created",
"Timestamp": "2024-12-04T15:02:42.5997621+01:00",
"Payload": {
"OrderId": "7890abcd-ef12-3456-7890-abcdef123456",
"Reference": "ORDER-2024-12345",
"Amount": 1250.00,
"Currency": "SEK",
"Status": "Authorized"
}
}
See Webhooks Overview and Webhooks for Orders for implementation details.
Phase 3: Capture Paymentβ
When order items are ready to be delivered, capture the payment to finalize the transaction and transfer funds. This can only be done on orders with status NotActivated or PartActivated.
When to execute: When goods are shipped or services are delivered.
The system is eventually consistent. If you attempt to capture payment immediately after receiving the order notification, you may encounter 404 Not Found or 403 Forbidden status codes. Implement retry logic with exponential backoff to handle these transient states while the order becomes fully available.
Basic capture request:
POST /orders/7890abcd-ef12-3456-7890-abcdef123456/captures HTTP/1.1
Host: api.uat.walleydev.com
Authorization: Bearer bXlVc2VybmFtZTpmN2E1ODA4MGQzZTk0M2VmNWYyMTZlMDE...
Content-Type: application/json
{
"amount": 1248.00,
"actionReference": "SHIP-2024-12345",
"items": [
{
"id": "PROD-001",
"description": "Wireless Headphones",
"unitPrice": 999.00,
"quantity": 1,
"vat": 25.0
},
{
"id": "SHIP-001",
"description": "Standard Shipping",
"unitPrice": 49.00,
"quantity": 1,
"vat": 25.0
}
]
}
Response:
Status: 202 Accepted
Location: /manage/orders/7890abcd-ef12-3456-7890-abcdef123456
Key points:
- Capture full order or partial amounts (e.g., only shipped items)
- Only captured amounts are settled to your account
- Response is
202 Accepted- processing is asynchronous - Multiple partial captures are supported
For detailed information including partial capture, capture by amount, replacing items, and error handling, see Capture Order API documentation.
Phase 4: Refund Managementβ
Refunds can only be issued against captured amounts. When a customer returns items or requires compensation, use the Refund API to process full or partial refunds.
When to execute: When refund is needed.
Basic refund request:
POST /orders/7890abcd-ef12-3456-7890-abcdef123456/refunds HTTP/1.1
Host: api.uat.walleydev.com
Authorization: Bearer bXlVc2VybmFtZTpmN2E1ODA4MGQzZTk0M2VmNWYyMTZlMDE...
Content-Type: application/json
{
"amount": 1248.00,
"description": "Full refund - customer cancellation",
"actionReference": "REFUND-2024-12345"
}
Key points:
- Can only refund captured amounts
- Supports full refunds, partial refunds, and refunds with fees/discounts
- Response is
202 Accepted- refund is processed asynchronously
For complete refund documentation including partial refunds, adding fees/discounts, replacement articles, and error handling, see Refund Order API documentation.
Phase 5: Settlementβ
Query settlement data to reconcile payments with your accounting system. Settlements typically occur daily and include all captured amounts minus refunds.
When to execute: Daily or weekly for financial reconciliation.
Basic API usage:
GET /reports/settlements?query=startDate:>=2024-12-01%20AND%20endDate:<=2024-12-04&page=1&perPage=10 HTTP/1.1
Host: api.uat.walleydev.com
Authorization: Bearer bXlVc2VybmFtZTpmN2E1ODA4MGQzZTk0M2VmNWYyMTZlMDE...
Response:
{
"data": [
{
"id": "1",
"startDate": "2024-12-01T00:00:00",
"endDate": "2024-12-04T00:00:00",
"storeId": 1,
"totalAmount": 100000.0,
"currency": "SEK",
"captured": 103000.0,
"refunded": -3000.0,
"reference": "2134"
}
]
}
Get settlement transactions:
GET /reports/settlements/1/transactions?page=1&perPage=10 HTTP/1.1
Host: api.uat.walleydev.com
Authorization: Bearer bXlVc2VybmFtZTpmN2E1ODA4MGQzZTk0M2VmNWYyMTZlMDE...
Response:
{
"data": [
{
"orderId": "7890abcd-ef12-3456-7890-abcdef123456",
"orderNumber": "ORDER-2024-12345",
"type": "Purchase",
"amount": 1248.00,
"currency": "SEK",
"purchaseDate": "2024-12-01",
"invoiceNumber": "11111111"
}
]
}
For complete information on settlements including query parameters, transaction details, file formats, and reconciliation best practices, see the Settlements documentation.
Best practicesβ
Security: Store API credentials securely, use HTTPS for all communication, validate webhook HMAC signatures (Approach B) or ensure HTTPS notification endpoints (Approach A), and implement IP whitelisting.
Error handling: Implement retry logic with exponential backoff, log all API requests/responses, and set up monitoring for critical failures.
Idempotency: Use idempotency keys for captures and refunds, handle duplicate notifications/webhooks by storing processed IDs, and use database transactions for state changes.
Operations: Capture within authorization validity, process webhooks asynchronously, maintain audit trails, and run daily settlement reconciliation.
Related documentationβ
- Initialize Checkout API - Initialize checkout sessions
- Notification Callback - Approach A implementation details
- Get Checkout Information API - Retrieve checkout information (Approach A)
- Webhooks Overview - Webhook concepts and setup
- Webhooks for Orders - All order lifecycle webhooks (Approach B)
- Merchant Hub Webhook Management - Configure webhooks
- Capture API - Capture payment details
- Refund API - Process refunds
- Settlements API - Financial reconciliation
- Authentication Guide - API authentication methods
- Error Codes Reference - Complete error code documentation