1+ <?php
2+ /**
3+ * @author Tim Lytle <tim@timlytle.net>
4+ */
5+
6+ namespace Nexmo \Message \Callback ;
7+ use Nexmo \Client \Callback \Callback ;
8+
9+ class Receipt extends Callback
10+ {
11+ protected $ expected = array (
12+ 'err-code ' ,
13+ 'message-timestamp ' ,
14+ 'msisdn ' ,
15+ 'network-code ' ,
16+ 'price ' ,
17+ 'scts ' ,
18+ 'status ' ,
19+ //'timestamp',
20+ 'to '
21+ );
22+
23+ public function __construct (array $ data )
24+ {
25+ //default value
26+ $ data = array_merge (array ('client-ref ' => null ), $ data );
27+
28+ parent ::__construct ($ data );
29+ }
30+
31+ /**
32+ * @return int
33+ */
34+ public function getErrorCode ()
35+ {
36+ return (int ) $ this ->data ['err-code ' ];
37+ }
38+
39+ /**
40+ * @return string
41+ */
42+ public function getNetwork ()
43+ {
44+ return (string ) $ this ->data ['network-code ' ];
45+ }
46+
47+ /**
48+ * @return string
49+ */
50+ public function getId ()
51+ {
52+ return (string ) $ this ->data ['messageId ' ];
53+ }
54+
55+ /**
56+ * @return string
57+ */
58+ public function getReceiptFrom ()
59+ {
60+ return (string ) $ this ->data ['msisdn ' ];
61+ }
62+
63+ /**
64+ * @return string
65+ */
66+ public function getTo ()
67+ {
68+ return $ this ->getReceiptFrom ();
69+ }
70+
71+ /**
72+ * @return string
73+ */
74+ public function getReceiptTo ()
75+ {
76+ return (string ) $ this ->data ['to ' ];
77+ }
78+
79+ /**
80+ * @return string
81+ */
82+ public function getFrom ()
83+ {
84+ return $ this ->getReceiptTo ();
85+ }
86+
87+ /**
88+ * @return string
89+ */
90+ public function getStatus ()
91+ {
92+ return (string ) $ this ->data ['status ' ];
93+ }
94+
95+ /**
96+ * @return string
97+ */
98+ public function getPrice ()
99+ {
100+ return (string ) $ this ->data ['price ' ];
101+ }
102+
103+ /**
104+ * @return \DateTime
105+ */
106+ public function getTimestamp ()
107+ {
108+ $ date = \DateTime::createFromFormat ('ymdHi ' , $ this ->data ['scts ' ]);
109+ if ($ date ){
110+ return $ date ;
111+ }
112+
113+ throw new \UnexpectedValueException ('could not parse message timestamp ' );
114+ }
115+
116+ /**
117+ * @return \DateTime
118+ */
119+ public function getSent ()
120+ {
121+ $ date = \DateTime::createFromFormat ('Y-m-d H:i:s ' , $ this ->data ['message-timestamp ' ]);
122+ if ($ date ){
123+ return $ date ;
124+ }
125+
126+ throw new \UnexpectedValueException ('could not parse message timestamp ' );
127+ }
128+
129+ /**
130+ * @return string|null
131+ */
132+ public function getClientRef ()
133+ {
134+ return $ this ->data ['client-ref ' ];
135+ }
136+ }
0 commit comments