33namespace NotificationChannels \Textlocal ;
44
55use Illuminate \Notifications \Notification ;
6+ use NotificationChannels \Textlocal \Contracts \INotificationUsesTextlocalClientConfig ;
7+ use NotificationChannels \Textlocal \Contracts \IUsesTextlocalClientConfig ;
68use NotificationChannels \Textlocal \Exceptions \CouldNotSendNotification ;
79
810/**
@@ -66,8 +68,10 @@ public function send($notifiable, Notification $notification)
6668 $ this ->sender = $ notification ->getSenderId ();
6769 }
6870
71+ $ client = $ this ->getClient ($ notifiable , $ notification );
72+
6973 try {
70- $ response = $ this -> client
74+ $ response = $ client
7175 ->setUnicodeMode ($ unicode )
7276 ->sendSms ($ numbers , $ message , $ this ->sender );
7377
@@ -76,4 +80,25 @@ public function send($notifiable, Notification $notification)
7680 throw CouldNotSendNotification::serviceRespondedWithAnError ($ exception , $ message );
7781 }
7882 }
83+
84+ public function getClient ($ notifiable , Notification $ notification )
85+ {
86+ $ client = $ this ->client ;
87+
88+ if ($ notifiable instanceof IUsesTextlocalClientConfig) {
89+
90+ [$ username , $ hash , $ apiKey , $ country ] = $ notification ->getTextlocalClientConfig ($ notification );
91+
92+ $ client = new Textlocal ($ username , $ hash , $ apiKey , $ country );
93+ }
94+
95+ if ($ notification instanceof INotificationUsesTextlocalClientConfig) {
96+
97+ [$ username , $ hash , $ apiKey , $ country ] = $ notification ->getTextlocalClientConfig ($ notifiable );
98+
99+ $ client = new Textlocal ($ username , $ hash , $ apiKey , $ country );
100+ }
101+
102+ return $ client ;
103+ }
79104}
0 commit comments