Skip to content

Commit a49b173

Browse files
committed
Add verify endpoint
1 parent 9f7ad35 commit a49b173

File tree

7 files changed

+254
-8
lines changed

7 files changed

+254
-8
lines changed

examples/verify-create.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
$Verify = new \MessageBird\Objects\Verify();
8+
$Verify->recipient = 31612345678;
9+
10+
$extraOptions = [
11+
'originator' => 'MessageBird',
12+
'timeout' => 60,
13+
];
14+
15+
try {
16+
$VerifyResult = $MessageBird->verify->create($Verify, $extraOptions);
17+
var_dump($VerifyResult);
18+
19+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
20+
// That means that your accessKey is unknown
21+
echo 'wrong login';
22+
23+
} catch (\MessageBird\Exceptions\BalanceException $e) {
24+
// That means that you are out of credits, so do something about it.
25+
echo 'no balance';
26+
27+
} catch (\Exception $e) {
28+
echo $e->getMessage();
29+
}

examples/verify-verification.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
try {
8+
$VerifyResult = $MessageBird->verify->verify('05a90ee1155d2f4cdd12440v10006813', '585438'); // Set a message id and the token here.
9+
var_dump($VerifyResult);
10+
11+
// Check if $VerifyResult->getStatus() === MessageBird\Objects\Verify::STATUS_VERIFIED
12+
13+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
14+
// That means that your accessKey is unknown
15+
echo 'wrong login';
16+
17+
} catch (\Exception $e) {
18+
echo $e->getMessage();
19+
}

examples/verify-view.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
try {
8+
$VerifyResult = $MessageBird->verify->read('05a90ee1155d2f4cdd12440v10006813'); // Set a message id here
9+
var_dump($VerifyResult);
10+
11+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
12+
// That means that your accessKey is unknown
13+
echo 'wrong login';
14+
15+
} catch (\Exception $e) {
16+
echo $e->getMessage();
17+
}

src/MessageBird/Client.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ class Client
3535
public $hlr;
3636

3737
/**
38-
* @var Resources\Otp
38+
* @var Resources\Verify
3939
*/
40-
public $otp;
40+
public $verify;
4141

