diff --git a/app/Controllers/Abha.php b/app/Controllers/Abha.php
index 22ccd0c..e0ab82d 100644
--- a/app/Controllers/Abha.php
+++ b/app/Controllers/Abha.php
@@ -111,7 +111,10 @@ class Abha extends BaseController
$abhaNum = (string) ($profile['ABHANumber'] ?? $profile['abha_id'] ?? $payload['ABHANumber'] ?? $payload['abha_id'] ?? '');
$aadhaarVerifiedAbha = preg_replace('/\D/', '', $abhaNum);
- if ($newTxnId && strlen($aadhaarVerifiedAbha) === 14) {
+ // ABDM v3 creates/returns the ABHA inside Aadhaar verify-otp when an alternate
+ // mobile is supplied, so no further mobile OTP step may run for this person.
+ $abhaCreated = strlen($aadhaarVerifiedAbha) === 14;
+ if ($newTxnId && $abhaCreated) {
session()->set('abha_enrol_identity_' . $newTxnId, $aadhaarVerifiedAbha);
}
$abhaAddress = (string) (
@@ -125,9 +128,14 @@ class Abha extends BaseController
);
$name = $this->extractAbhaProfileName($profile, $payload);
$photo = $this->extractAbhaProfilePhoto($profile, $payload);
- // A different communication number is not verified until Step 3 succeeds.
- // Never persist the operator-entered number merely because Aadhaar OTP passed.
$mobile = (string) ($profile['mobile'] ?? $payload['mobile'] ?? $payload['mobileNumber'] ?? '');
+ $mobileSource = $mobile === '' ? '' : 'abdm';
+ $enrolMobile = preg_replace('/\D/', '', $requestMobile);
+ // ABDM accepted this number while creating the ABHA but does not always echo it back.
+ if ($mobile === '' && $abhaCreated && strlen($enrolMobile) === 10) {
+ $mobile = $enrolMobile;
+ $mobileSource = 'enrolment';
+ }
$profileGender = (string) ($profile['gender'] ?? $payload['gender'] ?? '');
$profileDob = (string) ($profile['dob'] ?? $profile['date_of_birth'] ?? $payload['dob'] ?? $payload['date_of_birth'] ?? '');
$verifiedStatus = (string) (($payload['gateway_abha_profile']['status'] ?? '') ?: ($profile['verifiedStatus'] ?? '') ?: ($profile['status'] ?? '') ?: ($payload['verifiedStatus'] ?? '') ?: ($payload['status'] ?? ''));
@@ -161,10 +169,6 @@ class Abha extends BaseController
$patientInfo = $this->tryAutoLinkByDirectMatch($abhaNum, $name, $mobile, $profileGender, $profileDob, $abhaMeta);
- // ABDM v3 creates/returns the ABHA inside Aadhaar verify-otp when an alternate
- // mobile is supplied, so no further mobile OTP step may run for this person.
- $abhaCreated = strlen($aadhaarVerifiedAbha) === 14;
-
$responseBase = [
'ok' => 1,
'txn_id' => $newTxnId,
@@ -178,6 +182,7 @@ class Abha extends BaseController
'name' => $name,
'photo' => $photo,
'mobile' => $mobile,
+ 'mobile_source' => $mobileSource,
'gender' => $profileGender,
'dob' => $profileDob,
'abha_address' => $abhaAddress,
diff --git a/app/Views/partials/abha_create_modal.php b/app/Views/partials/abha_create_modal.php
index f58550e..3dca275 100644
--- a/app/Views/partials/abha_create_modal.php
+++ b/app/Views/partials/abha_create_modal.php
@@ -405,12 +405,16 @@ window.AbhaCreateModal = (function () {
return;
}
var maskedComm = escapeHtml(maskMobile(communicationMobile));
- if (digits(response.mobile).slice(-10) === communicationMobile) {
- alertBox('success', created + '
Alternate mobile ' + maskedComm + ' is attached to this ABHA as the communication number. No separate mobile OTP is needed.');
+ if (response.mobile_source === 'abdm' && digits(response.mobile).slice(-10) === communicationMobile) {
+ alertBox('success', created + '
ABDM confirmed mobile ' + maskedComm + ' as the ABHA communication number. It will be saved on the patient record. No separate mobile OTP is needed.');
return;
}
- alertBox('warning', created + '
The alternate mobile ' + maskedComm + ' was sent with the Aadhaar verification, but ABDM did not confirm it in the response, so treat it as not yet attached.'
- + '
HMS deliberately did not send a second mobile OTP: that check returns whichever ABHA already owns this number (for example a parent\'s ABHA) and would overwrite this record. Attach or change the number from the ABHA app/portal instead.');
+ if (response.mobile_source === 'enrolment') {
+ alertBox('success', created + '
Alternate mobile ' + maskedComm + ' was submitted with the Aadhaar verification that created this ABHA and will be saved on the patient record. ABDM did not echo it back in the response, so confirm it in the ABHA app if the beneficiary reports missing notifications.'
+ + '
HMS does not send a second mobile OTP: that check returns whichever ABHA already owns this number (for example a parent\'s ABHA) and would overwrite this record.');
+ return;
+ }
+ alertBox('warning', created + '
The alternate mobile ' + maskedComm + ' could not be attached, and ABDM returned ' + (escapeHtml(maskMobile(response.mobile)) || 'no number') + ' instead. Attach or change the number from the ABHA app/portal.');
}
function requestMobileOtp() {
@@ -459,8 +463,8 @@ window.AbhaCreateModal = (function () {
$('#abhaCreateProfileDob').text(profile.dob || '-');
$('#abhaCreateProfileGender').text(genderText(profile.gender));
$('#abhaCreateProfileMobile').text(profile.mobile
- ? maskMobile(profile.mobile)
- : (communicationMobile ? maskMobile(communicationMobile) + ' (sent at enrolment, unconfirmed)' : '-'));
+ ? maskMobile(profile.mobile) + (profile.mobile_source === 'enrolment' ? ' (submitted at enrolment)' : '')
+ : '-');
$('#abhaCreateProfileFullAddress').text([profile.address, profile.district, profile.state, profile.zip].filter(Boolean).join(', ') || '-');
$('#abhaCreateStatusText').text(profile.abha_number ? 'ABHA Ready' : 'ABHA Verified');