44
55use Fleetbase \Casts \Json ;
66use Fleetbase \Mail \VerificationMail ;
7+ use Fleetbase \Services \SmsService ;
78use Fleetbase \Support \Utils ;
89use Fleetbase \Traits \Expirable ;
910use Fleetbase \Traits \HasMetaAttributes ;
@@ -180,9 +181,10 @@ public static function generateSmsVerificationFor($subject, $for = 'phone_verifi
180181 $ message = $ messageCallback ($ verificationCode );
181182 }
182183
183- // Twilio params
184- $ twilioParams = [];
184+ // SMS service options
185+ $ smsOptions = [];
185186
187+ // Check for company-specific sender ID
186188 $ companyUuid = data_get ($ options , 'company_uuid ' ) ?? session ('company ' ) ?? data_get ($ subject , 'company_uuid ' );
187189 if ($ companyUuid ) {
188190 $ company = Company::select (['uuid ' , 'options ' ])->find ($ companyUuid );
@@ -192,13 +194,33 @@ public static function generateSmsVerificationFor($subject, $for = 'phone_verifi
192194 $ senderId = $ company ->getOption ('alpha_numeric_sender_id ' );
193195
194196 if ($ enabled && !empty ($ senderId )) {
195- $ twilioParams ['from ' ] = $ senderId ;
197+ // Alphanumeric sender IDs are Twilio-specific
198+ // Do NOT set in $smsOptions['from'] as it would be passed to all providers
199+ $ smsOptions ['twilioParams ' ]['from ' ] = $ senderId ;
196200 }
197201 }
198202 }
199203
204+ // Allow explicit provider selection
205+ $ provider = data_get ($ options , 'provider ' );
206+
207+ // Send SMS using SmsService with automatic provider routing
200208 if ($ subject ->phone ) {
201- Twilio::message ($ subject ->phone , $ message , [], $ twilioParams );
209+ try {
210+ $ smsService = new SmsService ();
211+ $ smsService ->send ($ subject ->phone , $ message , $ smsOptions , $ provider );
212+ } catch (\Throwable $ e ) {
213+ // Log error but don't fail the verification code generation
214+ \Illuminate \Support \Facades \Log::error ('Failed to send SMS verification ' , [
215+ 'phone ' => $ subject ->phone ,
216+ 'error ' => $ e ->getMessage (),
217+ ]);
218+
219+ // Optionally rethrow based on configuration
220+ if (config ('sms.throw_on_error ' , false )) {
221+ throw $ e ;
222+ }
223+ }
202224 }
203225
204226 return $ verificationCode ;
0 commit comments