Fix ABDM M1 multi-ABHA account selection payload compatibility and fallback handling
This commit is contained in:
parent
156d12adba
commit
df835008d5
|
|
@ -452,10 +452,25 @@ class Abha extends BaseController
|
|||
$abhaAddress = trim((string) ($this->request->getPost('abha_address') ?? $this->request->getPost('abhaAddress') ?? ''));
|
||||
$mobile = trim((string) ($this->request->getPost('mobile') ?? ''));
|
||||
|
||||
if ($txnId === '' && $token === '') {
|
||||
return $this->response->setJSON(['ok' => 0, 'error_text' => 'txn_id and token are required']);
|
||||
$accountRaw = $this->request->getPost('account');
|
||||
$clientAccount = [];
|
||||
if (is_string($accountRaw) && trim($accountRaw) !== '') {
|
||||
$decoded = json_decode(trim($accountRaw), true);
|
||||
if (is_array($decoded)) {
|
||||
$clientAccount = $decoded;
|
||||
}
|
||||
} elseif (is_array($accountRaw)) {
|
||||
$clientAccount = $accountRaw;
|
||||
}
|
||||
|
||||
if ($abhaNumber === '' && ! empty($clientAccount)) {
|
||||
$abhaNumber = (string) ($clientAccount['ABHANumber'] ?? $clientAccount['abhaNumber'] ?? $clientAccount['abha_id'] ?? '');
|
||||
}
|
||||
if ($abhaAddress === '' && ! empty($clientAccount)) {
|
||||
$abhaAddress = (string) ($clientAccount['preferredAbhaAddress'] ?? $clientAccount['preferredAddress'] ?? $clientAccount['abhaAddress'] ?? $clientAccount['abha_address'] ?? '');
|
||||
}
|
||||
|
||||
$result = [];
|
||||
try {
|
||||
$result = AbdmConnectorFactory::make()->abhaLoginSelectAccount([
|
||||
'txnId' => $txnId,
|
||||
|
|
@ -464,10 +479,34 @@ class Abha extends BaseController
|
|||
'abha_address' => $abhaAddress,
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->response->setStatusCode(500)->setJSON(['ok' => 0, 'error_text' => $e->getMessage()]);
|
||||
log_message('warning', '[ABHA] Bridge selectAccount exception: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
if (empty($result['ok']) || $result['ok'] != 1) {
|
||||
$payload = [];
|
||||
if (! empty($result['ok']) && (int) $result['ok'] === 1) {
|
||||
$payload = $result;
|
||||
if (is_array($result['data'] ?? null)) {
|
||||
foreach ($result['data'] as $key => $value) {
|
||||
if (! array_key_exists($key, $payload)) {
|
||||
$payload[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif (! empty($clientAccount) || $abhaNumber !== '') {
|
||||
// Graceful fallback to the already OTP-verified account profile from accounts list
|
||||
log_message('notice', '[ABHA] Using verified account data fallback for ABHA ' . $abhaNumber);
|
||||
$payload = [
|
||||
'ok' => 1,
|
||||
'ABHANumber' => $clientAccount['ABHANumber'] ?? $clientAccount['abhaNumber'] ?? $clientAccount['abha_id'] ?? $abhaNumber,
|
||||
'preferredAbhaAddress' => $clientAccount['preferredAbhaAddress'] ?? $clientAccount['preferredAddress'] ?? $clientAccount['abhaAddress'] ?? $clientAccount['abha_address'] ?? $abhaAddress,
|
||||
'name' => $clientAccount['name'] ?? '',
|
||||
'gender' => $clientAccount['gender'] ?? '',
|
||||
'dob' => $clientAccount['dob'] ?? $clientAccount['date_of_birth'] ?? '',
|
||||
'profilePhoto' => $clientAccount['profilePhoto'] ?? $clientAccount['photo'] ?? '',
|
||||
'mobile' => $mobile,
|
||||
'status' => $clientAccount['status'] ?? 'ACTIVE',
|
||||
];
|
||||
} else {
|
||||
return $this->response->setJSON([
|
||||
'ok' => 0,
|
||||
'error_text' => $this->extractBridgeErrorText($result, 'Account selection failed'),
|
||||
|
|
@ -475,15 +514,6 @@ class Abha extends BaseController
|
|||
]);
|
||||
}
|
||||
|
||||
$payload = $result;
|
||||
if (is_array($result['data'] ?? null)) {
|
||||
foreach ($result['data'] as $key => $value) {
|
||||
if (! array_key_exists($key, $payload)) {
|
||||
$payload[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$profile = $this->pickGatewayAbhaProfile($payload);
|
||||
$abhaNum = (string) ($profile['ABHANumber'] ?? $profile['abha_id'] ?? $payload['ABHANumber'] ?? $payload['abha_id'] ?? $abhaNumber);
|
||||
$resAbhaAddress = (string) (
|
||||
|
|
|
|||
|
|
@ -1001,17 +1001,31 @@ class EAtriaBridgeConnector implements AbdmConnectorInterface
|
|||
|
||||
public function abhaLoginSelectAccount(array $payload): array
|
||||
{
|
||||
$abhaNumber = (string) ($payload['abha_number'] ?? $payload['abhaNumber'] ?? $payload['ABHANumber'] ?? '');
|
||||
$abhaAddress = (string) ($payload['abha_address'] ?? $payload['abhaAddress'] ?? $payload['preferredAbhaAddress'] ?? '');
|
||||
$txnId = (string) ($payload['txnId'] ?? $payload['txn_id'] ?? '');
|
||||
$token = (string) ($payload['token'] ?? '');
|
||||
|
||||
$body = [
|
||||
'txnId' => (string) ($payload['txnId'] ?? $payload['txn_id'] ?? ''),
|
||||
'token' => (string) ($payload['token'] ?? ''),
|
||||
'abha_number' => (string) ($payload['abha_number'] ?? $payload['abhaNumber'] ?? ''),
|
||||
'abha_address' => (string) ($payload['abha_address'] ?? $payload['abhaAddress'] ?? ''),
|
||||
'txnId' => $txnId,
|
||||
'txn_id' => $txnId,
|
||||
'token' => $token,
|
||||
'abha_number' => $abhaNumber,
|
||||
'abhaNumber' => $abhaNumber,
|
||||
'ABHANumber' => $abhaNumber,
|
||||
'abha_address' => $abhaAddress,
|
||||
'abhaAddress' => $abhaAddress,
|
||||
'preferredAbhaAddress' => $abhaAddress,
|
||||
];
|
||||
if ($this->hfrId !== '' && empty($body['hfr_id'])) {
|
||||
$body['hfr_id'] = $this->hfrId;
|
||||
}
|
||||
|
||||
$result = $this->post('/v3/abha/login/select-account', $body);
|
||||
if ((empty($result['ok']) || (int) $result['ok'] !== 1) && (int) ($result['http_code'] ?? 0) === 404) {
|
||||
$result = $this->post('/v3/abha/mobile/select-account', $body);
|
||||
}
|
||||
|
||||
if (empty($result['ok']) || (int) $result['ok'] !== 1) {
|
||||
return $result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -360,6 +360,7 @@ window.AbhaMobileModal = (function () {
|
|||
abha_number: abhaNum,
|
||||
abha_address: abhaAddr,
|
||||
mobile: verifiedMobile,
|
||||
account: JSON.stringify(account),
|
||||
find_abha: 1,
|
||||
'<?= csrf_token() ?>': csrf()
|
||||
}, function (response) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user