Completed
Push — master ( d595bc...3de291 )
by
unknown
01:27 queued 10s
created

NetgsmOtpMessage::mappers()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
4
namespace TarfinLabs\Netgsm;
5
6
7
use TarfinLabs\Netgsm\Exceptions\CouldNotSendNotification;
8
9
class NetgsmOtpMessage extends AbstractNetgsmMessage
10
{
11
    protected $url = 'https://api.netgsm.com.tr/sms/send/otp';
12
13
    protected $errorCodes = [
14
        '20'  => CouldNotSendNotification::MESSAGE_TOO_LONG,
15
        '30'  => CouldNotSendNotification::CREDENTIALS_INCORRECT,
16
        '40'  => CouldNotSendNotification::SENDER_INCORRECT,
17
        '50'  => CouldNotSendNotification::RECEIVER_INCORRECT,
18
        '60'  => CouldNotSendNotification::OTP_ACCOUNT_NOT_DEFINED,
19
        '70'  => CouldNotSendNotification::PARAMETERS_INCORRECT,
20
        '80'  => CouldNotSendNotification::QUERY_LIMIT_EXCEED,
21
        '100' => CouldNotSendNotification::SYSTEM_ERROR,
22
    ];
23
24
    protected $fields = [
25
        'usercode',
26
        'password',
27
        'msgheader',
28
        'msg',
29
        'no'
30
    ];
31
32
    /**
33
     * @return string
34
     */
35
    protected function createXmlPost(): string
36
    {
37
        $xml = '<?xml version="1.0" encoding="UTF-8"?>';
38
        $xml .= '<mainbody>';
39
        $xml .= '<header>';
40
        $xml .= '<usercode>'.$this->credentials['user_code'].'</usercode>';
41
        $xml .= '<password>'.$this->credentials['secret'].'</password>';
42
        $xml .= '<msgheader>'.$this->getHeader().'</msgheader>';
43
        $xml .= '</header>';
44
        $xml .= '<body>';
45
        $xml .= '<msg>';
46
        $xml .= '<![CDATA['.$this->message.']]>';
47
        $xml .= '</msg>';
48
        foreach ($this->recipients as $recipient) {
49
            $xml .= '<no>'.$recipient.'</no>';
50
        }
51
        $xml .= '</body>';
52
        $xml .= '</mainbody>';
53
54
        return $xml;
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function getUrl(): string
61
    {
62
        return $this->url;
63
    }
64
65
    /**
66
     * @return array
67
     */
68
    protected function mappers(): array
69
    {
70
        return [
71
            'usercode'  => $this->credentials['user_code'],
72
            'password'  => $this->credentials['secret'],
73
            'msgheader' => $this->header ?? $this->defaults['header'],
74
            'msg'       => $this->message,
75
            'no'        => is_array($this->recipients) ? $this->recipients[0] : $this->recipients,
76
        ];
77
    }
78
}
79