*/ final class UpdateCustomer implements Action { public function __construct( private readonly AppCustomerAuthService $authService, private readonly CrmService $crmService ) { } #[\Override] public function __invoke(ActionInput $input): UpdateCustomerOutput { Assert::isInstanceOf($input, UpdateCustomerInput::class); $customer = $this->authService->getCustomerAsMandatory(); try { /** @var array{firstname:string,lastname:string,birth_date:string,phone?:string,address?:string,postcode:string,city:string,opt_in?:bool} $data */ $data = [ 'firstname' => $input->firstname, 'lastname' => $input->lastname, 'birth_date' => $input->birthDate, 'postcode' => $input->postcode, 'city' => $input->city, 'opt_in' => $input->optIn, ]; if ($input->phone !== null) { $data['phone'] = $input->phone; } if ($input->address !== null) { $data['address'] = $input->address; } $result = $this->crmService->updateCustomerInfos( $customer, $data ); return new UpdateCustomerOutput($result); } catch (\Throwable $e) { report($e); return new UpdateCustomerOutput(false); } } }