Detect ABDM Bridge test-mode address responses

This commit is contained in:
DevSoftTech Server 2026-08-13 18:13:12 +05:30
parent d0a0bf984e
commit 22e960a834
2 changed files with 31 additions and 0 deletions

View File

@ -391,6 +391,10 @@ class Abha extends BaseController
'supported' => true,
'txn_id' => $txnId,
'suggestions' => array_values((array) ($result['suggestions'] ?? [])),
'bridge_mock' => ! empty($result['bridge_mock']),
'error_text' => ! empty($result['bridge_mock'])
? 'The ABDM Bridge is running in test mode and returned a mock response, so no ABHA address suggestions were provided.'
: '',
]);
}
@ -433,6 +437,14 @@ class Abha extends BaseController
$data = is_array($result['data'] ?? null) ? $result['data'] : [];
if (! empty($result['bridge_mock'])) {
return $this->response->setJSON([
'ok' => 0,
'error_text' => 'The ABDM Bridge is running in test mode and did not apply the ABHA address. Ask the Bridge team to enable live mode for /v3/abha/set-address.',
'request_id' => (string) ($result['request_id'] ?? ''),
]);
}
return $this->response->setJSON([
'ok' => 1,
'abha_address' => (string) ($result['abha_address'] ?? $data['abhaAddress'] ?? $data['abha_address'] ?? $abhaAddress),

View File

@ -850,10 +850,28 @@ class EAtriaBridgeConnector implements AbdmConnectorInterface
}
$result['suggestions'] = $this->normalizeAbhaAddressSuggestions($result);
$result['bridge_mock'] = $result['suggestions'] === [] && $this->isMockBridgeResponse($result);
return $result;
}
/**
* The Bridge answers stubbed endpoints with {"ok":1,"mode":"test"} and no real
* payload; treating that as success would report false results to the operator.
*
* @param array<string, mixed> $result
*/
private function isMockBridgeResponse(array $result): bool
{
if (strtolower(trim((string) ($result['mode'] ?? ''))) === 'test') {
return true;
}
$data = is_array($result['data'] ?? null) ? $result['data'] : [];
return stripos((string) ($data['message'] ?? ''), 'mock') !== false;
}
public function abhaSetAddress(array $payload): array
{
$txnId = (string) ($payload['txn_id'] ?? $payload['txnId'] ?? '');
@ -877,6 +895,7 @@ class EAtriaBridgeConnector implements AbdmConnectorInterface
if ($preferred !== '') {
$result['abha_address'] = $preferred;
}
$result['bridge_mock'] = $preferred === '' && $this->isMockBridgeResponse($result);
}
return $result;