forked from prawnsalad/Nexmo-PHP-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NexmoReceipt.php
58 lines (46 loc) · 1.33 KB
/
NexmoReceipt.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* Class NexmoReceipt handles and incoming message receipts sent by Nexmo
*
* Usage: $var = new NexmoReceipt ();
* Methods:
* exists ( )
*
*
*/
class NexmoReceipt {
const STATUS_DELIVERED = 'DELIVERED';
const STATUS_EXPIRED = 'EXPIRED';
const STATUS_FAILED = 'FAILED';
const STATUS_BUFFERED = 'BUFFERED';
public $from = '';
public $to = '';
public $network = '';
public $message_id = '';
public $status = '';
public $received_time = 0; // Format: UNIX timestamp
public $found = false;
public function __construct ($data = false) {
if (!$data) $data = $_GET;
if (!isset($data['msisdn'], $data['network-code'], $data['messageId'])) {
return;
}
// Flag that a receipt was found
$this->found = true;
// Get the relevant data
$this->to = $data['msisdn'];
$this->from = $data['to'];
$this->network = $data['network-code'];
$this->message_id = $data['messageId'];
$this->status = strtoupper($data['status']);
// Format the date into timestamp
$dp = date_parse_from_format('ymdGi', $data['scts']);
$this->received_time = mktime($dp['hour'], $dp['minute'], $dp['second'], $dp['month'], $dp['day'], $dp['year']);
}
/**
* Returns true if a valid receipt is found
*/
public function exists () {
return $this->found;
}
}