Skip to main content

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:
  1. Parse the payment error to determine if the payload needs fixing.
  2. If fixable (400 with VALIDATION_ERROR or INVALID_REQUEST): correct the payload and retry createPayment using the same checkout_session.
  3. If not fixable (403, method not available): create a new checkout session with different parameters.
  4. Checkout sessions expire after a configurable period. Do not reuse stale sessions.

Payment Succeeded, Webhook Not Received

Scenario: Payment shows SUCCEEDED but webhook was not delivered. Recovery:
  1. Poll getPayment to confirm status
  2. If SUCCEEDED, proceed with order fulfillment regardless of webhook
  3. 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:
  1. Check if the capture actually went through (GET the payment)
  2. If still AUTHORIZED: retry the capture
  3. If authorization has expired (typically 7 days): cannot capture; must create a new payment
  4. 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. Use webhook_id for deduplication.

Out-of-Order Webhooks

Webhooks may arrive out of order. Always check the timestamp and current payment status.

Failed Webhook Delivery

If your webhook endpoint is down, Yuno retries with exponential backoff. Implement a reconciliation job that periodically polls listPayments to catch any missed webhooks.

Escalation Checklist

When automated recovery fails, provide this context to Yuno support: