|
1
|
|
|
<?php |
|
2
|
|
|
namespace Tzsk\Sms\Drivers; |
|
3
|
|
|
|
|
4
|
|
|
use Melipayamak\MelipayamakApi; |
|
5
|
|
|
use Tzsk\Sms\Abstracts\Driver; |
|
6
|
|
|
|
|
7
|
|
|
class Melipayamak extends Driver |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Melipayamak Settings. |
|
11
|
|
|
* |
|
12
|
|
|
* @var null|object |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $settings = null; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Melipayamak Client. |
|
18
|
|
|
* |
|
19
|
|
|
* @var null|Client |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $client = null; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Construct the class with the relevant settings. |
|
25
|
|
|
* |
|
26
|
|
|
* SendSmsInterface constructor. |
|
27
|
|
|
* @param $settings object |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct($settings) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->settings = (object) $settings; |
|
32
|
|
|
$this->client = new MelipayamakApi($this->settings->username, $this->settings->password); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Determine if the sms must be a flash message or not. |
|
37
|
|
|
* |
|
38
|
|
|
* @param bool $flash |
|
39
|
|
|
* @return $this |
|
40
|
|
|
*/ |
|
41
|
|
|
public function asFlash($flash=true) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->settings->flash = $flash; |
|
44
|
|
|
|
|
45
|
|
|
return $this; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Send text message and return response. |
|
50
|
|
|
* |
|
51
|
|
|
* @return object |
|
52
|
|
|
*/ |
|
53
|
|
|
public function send() |
|
54
|
|
|
{ |
|
55
|
|
|
try { |
|
56
|
|
|
$response = ['status' => true, 'data' =>[]]; |
|
57
|
|
View Code Duplication |
foreach ($this->recipients as $recipient) { |
|
|
|
|
|
|
58
|
|
|
$sms = $this->client->sms()->send( |
|
59
|
|
|
$recipient, |
|
60
|
|
|
$this->settings->from, |
|
61
|
|
|
$this->body, |
|
62
|
|
|
$this->settings->flash |
|
63
|
|
|
); |
|
64
|
|
|
$response['data'][$recipient] = $this->getSmsResponse( |
|
65
|
|
|
json_decode($sms, true) |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
} catch (\Exception $e) { |
|
69
|
|
|
$response['status'][$recipient] = false; |
|
70
|
|
|
$response['data'][$recipient] = $e->getMessage(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$this->flash(false); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
return (object) $response; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Get the Melipayamak Response. |
|
80
|
|
|
* |
|
81
|
|
|
* @param $sms |
|
82
|
|
|
* @return object |
|
83
|
|
|
*/ |
|
84
|
|
|
protected function getSmsResponse($sms) |
|
85
|
|
|
{ |
|
86
|
|
|
$attributes = [ |
|
87
|
|
|
'recId', |
|
88
|
|
|
]; |
|
89
|
|
|
|
|
90
|
|
|
$res = []; |
|
91
|
|
|
foreach ($attributes as $attribute) { |
|
92
|
|
|
$res[$attribute] = $sms->$attribute; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return (object) $res; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..