Repository navigation
Error Handling
Rauf Abbas edited this page Oct 22, 2026
·
2 revisions
All response objects have error checking methods:
$response = $client->payment()
->amount(100)
->orderId('ORDER-123')
->send();
if ($response->isError()) {
echo 'Error: ' . $response->getMessage();
echo 'Trace ID: ' . $response->getTraceId();
}try {
$response = $client->payment()
->amount(100)
->orderId('ORDER-123')
->send();
if ($response->isSuccess()) {
// Handle success
header('Location: ' . $response->getRedirectUrl());
} else {
// Handle API error
logError($response->getMessage(), $response->getTraceId());
showUserError('Payment initialization failed');
}
} catch (\Exception $e) {
// Handle exception
logError($e->getMessage());
showUserError('An unexpected error occurred');
}When Epoint answers with an HTTP error, EpointException carries the status code and the decoded JSON body:
use Epoint\Exceptions\EpointException;
try {
$client->tokenPayment()->amount(10)->orderId('ORDER-123-1')->create();
} catch (EpointException $e) {
$httpCode = $e->getHttpCode(); // null for network / validation errors
$body = $e->getResponseData(); // null when the body was not JSON
$message = $body['message'] ?? $e->getMessage();
}applePay()->pay() and googlePay()->pay() return declined charges as unsuccessful responses instead of throwing.
// Invalid credentials
if ($response->getMessage() === 'Invalid credentials') {
// Check your public_key and private_key
}// Amount too small
if ($response->getMessage() === 'Amount must be greater than 0') {
// Check minimum amount requirement
}
// Invalid order ID
if ($response->getMessage() === 'Order ID already exists') {
// Use unique order IDs
}// Card declined
if ($callbackData['status'] === 'error') {
$reason = $callbackData['message'];
// Common reasons:
// - Insufficient funds
// - Card expired
// - Card blocked
// - Invalid card details
}$response->toArray();
// [
// 'status' => 'error',
// 'message' => 'Error description',
// 'code' => 'ERROR_CODE',
// 'trace_id' => 'a1b2c3d4...',
// ]Always log errors with trace IDs for troubleshooting:
function logPaymentError($response, $context = [])
{
error_log(sprintf(
'[EPOINT ERROR] %s | Trace ID: %s | Context: %s',
$response->getMessage(),
$response->getTraceId(),
json_encode($context)
));
}
// Usage
if ($response->isError()) {
logPaymentError($response, [
'order_id' => 'ORDER-123',
'amount' => 100.00,
]);
}When reporting issues to Epoint support, always include:
-
Trace ID:
$response->getTraceId() -
Error Message:
$response->getMessage() - Order ID: Your order identifier
- Transaction ID: If available
- Timestamp: When the error occurred
$supportInfo = [
'trace_id' => $response->getTraceId(),
'message' => $response->getMessage(),
'order_id' => 'ORDER-123',
'transaction' => $response->getTransaction(),
'timestamp' => date('Y-m-d H:i:s'),
];
// Include this information when contacting supporttry {
$callbackData = $client->verifyCallback($data, $signature);
} catch (\Epoint\Exceptions\SignatureVerificationException $e) {
// Invalid signature - possible fraud
error_log('Invalid callback signature: ' . $e->getMessage());
http_response_code(400);
exit;
}$data = $_POST['data'] ?? null;
$signature = $_POST['signature'] ?? null;
if (!$data || !$signature) {
error_log('Missing callback data');
http_response_code(400);
exit('Missing data');
}// Log all API responses
$response = $client->payment()->amount(100)->orderId('ORDER-123')->send();
error_log('Payment Response: ' . print_r($response->toArray(), true));// Test API connectivity
$heartbeat = $client->heartbeat();
if ($heartbeat['status'] === 'ok') {
echo 'API connection OK';
} else {
echo 'API connection failed';
}// Validate before sending
if ($amount < 0.01) {
throw new \Exception('Amount too small');
}
if (empty($orderId)) {
throw new \Exception('Order ID required');
}// Dump full response
$response = $client->payment()->amount(100)->send();
error_log(print_r($response->toArray(), true));<?php
class PaymentService
{
private $client;
private $logger;
public function createPayment($amount, $orderId)
{
try {
$response = $this->client->payment()
->amount($amount)
->orderId($orderId)
->send();
if ($response->isError()) {
$this->logError($response, 'payment_creation');
throw new PaymentException(
'Payment initialization failed',
$response->getTraceId()
);
}
return $response->getRedirectUrl();
} catch (\Exception $e) {
$this->logger->error('Payment exception', [
'message' => $e->getMessage(),
'order_id' => $orderId,
'amount' => $amount,
]);
throw $e;
}
}
private function logError($response, $context)
{
$this->logger->error('Epoint API Error', [
'message' => $response->getMessage(),
'trace_id' => $response->getTraceId(),
'status' => $response->getStatus(),
'context' => $context,
]);
}
}Solution: Verify you're using the correct private key. Don't modify callback POST data.
Solution: Use unique order IDs for each payment. Add timestamp or random string.
Solution: Ensure amount is a positive number with max 2 decimal places.
Solution: Verify the card_id exists and belongs to your merchant account.
Solution:
- Check callback URL is configured in Epoint panel
- Ensure URL is publicly accessible
- Verify firewall allows incoming requests
- Return HTTP 200 OK from callback