diff --git a/app/Controllers/Abha.php b/app/Controllers/Abha.php index 6e9d5e9..e59f0c3 100644 --- a/app/Controllers/Abha.php +++ b/app/Controllers/Abha.php @@ -144,6 +144,7 @@ class Abha extends BaseController 'skip_mobile' => true, 'card_base64' => $this->extractAbhaCardData($result), 'card_content_type' => $this->resolveAbhaCardContentType($result), + 'card_source' => $this->resolveAbhaCardSource($result), 'abha_number' => $abhaNum, 'name' => $name, 'photo' => $photo, @@ -307,6 +308,7 @@ class Abha extends BaseController 'ok' => 1, 'card_base64' => $this->extractAbhaCardData($result), 'card_content_type' => $this->resolveAbhaCardContentType($result), + 'card_source' => $this->resolveAbhaCardSource($result), 'abha_number' => $abhaNum, 'name' => $name, 'photo' => $photo, @@ -2001,6 +2003,7 @@ class Abha extends BaseController 'mobile_verified' => $authMethod === 'MOBILE_OTP' ? 1 : null, 'card_base64' => $cardData, 'card_content_type' => $this->resolveAbhaCardContentType($payload), + 'card_source' => $this->resolveAbhaCardSource($payload), 'candidates' => $candidates, ]); } @@ -2025,6 +2028,24 @@ class Abha extends BaseController return ''; } + private function resolveAbhaCardSource(array $payload): string + { + $data = is_array($payload['data'] ?? null) ? $payload['data'] : []; + foreach ([ + $payload['card_source'] ?? null, + $payload['source'] ?? null, + $data['card_source'] ?? null, + $data['source'] ?? null, + ] as $candidate) { + $value = strtolower(trim((string) $candidate)); + if ($value !== '') { + return str_contains($value, 'abdm') ? 'abdm' : 'generated'; + } + } + + return ''; + } + private function resolveAbhaCardContentType(array $payload): string { $data = is_array($payload['data'] ?? null) ? $payload['data'] : []; diff --git a/app/Libraries/Abdm/EAtriaBridgeConnector.php b/app/Libraries/Abdm/EAtriaBridgeConnector.php index 3fb1b9d..e5f10f0 100644 --- a/app/Libraries/Abdm/EAtriaBridgeConnector.php +++ b/app/Libraries/Abdm/EAtriaBridgeConnector.php @@ -730,6 +730,10 @@ class EAtriaBridgeConnector implements AbdmConnectorInterface ?: $this->extractOfficialCard($account) ?: $this->extractOfficialCard($profile); + if ($card !== '') { + $result['card_source'] = $this->extractCardSource($result) ?: $this->extractCardSource($data); + } + if ($card === '' && ($abhaNumber !== '' || $abhaAddress !== '')) { // Without the patient X-Token the Bridge can only return a generated // card; with it, ABDM's genuine card is fetched. @@ -748,6 +752,7 @@ class EAtriaBridgeConnector implements AbdmConnectorInterface if ($card !== '') { $result['card_base64'] = $card; $result['card_content_type'] = $this->resolveCardContentType($cardData); + $result['card_source'] = $this->extractCardSource($cardResult) ?: $this->extractCardSource($cardData); } } } @@ -755,6 +760,21 @@ class EAtriaBridgeConnector implements AbdmConnectorInterface return $result; } + /** + * @param array $source + */ + private function extractCardSource(array $source): string + { + foreach ([$source['card_source'] ?? null, $source['source'] ?? null] as $candidate) { + $value = strtolower(trim((string) $candidate)); + if ($value !== '') { + return str_contains($value, 'abdm') ? 'abdm' : 'generated'; + } + } + + return ''; + } + /** * @param array $result */ diff --git a/app/Views/partials/abha_create_modal.php b/app/Views/partials/abha_create_modal.php index 5a8c666..930e6e0 100644 --- a/app/Views/partials/abha_create_modal.php +++ b/app/Views/partials/abha_create_modal.php @@ -420,7 +420,11 @@ window.AbhaCreateModal = (function () { var card = profile.card_base64 || ''; if (card) { var cardSrc = String(card).indexOf('data:') === 0 ? card : 'data:' + (profile.card_content_type || 'image/png') + ';base64,' + card; - $('#abhaCreateCardWrap').html('Official ABHA card'); + var isOfficial = profile.card_source === 'abdm'; + var note = isOfficial + ? '' + : '
Provisional card generated by the Bridge, not the official ABDM card.
'; + $('#abhaCreateCardWrap').html('ABHA card' + note); $('#abhaCreateDownloadCard').attr('href', cardSrc).removeClass('d-none'); } else { $('#abhaCreateCardWrap').html('
Official ABHA card was not returned by the Bridge.
'); diff --git a/app/Views/partials/abha_verify_modal.php b/app/Views/partials/abha_verify_modal.php index f1f7c7e..db40c1e 100644 --- a/app/Views/partials/abha_verify_modal.php +++ b/app/Views/partials/abha_verify_modal.php @@ -224,7 +224,11 @@ window.AbhaVerifyModal = (function () { var card = profile.card_base64 || ''; if (card) { var cardSrc = String(card).indexOf('data:') === 0 ? card : 'data:' + (profile.card_content_type || 'image/png') + ';base64,' + card; - $('#abhaVerifyCardWrap').html('Official ABHA card'); + var isOfficial = profile.card_source === 'abdm'; + var note = isOfficial + ? '' + : '
Provisional card generated by the Bridge, not the official ABDM card.
'; + $('#abhaVerifyCardWrap').html('ABHA card' + note); $('#abhaVerifyDownloadCard').attr('href', cardSrc).removeClass('d-none'); } else { $('#abhaVerifyCardWrap').html('
Official ABHA card was not returned by the Bridge.
');