Distinguish official ABHA card from generated fallback
This commit is contained in:
parent
1f4e8fa0cd
commit
167a68362a
|
|
@ -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'] : [];
|
||||
|
|
|
|||
|
|
@ -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<string, mixed> $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<string, mixed> $result
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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('<img src="' + cardSrc + '" alt="Official ABHA card">');
|
||||
var isOfficial = profile.card_source === 'abdm';
|
||||
var note = isOfficial
|
||||
? ''
|
||||
: '<div class="small text-warning mt-1"><i class="bi bi-exclamation-triangle me-1"></i>Provisional card generated by the Bridge, not the official ABDM card.</div>';
|
||||
$('#abhaCreateCardWrap').html('<img src="' + cardSrc + '" alt="ABHA card">' + note);
|
||||
$('#abhaCreateDownloadCard').attr('href', cardSrc).removeClass('d-none');
|
||||
} else {
|
||||
$('#abhaCreateCardWrap').html('<div class="text-center text-muted"><i class="bi bi-card-image fs-1 d-block mb-2"></i><span>Official ABHA card was not returned by the Bridge.</span></div>');
|
||||
|
|
|
|||
|
|
@ -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('<img src="' + cardSrc + '" alt="Official ABHA card">');
|
||||
var isOfficial = profile.card_source === 'abdm';
|
||||
var note = isOfficial
|
||||
? ''
|
||||
: '<div class="small text-warning mt-1"><i class="bi bi-exclamation-triangle me-1"></i>Provisional card generated by the Bridge, not the official ABDM card.</div>';
|
||||
$('#abhaVerifyCardWrap').html('<img src="' + cardSrc + '" alt="ABHA card">' + note);
|
||||
$('#abhaVerifyDownloadCard').attr('href', cardSrc).removeClass('d-none');
|
||||
} else {
|
||||
$('#abhaVerifyCardWrap').html('<div class="text-center text-muted"><i class="bi bi-card-image fs-1 d-block mb-2"></i>Official ABHA card was not returned by the Bridge.</div>');
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user