3
3
namespace NotificationChannels \Textlocal ;
4
4
5
5
use Illuminate \Notifications \Notification ;
6
+ use NotificationChannels \Textlocal \Contracts \INotificationUsesTextlocalClientConfig ;
7
+ use NotificationChannels \Textlocal \Contracts \IUsesTextlocalClientConfig ;
6
8
use NotificationChannels \Textlocal \Exceptions \CouldNotSendNotification ;
7
9
8
10
/**
@@ -66,8 +68,10 @@ public function send($notifiable, Notification $notification)
66
68
$ this ->sender = $ notification ->getSenderId ();
67
69
}
68
70
71
+ $ client = $ this ->getClient ($ notifiable , $ notification );
72
+
69
73
try {
70
- $ response = $ this -> client
74
+ $ response = $ client
71
75
->setUnicodeMode ($ unicode )
72
76
->sendSms ($ numbers , $ message , $ this ->sender );
73
77
@@ -76,4 +80,25 @@ public function send($notifiable, Notification $notification)
76
80
throw CouldNotSendNotification::serviceRespondedWithAnError ($ exception , $ message );
77
81
}
78
82
}
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
+ }
79
104
}
0 commit comments