Error Handling

The API uses standard HTTP status codes and Laravel's validation error format to help you handle errors gracefully.

HTTP Status Codes

Success Codes (2xx)

CodeMeaningDescription
200OKRequest succeeded
201CreatedResource created successfully
204No ContentRequest succeeded with no response body

Client Error Codes (4xx)

CodeMeaningCommon Causes
400Bad RequestInvalid parameters or malformed request
401UnauthorizedInvalid or missing Bearer token
403ForbiddenValid token but insufficient permissions or scope
404Not FoundResource doesn't exist
422Unprocessable EntityValidation errors
429Too Many RequestsRate limit exceeded

Server Error Codes (5xx)

CodeMeaningAction Required
500Internal Server ErrorRetry with exponential backoff
502Bad GatewayTemporary issue, retry
503Service UnavailableService temporarily down

Validation Error Format

When a request fails validation, the API returns a 422 response:

{
  "message": "The given data was invalid.",
  "errors": {
    "amount": ["The amount field is required."],
    "currencyCode": ["The selected currency code is invalid."],
    "clientId": ["The client id field is required."]
  }
}

Common Errors

Payment Creation Errors

ErrorCauseSolution
amount requiredMissing amount fieldInclude amount in request body
currencyCode invalidCurrency not supportedUse a supported fiat currency code
clientId invalidClient ID not foundVerify your Client ID in the dashboard
reference requiredMissing referenceInclude a unique reference string

Authentication Errors

HTTP StatusCauseSolution
401Missing or invalid tokenCheck your Bearer token
403Token lacks required scopeUse a token with the correct scope (e.g., payments.create)

Refund Errors

ErrorCauseSolution
Payment not foundInvalid payment IDVerify the payment UUID
Refund not allowedPayment has refund = falseOnly payments with refund enabled can be refunded
Refund already existsDuplicate refund requestA refund request already exists for this payment

Error Handling Examples

JavaScript

async function createPayment(data) {
  try {
    const response = await fetch('https://api.yourdomain.com/api/payment/checkout', {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${CLIENT_TOKEN}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data)
    });

    if (!response.ok) {
      const error = await response.json();

      if (response.status === 422) {
        // Validation errors
        console.error('Validation failed:', error.errors);
      } else if (response.status === 401) {
        console.error('Authentication failed');
      } else if (response.status === 429) {
        // Rate limited — wait and retry
        const delay = 2 ** retryCount * 1000;
        await new Promise((resolve) => setTimeout(resolve, delay));
        return createPayment(data);
      }

      throw new Error(error.message);
    }

    return await response.json();
  } catch (error) {
    console.error('Payment creation failed:', error);
    throw error;
  }
}

Webhook Delivery Errors

If your webhook endpoint fails to respond with a 2xx status code within 10 seconds, the webhook will be retried. Common issues:

ErrorCauseSolution
Connection timeoutEndpoint unreachableCheck server availability
Invalid signatureSecret mismatchVerify your webhook secret matches the application config
Response timeoutSlow processingReturn 200 immediately, process asynchronously

Best Practices

  1. Handle validation errors by displaying field-specific messages to users
  2. Implement retry logic with exponential backoff for 5xx errors
  3. Log request details including status codes for debugging
  4. Validate input on your side before making API calls

Next Steps