|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LBHurtado\EngageSpark\Classes; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Arr; |
|
6
|
|
|
use LBHurtado\EngageSpark\EngageSpark; |
|
7
|
|
|
use Propaganistas\LaravelPhone\PhoneNumber; |
|
8
|
|
|
use LBHurtado\Common\Contracts\HttpApiParams; |
|
9
|
|
|
|
|
10
|
|
|
class SendHttpApiParams implements HttpApiParams |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var EngageSpark |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $service; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $mobile; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $message; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $senderId; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $recipientType = 'mobile_number'; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* SendParams constructor. |
|
39
|
|
|
* @param $service |
|
40
|
|
|
* @param $mobile |
|
41
|
|
|
* @param $message |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct(EngageSpark $service, string $mobile, string $message, string $senderId = null) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->service = $service; |
|
46
|
|
|
$this->mobile = $mobile; |
|
47
|
|
|
$this->message = $message; |
|
48
|
|
|
$this->setSenderId($service, $senderId); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function toArray(): array |
|
52
|
|
|
{ |
|
53
|
|
|
return [ |
|
54
|
|
|
'orgId' => $this->service->getOrgId(), |
|
55
|
|
|
'to' => $this->getFormattedMobile(), |
|
56
|
|
|
'from' => $this->senderId, |
|
57
|
|
|
'message' => $this->message, |
|
58
|
|
|
]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function setSenderId(EngageSpark $service, string $senderId = null) |
|
62
|
|
|
{ |
|
63
|
|
|
$this->senderId = $senderId ?? $service->getSenderId(); |
|
64
|
|
|
|
|
65
|
|
|
return $this; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
protected function getFormattedMobile() |
|
69
|
|
|
{ |
|
70
|
|
|
return tap(PhoneNumber::make($this->mobile, 'PH')->formatE164(), function(&$recipient) { |
|
71
|
|
|
$recipient = preg_replace('/\D/', '', $recipient); |
|
72
|
|
|
}); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|