Overview
AI agents must handle errors gracefully across multi-step payment workflows. This guide provides decision trees, retry patterns, and recovery strategies for every failure mode an agent may encounter.Payment APIs involve real money. Incorrect error handling can lead to duplicate charges, missed refunds, or stuck transactions. Follow these patterns precisely.
Error Decision Tree
Use this decision tree to determine the correct action for any HTTP error response.Retry vs. Fallback vs. Escalate
Exponential Backoff Pattern
All retryable errors should use exponential backoff with jitter to avoid thundering herd problems.Timeout Handling with Polling Fallback
When a payment request times out, the payment may have been created successfully on the server. Always check before retrying.Implementation
Partial Failure Recovery
Multi-step workflows can fail partway through. Each step requires specific recovery logic.Session Created, Payment Failed
Scenario:createCheckoutSession succeeded but createPayment returned an error.
Recovery:
- Parse the payment error to determine if the payload needs fixing.
- If fixable (400 with
VALIDATION_ERRORorINVALID_REQUEST): correct the payload and retrycreatePaymentusing the samecheckout_session. - If not fixable (403, method not available): create a new checkout session with different parameters.
- Checkout sessions expire after a configurable period. Do not reuse stale sessions.
Payment Succeeded, Webhook Not Received
Scenario: Payment showsSUCCEEDED but webhook was not delivered.
Recovery:
- Poll
getPaymentto confirm status - If SUCCEEDED, proceed with order fulfillment regardless of webhook
- Implement idempotent webhook processing so late-arriving webhooks do not cause duplicate actions
Capture Failed After Authorization
Scenario: Payment was authorized but capture request failed. Recovery:- Check if the capture actually went through (GET the payment)
- If still AUTHORIZED: retry the capture
- If authorization has expired (typically 7 days): cannot capture; must create a new payment
- If already SUCCEEDED: capture went through despite the error response
Idempotent Retry Patterns
For multi-step flows, use idempotency keys and deduplication to prevent duplicate operations.Deduplication Strategy
Example: Safe Refund
Circuit Breaker Pattern
When a provider experiences sustained outages, implement a circuit breaker to avoid wasting API calls and degrading user experience.Implementation
Error code mapping table
Mapping of verified error codes to agent actions. For the complete catalog see Error codes.Webhook Error Handling
Agents processing webhooks should handle these failure scenarios:Duplicate Webhooks
Yuno may deliver the same webhook multiple times. Usewebhook_id for deduplication.
Out-of-Order Webhooks
Webhooks may arrive out of order. Always check thetimestamp and current payment status.
Failed Webhook Delivery
If your webhook endpoint is down, Yuno retries with exponential backoff. Implement a reconciliation job that periodically pollslistPayments to catch any missed webhooks.