Detect ABDM Bridge test-mode address responses
This commit is contained in:
parent
d0a0bf984e
commit
22e960a834
|
|
@ -391,6 +391,10 @@ class Abha extends BaseController
|
||||||
'supported' => true,
|
'supported' => true,
|
||||||
'txn_id' => $txnId,
|
'txn_id' => $txnId,
|
||||||
'suggestions' => array_values((array) ($result['suggestions'] ?? [])),
|
'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'] : [];
|
$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([
|
return $this->response->setJSON([
|
||||||
'ok' => 1,
|
'ok' => 1,
|
||||||
'abha_address' => (string) ($result['abha_address'] ?? $data['abhaAddress'] ?? $data['abha_address'] ?? $abhaAddress),
|
'abha_address' => (string) ($result['abha_address'] ?? $data['abhaAddress'] ?? $data['abha_address'] ?? $abhaAddress),
|
||||||
|
|
|
||||||
|
|
@ -850,10 +850,28 @@ class EAtriaBridgeConnector implements AbdmConnectorInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
$result['suggestions'] = $this->normalizeAbhaAddressSuggestions($result);
|
$result['suggestions'] = $this->normalizeAbhaAddressSuggestions($result);
|
||||||
|
$result['bridge_mock'] = $result['suggestions'] === [] && $this->isMockBridgeResponse($result);
|
||||||
|
|
||||||
return $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
|
public function abhaSetAddress(array $payload): array
|
||||||
{
|
{
|
||||||
$txnId = (string) ($payload['txn_id'] ?? $payload['txnId'] ?? '');
|
$txnId = (string) ($payload['txn_id'] ?? $payload['txnId'] ?? '');
|
||||||
|
|
@ -877,6 +895,7 @@ class EAtriaBridgeConnector implements AbdmConnectorInterface
|
||||||
if ($preferred !== '') {
|
if ($preferred !== '') {
|
||||||
$result['abha_address'] = $preferred;
|
$result['abha_address'] = $preferred;
|
||||||
}
|
}
|
||||||
|
$result['bridge_mock'] = $preferred === '' && $this->isMockBridgeResponse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user