4242
/**
4343
* @var Resources\Balance
@@ -66,11 +66,12 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n
6666
if ($accessKey !== null) {
6767
$this->setAccessKey($accessKey);
6868
}
69-
$this->messages = new Resources\Messages($this->HttpClient);
70-
$this->hlr = new Resources\Hlr($this->HttpClient);
71-
$this->otp = new Resources\Otp($this->HttpClient);
72-
$this->balance = new Resources\Balance($this->HttpClient);
73-
$this->voicemessages = new Resources\VoiceMessage($this->HttpClient);
69+
70+
$this->messages = new Resources\Messages($this->HttpClient);
71+
$this->hlr = new Resources\Hlr($this->HttpClient);
72+
$this->verify = new Resources\Verify($this->HttpClient);
73+
$this->balance = new Resources\Balance($this->HttpClient);
74+
$this->voicemessages = new Resources\VoiceMessage($this->HttpClient);
7475
}
7576

7677
/**

src/MessageBird/Objects/Verify.php

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?php
2+
3+
namespace MessageBird\Objects;
4+
5+
/**
6+
* Class Verify
7+
*
8+
* @package MessageBird\Objects
9+
*/
10+
class Verify extends Base
11+
{
12+
const STATUS_SENT = 'sent';
13+
const STATUS_VERIFIED = 'verified';
14+
const STATUS_FAILED = 'failed';
15+
const STATUS_EXPIRED = 'expired';
16+
const STATUS_DELETED = 'deleted';
17+
18+
/**
19+
* An unique random ID which is created on the MessageBird platform and is returned upon
20+
* creation of the object.
21+
*
22+
* @var string
23+
*/
24+
protected $id;
25+
26+
/**
27+
* The URL of the created object.
28+
*
29+
* @var string
30+
*/
31+
protected $href;
32+
33+
/**
34+
* The msisdn of the recipient
35+
*
36+
* @var int
37+
*/
38+
public $recipient;
39+
40+
/**
41+
* A client reference. Here you can put your own reference,
42+
* like your internal reference.
43+
*
44+
* @var string
45+
*/
46+
public $reference;
47+
48+
/**
49+
* A hash containing one href entry referring to the URL of the created object.
50+
* The entry can either refer to either the messages or the voicemessages endpoint
51+
*
52+
* @var object
53+
*/
54+
protected $messages;
55+
56+
/**
57+
* The status of the Verify. Possible values: sent, expired, failed, verified, and deleted
58+
*
59+
* @var string
60+
*/
61+
protected $status;
62+
63+
/**
64+
* The date and time of the creation of the hlr in RFC3339 format (Y-m-d\TH:i:sP)
65+
*
66+
* @var string
67+
*/
68+
protected $createdDatetime;
69+
70+
/**
71+
* The date and time indicating the expiration time of the verify object in RFC3339 format (Y-m-d\TH:i:sP)
72+
*
73+
* @var string
74+
*/
75+
protected $validUntilDatetime;
76+
77+
78+
/**
79+
* Get the created id
80+
*
81+
* @return mixed
82+
*/
83+
public function getId()
84+
{
85+
return $this->id;
86+
}
87+
88+
/**
89+
* Get the created href
90+
*
91+
* @return string
92+
*/
93+
public function getHref()
94+
{
95+
return $this->href;
96+
}
97+
98+
/**
99+
* Get the created href
100+
*
101+
* @return string
102+
*/
103+
public function getMessage()
104+
{
105+
return $this->messages->href;
106+
}
107+
108+
/**
109+
* Get the status
110+
*
111+
* @return string
112+
*/
113+
public function getStatus()
114+
{
115+
return $this->status;
116+
}
117+
118+
/**
119+
* Get the $createdDatetime value
120+
*
121+
* @return string
122+
*/
123+
public function getCreatedDatetime()
124+
{
125+
return $this->createdDatetime;
126+
}
127+
128+
/**
129+
* Get the $validUntilDatetime value
130+
*
131+
* @return string
132+
*/
133+
public function getValidUntilDatetime()
134+
{
135+
return $this->validUntilDatetime;
136+
}
137+
}

src/MessageBird/Resources/Base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Base
2525
protected $resourceName;
2626

2727
/**
28-
* @var Objects\Hlr|Objects\Message|Objects\Balance
28+
* @var Objects\Hlr|Objects\Message|Objects\Balance|Objects\Verify
2929
*/
3030
protected $Object;
3131

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace MessageBird\Resources;
4+
5+
use MessageBird\Objects;
6+
use MessageBird\Common;
7+
8+
/**
9+
* Class Verify
10+
*
11+
* @package MessageBird\Resources
12+
*/
13+
class Verify extends Base
14+
{
15+
16+
/**
17+
* @param Common\HttpClient $HttpClient
18+
*/
19+
public function __construct(Common\HttpClient $HttpClient)
20+
{
21+
$this->setObject(new Objects\Verify);
22+
$this->setResourceName('verify');
23+
24+
parent::__construct($HttpClient);
25+
}
26+
27+
/**
28+
* @param $id
29+
* @param $token
30+
*
31+
* @return $this->Object
32+
*
33+
* @throws \MessageBird\Exceptions\HttpException
34+
* @throws \MessageBird\Exceptions\RequestException
35+
* @throws \MessageBird\Exceptions\ServerException
36+
*/
37+
public function verify($id, $token)
38+
{
39+
$ResourceName = $this->resourceName . (($id) ? '/' . $id : null);
40+
list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_GET, $ResourceName, ['token' => $token]);
41+
return $this->processRequest($body);
42+
}
43+
}

0 commit comments

Comments
 (0)