feat: voucher purchase flow
This commit is contained in:
1 parent
a628e96d06
commit
f3dd122678
70 files changed
+3672
-122
No files matched your search
@@ -7,6 +7,7 @@ namespace App\Service;
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Model\Address;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\BusProNet\Model\PersonalData;
|
||||
use App\Entity\User;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Security\Crypt;
|
||||
@@ -45,16 +46,52 @@ class ParticipantDataPrefiller
|
||||
* @return ParticipantDto The prepopulated participant (or unchanged if API fails)
|
||||
*/
|
||||
public function prefillApplicantFromUser(User $user, ParticipantDto $applicant): ParticipantDto
|
||||
{
|
||||
$personalData = $this->fetchPersonalData($user);
|
||||
if (null === $personalData) {
|
||||
return $applicant;
|
||||
}
|
||||
|
||||
// Create a temporary participant from personal data
|
||||
$prepopulated = ParticipantDto::fromPersonalData($personalData);
|
||||
|
||||
// Copy personal data fields to the existing applicant
|
||||
// Preserve booking-specific fields (roomId, services, etc.)
|
||||
$applicant->addressId = $prepopulated->addressId;
|
||||
$applicant->personId = $prepopulated->personId;
|
||||
$applicant->firstName = $prepopulated->firstName;
|
||||
$applicant->lastName = $prepopulated->lastName;
|
||||
$applicant->title = $prepopulated->title;
|
||||
$applicant->gender = $prepopulated->gender;
|
||||
$applicant->nationality = $prepopulated->nationality;
|
||||
$applicant->dateOfBirth = $prepopulated->dateOfBirth;
|
||||
$applicant->email = $prepopulated->email;
|
||||
$applicant->mobile = $prepopulated->mobile;
|
||||
$applicant->address = $prepopulated->address;
|
||||
$applicant->height = $prepopulated->height;
|
||||
$applicant->weight = $prepopulated->weight;
|
||||
$applicant->shoeSize = $prepopulated->shoeSize;
|
||||
$applicant->remarksRoom = $prepopulated->remarksRoom;
|
||||
$applicant->licensePlate = $prepopulated->licensePlate;
|
||||
|
||||
return $applicant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the authenticated user's personal data from the BPN API for prefilling a form.
|
||||
*
|
||||
* Never throws: a failure is logged and returns null, so a purchase flow is never interrupted
|
||||
* by a prefill.
|
||||
*/
|
||||
public function fetchPersonalData(User $user): ?PersonalData
|
||||
{
|
||||
try {
|
||||
// Decrypt user password for API authentication
|
||||
$password = $this->crypt->decrypt($user->getPassword());
|
||||
$email = $user->getEmail();
|
||||
|
||||
// Fetch personal data from API
|
||||
$result = $this->apiClient->getPersonalData($email, $password);
|
||||
|
||||
// Handle API error response
|
||||
if ($result instanceof Notification) {
|
||||
$this->logger->warning('Failed to fetch personal data for prepopulation', [
|
||||
'email' => $email,
|
||||
@@ -62,40 +99,18 @@ class ParticipantDataPrefiller
|
||||
'message' => $result->message,
|
||||
]);
|
||||
|
||||
return $applicant;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create a temporary participant from personal data
|
||||
$prepopulated = ParticipantDto::fromPersonalData($result);
|
||||
|
||||
// Copy personal data fields to the existing applicant
|
||||
// Preserve booking-specific fields (roomId, services, etc.)
|
||||
$applicant->addressId = $prepopulated->addressId;
|
||||
$applicant->personId = $prepopulated->personId;
|
||||
$applicant->firstName = $prepopulated->firstName;
|
||||
$applicant->lastName = $prepopulated->lastName;
|
||||
$applicant->title = $prepopulated->title;
|
||||
$applicant->gender = $prepopulated->gender;
|
||||
$applicant->nationality = $prepopulated->nationality;
|
||||
$applicant->dateOfBirth = $prepopulated->dateOfBirth;
|
||||
$applicant->email = $prepopulated->email;
|
||||
$applicant->mobile = $prepopulated->mobile;
|
||||
$applicant->address = $prepopulated->address;
|
||||
$applicant->height = $prepopulated->height;
|
||||
$applicant->weight = $prepopulated->weight;
|
||||
$applicant->shoeSize = $prepopulated->shoeSize;
|
||||
$applicant->remarksRoom = $prepopulated->remarksRoom;
|
||||
$applicant->licensePlate = $prepopulated->licensePlate;
|
||||
|
||||
return $applicant;
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
// Catch any unexpected exceptions (decryption failure, API errors, etc.)
|
||||
$this->logger->error('Exception during applicant prepopulation', [
|
||||
$this->logger->error('Exception during personal data prepopulation', [
|
||||
'error' => $e->getMessage(),
|
||||
'email' => $user->getEmail(),
|
||||
]);
|
||||
|
||||
return $applicant;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user