Inventory Validation and Reservation Strategies
When integrating Walley Checkout, preventing overselling while maintaining a good customer experience is critical. This guide explains different strategies for validating stock availability and reserving inventory during the checkout process.
Overview of Approachesβ
There are three main approaches to handle inventory during checkout:
| Approach | When to Validate | Best For |
|---|---|---|
| No Validation | After payment | Digital products, low-traffic stores |
| Pre-Payment Validation | Before payment | Standard e-commerce, stock checking |
| Advanced Validation | Before payment, Failed payment | Complex rules, Inventory reservation, Gift cards |
Comparison Matrixβ
Choose the right approach based on your requirements:
| Criteria | No Validation | Pre-Payment Validation | Advanced Callbacks |
|---|---|---|---|
| Overselling Prevention | β None | β Good | β Excellent |
| Checkout Speed | β‘ Fastest | π Slower (+10s max) | π Slower (+10s max) |
| Implementation Complexity | β Simple | β Simple | β οΈ Medium |
| Conversion Rate Impact | β None | β οΈ Potential negative | β οΈ Potential negative |
| Custom Validation | β No | β οΈ Limited | β Full support |
| Rollback Support | N/A | β No | β Yes (PaymentFailed) |
| HTTP Method | N/A | GET | POST with body |
Approach 1: No Validation (Notification Only)β
Overviewβ
The simplest approach relies solely on the notification callback to process orders after payment completion. No pre-payment validation is performed.
Configurationβ
{
"storeId": 123,
"countryCode": "SE",
"notificationUri": "https://api.myshop.com/notifications/{checkout.id}",
"cart": {
"items": [...]
}
}
When to Useβ
- Digital products - No physical inventory to manage
- Made-to-order products - Items created after purchase
- Low-traffic stores - Minimal risk of simultaneous purchases
- Services - No stock limitations
Pros and Consβ
β Advantages:
- Fastest checkout experience
- Simplest implementation
- No timeout concerns
- Highest conversion rate
β Disadvantages:
- Risk of overselling
- Customer disappointment if items unavailable
- Manual handling of out-of-stock situations
How It Worksβ
- Customer completes payment through Walley Checkout
- Walley sends GET request to your
notificationUri - Your backend receives the notification
- Check if order was already processed (idempotency)
- Retrieve checkout information using the checkout ID
- If status is
PurchaseCompleted:- Deduct inventory from stock
- Create the order in your system
- Send confirmation email to customer
- Respond with
200 OKto confirm receipt
Approach 2: Pre-Payment Validationβ
Overviewβ
Validate stock availability just before payment is processed using the validationUri. This provides a final check to ensure items are in stock before the customer's payment is authorized.
Architectureβ
Customer completes checkout form
β
Customer clicks "Complete Purchase"
β
Walley calls validationUri (GET)
β
Your backend checks stock availability
β
Response: Success or Error
β
If success β Process payment
β
If payment succeeds β Notification callback
Configurationβ
{
"storeId": 123,
"countryCode": "SE",
"notificationUri": "https://api.myshop.com/notifications/{checkout.id}",
"validationUri": "https://api.myshop.com/validate/{checkout.id}",
"cart": {
"items": [...]
}
}
When to Useβ
- Standard e-commerce - Typical online stores with inventory management
- Medium traffic - Moderate number of concurrent users
- Simple validation - Primary need is stock availability checking
- Quick implementation - Simpler than reservation systems
Pros and Consβ
β Advantages:
- Prevents overselling at point of payment
- No reservation state to manage
- Simple to implement
- Works with existing inventory systems
β Disadvantages:
- Adds latency to checkout (up to 10 seconds)
- No rollback mechanism if payment fails
- Customer may lose item during checkout
- Multiple validation calls possible
How It Worksβ
- Customer completes checkout form and clicks "Complete Purchase"
- Walley calls your
validationUriwith a GET request - Your validation endpoint:
- Retrieves checkout information using the checkout ID
- Checks stock availability for all items
- Returns success (200 OK) or error (400/500) response
- If validation succeeds:
- Payment is processed
- Order can optionally be created in pending state
- If validation fails:
- Customer sees error message
- Purchase is not completed
- After successful payment:
- Walley sends notification to
notificationUri - Your backend finalizes the order
- Inventory is deducted
- Confirmation email is sent
- Walley sends notification to
Key Considerationsβ
- 10-Second Timeout: Validation must complete within 10 seconds
- Multiple Calls: Validation may be called multiple times if customer retries
- Idempotency: Handle duplicate validation requests gracefully
- Error Messages: Provide clear feedback about unavailable items
Even if validation succeeds, the purchase may still fail due to credit checks or payment issues. Always treat the order as pending until receiving the notificationUri callback with PurchaseCompleted status.
Approach 3: Advanced Validation with Callbacksβ
Overviewβ
Use the callback object with ValidateOrder and PaymentFailed callback types for advanced validation scenarios with built-in rollback support.
Configurationβ
{
"storeId": 123,
"countryCode": "SE",
"notificationUri": "https://api.myshop.com/notifications/{checkout.id}",
"callback": {
"callbackUri": "https://api.myshop.com/callbacks/{checkout.id}",
"callbackTypes": ["ValidateOrder", "PaymentFailed"]
},
"cart": {
"items": [...]
}
}
When to Useβ
- Complex validation rules - Multiple checks beyond stock (customer eligibility, regional restrictions)
- Rollback requirements - Need to handle payment failures gracefully
- Multiple validation steps - Customer verification, business rules, inventory reservation, gift cards
Pros and Consβ
β Advantages:
- Prevents overselling
- Supports complex business logic
- Built-in rollback via PaymentFailed callback
- Structured request/response format
β Disadvantages:
- Adds latency to checkout (up to 10 seconds)
- More complex than validationUri
- Requires fast backend response
- May lower conversion rate if slow
Callback Flowβ
Customer completes checkout form
β
Customer clicks "Complete Purchase"
β
Walley calls ValidateOrder callback (POST)
β
Your backend: Check stock, validate rules
β
Response: Success or Error
β
If success β Process payment
β
If payment fails β PaymentFailed callback
β
If payment succeeds β Notification callback
How It Worksβ
ValidateOrder Callback:
- Walley sends POST request to your
callbackUriwith typeValidateOrder - Request body includes
checkoutIdandpublicTokenfor verification - Your backend:
- Retrieves checkout information
- Checks stock availability
- Validates customer eligibility (if needed)
- Validates business rules (regional restrictions, etc.)
- Optionally reserves inventory
- Creates pending order
- Response options:
- Success (200 OK): Return
{ orderReference: "ORDER-123" }(optional) - Error (400): Return
{ title: "...", message: "...", clientPayload: {...} } - Timeout/Error (500): Customer sees generic error
- Success (200 OK): Return
PaymentFailed Callback:
- Triggered when payment fails after successful validation
- Your backend:
- Finds the pending order by checkoutId
- Cancels the order
- Releases any inventory reservations
- Cleans up any other resources
- Always respond with 200 OK (failures here don't affect customer)
Notification Callback:
- Triggered when payment succeeds
- Your backend:
- Updates order from pending to completed
- Confirms inventory reservation (converts to sale)
- Sends confirmation email
- Triggers fulfillment process
Key Considerationsβ
- 10-Second Timeout: Validation must complete within 10 seconds
- Idempotency: Implement caching to handle duplicate calls
- Error Handling: Provide clear error messages to customers
- Rollback: Always handle PaymentFailed to release reservations
Decision Guideβ
Use this flowchart to choose the right approach:
Do you sell physical products with limited stock?
β
ββ NO (digital/services) β Use No Validation
β
ββ YES β Need to prevent overselling?
β
ββ Simple stock checking only?
β ββ YES β Use Pre-Payment Validation (validationUri)
β
ββ Need rollback if payment fails?
β ββ YES β Use Advanced Callbacks (ValidateOrder + PaymentFailed)
β
ββ Complex validation rules?
(customer eligibility, regional restrictions, gift cards, release inventory reservations)
ββ YES β Use Advanced Callbacks
Migration from validationUri to Callbacksβ
If you're currently using validationUri and want to add rollback support, migrate to the callback object:
Before (validationUri):
{
"notificationUri": "https://api.myshop.com/notifications/{checkout.id}",
"validationUri": "https://api.myshop.com/validate/{checkout.id}"
}
After (callback object):
{
"notificationUri": "https://api.myshop.com/notifications/{checkout.id}",
"callback": {
"callbackUri": "https://api.myshop.com/callbacks/{checkout.id}",
"callbackTypes": ["ValidateOrder", "PaymentFailed"]
}
}
Key Differences:
- Request Method: GET (validationUri) β POST (callback)
- Request Body: None β JSON with type and checkout details
- Rollback: Not available β PaymentFailed callback
- Authentication: None β checkoutId and publicToken provided
You cannot use both validationUri and callback.ValidateOrder simultaneously. Choose one validation method.
Best Practicesβ
All Approachesβ
- Implement Idempotency: Always check if a notification/callback was already processed
- Comprehensive Logging: Log all inventory operations for debugging and auditing
- Monitor Performance: Track validation times and reservation expiry rates
- Error Handling: Gracefully handle timeouts, connection failures, and partial stock
Pre-Payment Validation (validationUri)β
- Response Time: Must complete within 10 seconds
- Idempotency: Handle duplicate validation requests (customer may retry)
- Error Messages: Provide clear, specific reasons for validation failures
- Pending Orders: Optionally create pending orders during validation
Advanced Validation (Callbacks)β
- Response Time: Must complete within 10 seconds (set internal timeout at 8-9 seconds)
- Optimization: Use caching, batch queries, and parallel execution
- Clear Errors: Provide specific, actionable error messages to customers
- Always Rollback: Handle PaymentFailed callback to release resources
Testing Considerationsβ
Key Test Scenariosβ
- Happy Path: Successful purchase with stock available
- Out of Stock: Item becomes unavailable during checkout
- Reservation Expiry: User abandons checkout, reservation is released
- Payment Failure: Payment declined, rollback occurs correctly
- Concurrent Purchases: Multiple users buying last available item
- Timeout Handling: Validation takes too long, proper error shown
What to Verifyβ
- Inventory is correctly reserved/deducted
- No overselling occurs under concurrent load
- Expired reservations are released
- PaymentFailed callback releases resources
- Idempotency works for duplicate notifications
- Error messages are clear and helpful
Troubleshootingβ
| Issue | Possible Cause | Solution |
|---|---|---|
| Overselling occurs | Race conditions | Implement database locks/transactions |
| "Reservation expired" | Checkout takes too long | Increase expiry duration (30 min) |
| "Validation timeout" | Slow backend | Optimize queries, add caching |
| Inventory remains locked | Cleanup job not running | Verify background job is active |
| Duplicate orders | Missing idempotency | Always check if already processed |
Related Documentationβ
- Initialize Checkout - Setup callbacks and configuration
- Validate Order Callback - Detailed callback documentation
- Notification Callback - Purchase completion handling
- Gift Cards Use Case - Another callback example
Summaryβ
Choose your inventory validation strategy based on:
- Product type - Digital β No Validation
- Validation needs - Simple stock check β Pre-Payment Validation
- Rollback requirements - Need cleanup β Advanced Callbacks
- Business rules - Complex logic β Advanced Callbacks
Remember that the notification callback is always required and is the only reliable confirmation of purchase completion, regardless of which validation approach you choose.
For questions or assistance, contact Walley Merchant Services at help@walley.se.