1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: vincent
5
+ * Date: 12/14/17
6
+ * Time: 6:04 PM
7
+ */
8
+
9
+ namespace CraftedSystems \LaravelSMS \Gateways ;
10
+
11
+ use CraftedSystems \LaravelSMS \Contracts \SMSContract ;
12
+ use Illuminate \Http \Request ;
13
+ use AfricasTalking \AfricasTalkingGateway ;
14
+
15
+ class AfricasTalking implements SMSContract
16
+ {
17
+ /**
18
+ * @var AfricasTalkingGateway
19
+ */
20
+ protected $ class ;
21
+
22
+
23
+ /**
24
+ * MicroMobile constructor.
25
+ * @param $settings
26
+ * @throws \Exception
27
+ */
28
+ public function __construct ($ settings )
29
+ {
30
+ if (!class_exists ('AfricasTalking\AfricasTalkingGateway ' )) {
31
+
32
+ throw new \Exception ("Class 'AfricasTalking\AfricasTalkingGateway' does not exist " );
33
+ }
34
+
35
+ $ s = (object )$ settings ;
36
+
37
+ $ this ->class = new AfricasTalkingGateway ($ s ->username , $ s ->api_key );
38
+ }
39
+
40
+ /**
41
+ * @param $recipient
42
+ * @param $message
43
+ * @param null $params
44
+ * @return mixed
45
+ * @throws \Exception
46
+ */
47
+ public function send ($ recipient , $ message , $ params = null )
48
+ {
49
+ $ response = $ this ->class ->sendMessage ($ recipient , $ message , config ('sms.gateways.africastalking.from ' ));
50
+
51
+ $ data = [
52
+ 'is_success ' => $ response [0 ]->status === 'Success ' ,
53
+ 'correlator ' => '' ,
54
+ 'message_id ' => $ response [0 ]->messageId ,
55
+ 'cost ' => $ response [0 ]->cost
56
+ ];
57
+
58
+ return (object )$ data ;
59
+ }
60
+
61
+
62
+ /**
63
+ * @return mixed
64
+ * @throws \AfricasTalking\AfricasTalkingGatewayException
65
+ */
66
+ public function getBalance ()
67
+ {
68
+ return trim (str_replace ('KES ' , '' , $ this ->class ->getUserData ()->balance ));
69
+ }
70
+
71
+
72
+ /**
73
+ * @param Request $request
74
+ * @return mixed|object
75
+ */
76
+ public function getDeliveryReports (Request $ request )
77
+ {
78
+ $ status = $ request ->status ;
79
+
80
+ if ($ status == "Failed " || $ status == "Rejected " ) {
81
+
82
+ $ fs = $ request ->failureReason ;
83
+
84
+ } else {
85
+
86
+ $ fs = $ status ;
87
+ }
88
+
89
+
90
+ $ data = [
91
+ 'status ' => $ fs ,
92
+ 'message_id ' => $ request ->id ,
93
+ 'phone_number ' => ''
94
+ ];
95
+
96
+ return (object )$ data ;
97
+ }
98
+ }
0 commit comments