From 7222fda846fde9ca767786159d3e7bfb212ff2dc Mon Sep 17 00:00:00 2001 From: Rajneesh Katkam Date: Tue, 1 Aug 2023 03:01:36 +0530 Subject: [PATCH 1/8] Verify APIs for PHP --- CHANGELOG.md | 6 + src/Plivo/Resources/Verify/VerifySession.php | 84 +++++++ .../Verify/VerifySessionCreateResponse.php | 37 +++ .../Verify/VerifySessionInterface.php | 225 ++++++++++++++++++ .../Resources/Verify/VerifySessionList.php | 33 +++ src/Plivo/RestClient.php | 18 ++ src/Plivo/Version.php | 2 +- 7 files changed, 404 insertions(+), 1 deletion(-) create mode 100644 src/Plivo/Resources/Verify/VerifySession.php create mode 100644 src/Plivo/Resources/Verify/VerifySessionCreateResponse.php create mode 100644 src/Plivo/Resources/Verify/VerifySessionInterface.php create mode 100644 src/Plivo/Resources/Verify/VerifySessionList.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dcae2ca..36e9fdde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ # Change Log +## [4.53.0](https://github.com/plivo/plivo-php/tree/v4.53.0) (2023-08-02) +**Feature - Verify** +- Added Create Session API +- Added Get Session API +- Added List Session API +- Added Validate Session API ## [4.52.0](https://github.com/plivo/plivo-php/tree/v4.52.0) (2023-07-18) - Removed object_id and object_type in the parameter as well as response in [list all numbers API] diff --git a/src/Plivo/Resources/Verify/VerifySession.php b/src/Plivo/Resources/Verify/VerifySession.php new file mode 100644 index 00000000..967c2639 --- /dev/null +++ b/src/Plivo/Resources/Verify/VerifySession.php @@ -0,0 +1,84 @@ +properties = [ + 'apiId' => $response['api_id'], + 'sessionUuid' => $response['session_uuid'], + 'appUuid' => $response['app_uuid'], + 'alias' => $response['alias'], + 'recipient' => $response['recipient'], + 'channel' => $response['channel'], + 'status' => $response['status'], + 'count' => $response['count'], + 'createdAt' => $response['created_at'], + 'updatedAt' => $response['updated_at'], + ]; + + // handled empty string and null case + if (!empty($response['requestor_ip'])) { + $this->properties['requesterIP'] = $response['requestor_ip']; + } + + if (!empty($response['destination_country_iso2'])) { + $this->properties['destinationCountryIso2'] = $response['destination_country_iso2']; + } + if (!empty($response['destination_network'])) { + $this->properties['destinationNetwork'] = $response['destination_network']; + } + if (!empty($response['attempt_details'])) { + $this->properties['attemptDetails'] = $response['attempt_details']; + } + if (!empty($response['charges'])) { + $this->properties['charges'] = $response['charges']; + } + + + $this->pathParams = [ + 'authId' => $authId, + 'sessionUuid' => $response['session_uuid'] + ]; + + $this->id = $response['session_uuid']; + $this->uri = $uri; + } + public function __debugInfo() { + return $this->properties; + } +} \ No newline at end of file diff --git a/src/Plivo/Resources/Verify/VerifySessionCreateResponse.php b/src/Plivo/Resources/Verify/VerifySessionCreateResponse.php new file mode 100644 index 00000000..809ada4f --- /dev/null +++ b/src/Plivo/Resources/Verify/VerifySessionCreateResponse.php @@ -0,0 +1,37 @@ +sessionUuid = $sessionUuid; + } + + /** + * Get the Session UUID + * @return string + */ + public function getSessionUuid() + { + return $this->sessionUuid; + } + + +} \ No newline at end of file diff --git a/src/Plivo/Resources/Verify/VerifySessionInterface.php b/src/Plivo/Resources/Verify/VerifySessionInterface.php new file mode 100644 index 00000000..ed4cf4b2 --- /dev/null +++ b/src/Plivo/Resources/Verify/VerifySessionInterface.php @@ -0,0 +1,225 @@ +pathParams = [ + 'authId' => $authId + ]; + $this->uri = "Account/".$authId."/"; + } + + /** + * @param string $sessionUuid + * @return VerifySession + * @throws PlivoValidationException + */ + public function get($sessionUuid) + { + if (ArrayOperations::checkNull([$sessionUuid])) { + throw + new PlivoValidationException( + 'session uuid is mandatory'); + } + + $response = $this->client->fetch( + $this->uri . 'Verify/Session/'. $sessionUuid .'/', + [] + ); + + // return the object for chain method + if ($response->getStatusCode() == 200){ + return new VerifySession( + $this->client, $response->getContent(), + $this->pathParams['authId'], $this->uri); + } + return json_encode($response->getContent(), JSON_FORCE_OBJECT); + } + + + + /** + * Return a list of sessions + * @param array $optionalArgs + * + Valid arguments + * + [string] :session_time - Filter out messages according to the time of completion. The filter can be used in the following five forms: + *
session_time: The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received at 2012-03-21 11:47[:30], use session_time=2012-03-21 11:47[:30] + *
session_time\__gt: gt stands for greater than. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received after 2012-03-21 11:47, use session_time\__gt=2012-03-21 11:47 + *
session_time\__gte: gte stands for greater than or equal. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received after or exactly at 2012-03-21 11:47[:30], use session_time\__gte=2012-03-21 11:47[:30] + *
session_time\__lt: lt stands for lesser than. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received before 2012-03-21 11:47, use session_time\__lt=2012-03-21 11:47 + *
session_time\__lte: lte stands for lesser than or equal. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received before or exactly at 2012-03-21 11:47[:30], use session_time\__lte=2012-03-21 11:47[:30] + *
Note: The above filters can be combined to get messages that were sent/received in a particular time range. The timestamps need to be UTC timestamps. + * + [string] :status - Status value of the session, is one of "in-progress", "validated" or "expired". + * + [int] :limit - Used to display the number of results per page. The maximum number of results that can be fetched is 20. + * + [int] :offset - Denotes the number of value items by which the results should be offset. Eg:- If the result contains a 1000 values and limit is set to 10 and offset is set to 705, then values 706 through 715 are displayed in the results. This parameter is also used for pagination of the results. + * + [string] : recipient - Filters the results by recipient number. + * + [string] : app_uuid - Filter the results by App UUID. + * + [string]: country - Filter the results by country. For e.g. Filter results for India using 'IN' as the value. + * + [string]: alias - Filter the results using alias of verify application. + * @return VerifySessionList output + */ + public function list( $optionalArgs = []) + { + $response = $this->client->fetch( + $this->uri . 'Verify/Session/', + $optionalArgs + ); + + if(!array_key_exists("error", $response->getContent())) { + $sessions = []; + foreach ($response->getContent()['sessions'] as $session) { + $newSession = new VerifySession($this->client, $session, $this->pathParams['authId'], $this->uri); + array_push($sessions, $newSession); + } + return new VerifySessionList($this->client, $response->getContent()['meta'], $sessions, $response->getContent()["api_id"]); + } else { + throw new PlivoResponseException( + $response->getContent()['error'], + 0, + null, + $response->getContent(), + $response->getStatusCode() + ); + } + } + + /** + * Create a new Session + * + * @param string $recipient + * @param array $optionalArgs + * + Valid arguments + * + [string] :app_uuid - The application that needs to be used for sending the verification code. + * + [string] :channel - The channel to be used for sending the verification code. NOTE: Application should support the channel mentioned. + * + [string] :url - The URL to which with the status of the session is sent. The following parameters are sent to the URL: + *
SessionUUID - The unique ID for the session + *
ChannelStatus - The status received from the channel(sms/voice). + *
Recipient - The number to which verification code is sent. + *
RequestTime - The time at which the session request was made. + *
AttemptUUID - The unique ID for the channel(sms/voice) through which verification code is sent. + *
Channel - The channel(sms/voice) through which verification code is sent. + *
ChannelErrorCode - Error code received from the channel if any error occurred. + *
AttemptSequence - The attempt number for which the session status is received. For e.g. is two attempted are made within a session, 1st via SMS and 2nd via Voice, then callbacks received for SMS would have AttemptSequence value as 1 and for Voice it would be 2. + *
SessionStatus - The status of the session(in-progress/validated/expired). + * + [string] :method - The method used to call the url. Defaults to POST. + * @return VerifySessionCreateResponse output + * @throws PlivoValidationException,PlivoResponseException + */ + public function create($recipient, array $optionalArgs = []) + { + $mandatoryArgs = [ + 'recipient' => $recipient, + ]; + + if (ArrayOperations::checkNull($mandatoryArgs)) { + throw new PlivoValidationException( + "Mandatory parameters cannot be null"); + } + + $response = $this->client->update( + $this->uri .'Verify/Session/', + array_merge($mandatoryArgs, $optionalArgs) + ); + + $responseContents = $response->getContent(); + + if(array_key_exists("error",$responseContents)){ + throw new PlivoResponseException( + $responseContents['error'], + 0, + null, + $response->getContent(), + $response->getStatusCode() + + ); + } else { + return new VerifySessionCreateResponse( + $responseContents['message'], + $responseContents['session_uuid'], + $responseContents['api_id'], + $response->getStatusCode() + ); + } + } + + + /** + * Validate Session + * + * @param string $sessionUuid + * @param string $otp + * @return VerifySessionCreateResponse + */ + public function validate($sessionUuid, $otp) + { + + $mandatoryArgs = [ + 'otp' => $otp, + ]; + + if (ArrayOperations::checkNull([$sessionUuid])) { + throw + new PlivoValidationException( + 'session uuid is mandatory'); + } + + if (ArrayOperations::checkNull($mandatoryArgs)) { + throw new PlivoValidationException( + "Mandatory parameters cannot be null"); + } + + $response = $this->client->update( + $this->uri . 'Verify/Session/'. $sessionUuid .'/', + $mandatoryArgs + ); + + $responseContents = $response->getContent(); + + if(array_key_exists("error",$responseContents)){ + throw new PlivoResponseException( + $responseContents['error'], + 0, + null, + $response->getContent(), + $response->getStatusCode() + + ); + } else { + return new VerifySessionCreateResponse( + $responseContents['message'], + "", + $responseContents['api_id'], + $response->getStatusCode() + ); + } + } + + +} \ No newline at end of file diff --git a/src/Plivo/Resources/Verify/VerifySessionList.php b/src/Plivo/Resources/Verify/VerifySessionList.php new file mode 100644 index 00000000..5d669d32 --- /dev/null +++ b/src/Plivo/Resources/Verify/VerifySessionList.php @@ -0,0 +1,33 @@ +apiId = $apiId; + } +} \ No newline at end of file diff --git a/src/Plivo/RestClient.php b/src/Plivo/RestClient.php index dc21b2ab..c9517891 100644 --- a/src/Plivo/RestClient.php +++ b/src/Plivo/RestClient.php @@ -11,6 +11,7 @@ use Plivo\Resources\HostedMessaging\HostedMessageLOAInterface; use Plivo\Resources\HostedMessaging\HostedMessagingNumberInterface; use Plivo\Resources\Message\MessageInterface; +use Plivo\Resources\Verify\VerifySessionInterface; use Plivo\Resources\Powerpack\PowerpackInterface; use Plivo\Resources\Media\MediaInterface; use Plivo\Resources\Brand\BrandInterface; @@ -42,6 +43,7 @@ * @property ApplicationInterface application Interface to handle all Application related api calls * @property AccountInterface account Interface to handle all Account related api calls * @property MessageInterface message Interface to handle all Message related api calls + * @property VerifySessionInterface verify session Interface to handle all Session related api calls * @property PowerpackInterface powerpack Interface to handle all Powerpack related api calls * @property MediaInterface media Interface to handle all upload mms media api * @property ProfileInterface profile Interface to handle all 10dlc related profile api @@ -83,6 +85,11 @@ class RestClient */ protected $_message; + /** + * @var VerifySessionInterface + */ + protected $_verifySession; + /** * @var PowerpackInterface */ @@ -276,6 +283,17 @@ protected function getMessages() return $this->_message; } + /** + * @return VerifySessionInterface + */ + protected function getVerifySessions() + { + if (!$this->_verifySession) { + $this->_verifySession = new VerifySessionInterface($this->client, $this->client->getAuthId()); + } + return $this->_verifySession; + } + /** * @return PowerpackInterface */ diff --git a/src/Plivo/Version.php b/src/Plivo/Version.php index 38ae7a1f..7bbf0783 100644 --- a/src/Plivo/Version.php +++ b/src/Plivo/Version.php @@ -20,7 +20,7 @@ class Version /** * @const int PHP helper library minor version number */ - const MINOR = 52; + const MINOR = 53; /** * @const int PHP helper library patch number From 9d6fd5a3a23ccbb0ff730374e528cef31e834453 Mon Sep 17 00:00:00 2001 From: Rajneesh Katkam Date: Tue, 1 Aug 2023 12:25:15 +0530 Subject: [PATCH 2/8] Verify APIs for PHP --- .../Resources/Verify/VerifySessionInterface.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Plivo/Resources/Verify/VerifySessionInterface.php b/src/Plivo/Resources/Verify/VerifySessionInterface.php index ed4cf4b2..b20035d1 100644 --- a/src/Plivo/Resources/Verify/VerifySessionInterface.php +++ b/src/Plivo/Resources/Verify/VerifySessionInterface.php @@ -69,13 +69,13 @@ public function get($sessionUuid) * Return a list of sessions * @param array $optionalArgs * + Valid arguments - * + [string] :session_time - Filter out messages according to the time of completion. The filter can be used in the following five forms: - *
session_time: The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received at 2012-03-21 11:47[:30], use session_time=2012-03-21 11:47[:30] - *
session_time\__gt: gt stands for greater than. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received after 2012-03-21 11:47, use session_time\__gt=2012-03-21 11:47 - *
session_time\__gte: gte stands for greater than or equal. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received after or exactly at 2012-03-21 11:47[:30], use session_time\__gte=2012-03-21 11:47[:30] - *
session_time\__lt: lt stands for lesser than. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received before 2012-03-21 11:47, use session_time\__lt=2012-03-21 11:47 - *
session_time\__lte: lte stands for lesser than or equal. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received before or exactly at 2012-03-21 11:47[:30], use session_time\__lte=2012-03-21 11:47[:30] - *
Note: The above filters can be combined to get messages that were sent/received in a particular time range. The timestamps need to be UTC timestamps. + * + [string] :session_time - Filter out sessions according to the time of completion. The filter can be used in the following five forms: + *
session_time: The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all sessions that were sent/received at 2012-03-21 11:47[:30], use session_time=2012-03-21 11:47[:30] + *
session_time\__gt: gt stands for greater than. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all sessions that were sent/received after 2012-03-21 11:47, use session_time\__gt=2012-03-21 11:47 + *
session_time\__gte: gte stands for greater than or equal. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all sessions that were sent/received after or exactly at 2012-03-21 11:47[:30], use session_time\__gte=2012-03-21 11:47[:30] + *
session_time\__lt: lt stands for lesser than. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all sessions that were sent/received before 2012-03-21 11:47, use session_time\__lt=2012-03-21 11:47 + *
session_time\__lte: lte stands for lesser than or equal. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all sessions that were sent/received before or exactly at 2012-03-21 11:47[:30], use session_time\__lte=2012-03-21 11:47[:30] + *
Note: The above filters can be combined to get sessions that were sent/received in a particular time range. The timestamps need to be UTC timestamps. * + [string] :status - Status value of the session, is one of "in-progress", "validated" or "expired". * + [int] :limit - Used to display the number of results per page. The maximum number of results that can be fetched is 20. * + [int] :offset - Denotes the number of value items by which the results should be offset. Eg:- If the result contains a 1000 values and limit is set to 10 and offset is set to 705, then values 706 through 715 are displayed in the results. This parameter is also used for pagination of the results. From 60c5b1ff0e4a7c893f3e3193409a4ddf8e837065 Mon Sep 17 00:00:00 2001 From: Rajneesh Katkam Date: Tue, 1 Aug 2023 13:20:26 +0530 Subject: [PATCH 3/8] Added null checks for api-id --- src/Plivo/Resources/Verify/VerifySession.php | 5 ++++- src/Plivo/Resources/Verify/VerifySessionInterface.php | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Plivo/Resources/Verify/VerifySession.php b/src/Plivo/Resources/Verify/VerifySession.php index 967c2639..15241f44 100644 --- a/src/Plivo/Resources/Verify/VerifySession.php +++ b/src/Plivo/Resources/Verify/VerifySession.php @@ -39,7 +39,6 @@ public function __construct( parent::__construct($client); $this->properties = [ - 'apiId' => $response['api_id'], 'sessionUuid' => $response['session_uuid'], 'appUuid' => $response['app_uuid'], 'alias' => $response['alias'], @@ -52,6 +51,10 @@ public function __construct( ]; // handled empty string and null case + if (!empty($response['api_id'])) { + $this->properties['apiId'] = $response['api_id']; + } + if (!empty($response['requestor_ip'])) { $this->properties['requesterIP'] = $response['requestor_ip']; } diff --git a/src/Plivo/Resources/Verify/VerifySessionInterface.php b/src/Plivo/Resources/Verify/VerifySessionInterface.php index b20035d1..2098d57b 100644 --- a/src/Plivo/Resources/Verify/VerifySessionInterface.php +++ b/src/Plivo/Resources/Verify/VerifySessionInterface.php @@ -12,6 +12,7 @@ use Plivo\Resources\ResourceInterface; use Plivo\Exceptions\PlivoNotFoundException; use Plivo\Resources\ResourceList; +use Plivo\Resources\ResponseUpdate; /** * Class VerifySessionInterface @@ -175,7 +176,7 @@ public function create($recipient, array $optionalArgs = []) * * @param string $sessionUuid * @param string $otp - * @return VerifySessionCreateResponse + * @return ResponseUpdate */ public function validate($sessionUuid, $otp) { @@ -212,10 +213,9 @@ public function validate($sessionUuid, $otp) ); } else { - return new VerifySessionCreateResponse( - $responseContents['message'], - "", + return new ResponseUpdate( $responseContents['api_id'], + $responseContents['message'], $response->getStatusCode() ); } From 3b62e61020c3a37bdb6c72a6a68ca70b02f2916c Mon Sep 17 00:00:00 2001 From: Rajneesh Katkam Date: Tue, 1 Aug 2023 13:41:34 +0530 Subject: [PATCH 4/8] Return object changed for validate() --- .../Verify/VerifySessionInterface.php | 21 ++----------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/Plivo/Resources/Verify/VerifySessionInterface.php b/src/Plivo/Resources/Verify/VerifySessionInterface.php index 2098d57b..7ee81415 100644 --- a/src/Plivo/Resources/Verify/VerifySessionInterface.php +++ b/src/Plivo/Resources/Verify/VerifySessionInterface.php @@ -12,7 +12,6 @@ use Plivo\Resources\ResourceInterface; use Plivo\Exceptions\PlivoNotFoundException; use Plivo\Resources\ResourceList; -use Plivo\Resources\ResponseUpdate; /** * Class VerifySessionInterface @@ -176,7 +175,7 @@ public function create($recipient, array $optionalArgs = []) * * @param string $sessionUuid * @param string $otp - * @return ResponseUpdate + * @return array */ public function validate($sessionUuid, $otp) { @@ -202,23 +201,7 @@ public function validate($sessionUuid, $otp) ); $responseContents = $response->getContent(); - - if(array_key_exists("error",$responseContents)){ - throw new PlivoResponseException( - $responseContents['error'], - 0, - null, - $response->getContent(), - $response->getStatusCode() - - ); - } else { - return new ResponseUpdate( - $responseContents['api_id'], - $responseContents['message'], - $response->getStatusCode() - ); - } + return $responseContents; } From 193ba71a26e541d9efdb3e3d10092c8c09808a4a Mon Sep 17 00:00:00 2001 From: Rajneesh Katkam Date: Tue, 1 Aug 2023 14:39:51 +0530 Subject: [PATCH 5/8] checks added for mandatory params --- .../Verify/VerifySessionInterface.php | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/Plivo/Resources/Verify/VerifySessionInterface.php b/src/Plivo/Resources/Verify/VerifySessionInterface.php index 7ee81415..808f9fa2 100644 --- a/src/Plivo/Resources/Verify/VerifySessionInterface.php +++ b/src/Plivo/Resources/Verify/VerifySessionInterface.php @@ -12,6 +12,7 @@ use Plivo\Resources\ResourceInterface; use Plivo\Exceptions\PlivoNotFoundException; use Plivo\Resources\ResourceList; +use Plivo\Resources\ResponseUpdate; /** * Class VerifySessionInterface @@ -43,10 +44,10 @@ public function __construct(BaseClient $plivoClient, $authId) */ public function get($sessionUuid) { - if (ArrayOperations::checkNull([$sessionUuid])) { + if (ArrayOperations::checkNull([$sessionUuid]) or empty($sessionUuid)) { throw new PlivoValidationException( - 'session uuid is mandatory'); + 'session uuid is mandatory and cannot be empty'); } $response = $this->client->fetch( @@ -138,9 +139,9 @@ public function create($recipient, array $optionalArgs = []) 'recipient' => $recipient, ]; - if (ArrayOperations::checkNull($mandatoryArgs)) { + if (ArrayOperations::checkNull($mandatoryArgs) or empty($recipient)) { throw new PlivoValidationException( - "Mandatory parameters cannot be null"); + "recipient is mandatory and cannot be empty"); } $response = $this->client->update( @@ -175,7 +176,7 @@ public function create($recipient, array $optionalArgs = []) * * @param string $sessionUuid * @param string $otp - * @return array + * @return ResponseUpdate */ public function validate($sessionUuid, $otp) { @@ -184,15 +185,15 @@ public function validate($sessionUuid, $otp) 'otp' => $otp, ]; - if (ArrayOperations::checkNull([$sessionUuid])) { + if (ArrayOperations::checkNull([$sessionUuid]) or empty($sessionUuid)) { throw new PlivoValidationException( - 'session uuid is mandatory'); + 'session uuid is mandatory and cannot be empty'); } - if (ArrayOperations::checkNull($mandatoryArgs)) { + if (ArrayOperations::checkNull($mandatoryArgs) or empty($otp)) { throw new PlivoValidationException( - "Mandatory parameters cannot be null"); + "otp is mandatory and cannot be empty"); } $response = $this->client->update( @@ -201,7 +202,22 @@ public function validate($sessionUuid, $otp) ); $responseContents = $response->getContent(); - return $responseContents; + if(array_key_exists("error",$responseContents)){ + throw new PlivoResponseException( + $responseContents['error'], + 0, + null, + $response->getContent(), + $response->getStatusCode() + + ); + } else { + return new ResponseUpdate( + $responseContents['api_id'], + $responseContents['message'], + $response->getStatusCode() + ); + } } From b8c26ad11699772f53b44e1fa7bc3c24fddeafc8 Mon Sep 17 00:00:00 2001 From: Rajneesh Katkam Date: Tue, 1 Aug 2023 14:47:08 +0530 Subject: [PATCH 6/8] added exception for get response --- .../Verify/VerifySessionInterface.php | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Plivo/Resources/Verify/VerifySessionInterface.php b/src/Plivo/Resources/Verify/VerifySessionInterface.php index 808f9fa2..7b6daa5c 100644 --- a/src/Plivo/Resources/Verify/VerifySessionInterface.php +++ b/src/Plivo/Resources/Verify/VerifySessionInterface.php @@ -40,7 +40,7 @@ public function __construct(BaseClient $plivoClient, $authId) /** * @param string $sessionUuid * @return VerifySession - * @throws PlivoValidationException + * @throws PlivoValidationException,PlivoResponseException */ public function get($sessionUuid) { @@ -54,14 +54,28 @@ public function get($sessionUuid) $this->uri . 'Verify/Session/'. $sessionUuid .'/', [] ); - + // return the object for chain method if ($response->getStatusCode() == 200){ return new VerifySession( $this->client, $response->getContent(), $this->pathParams['authId'], $this->uri); } - return json_encode($response->getContent(), JSON_FORCE_OBJECT); + + $responseContents = $response->getContent(); + if(array_key_exists("error",$responseContents)){ + throw new PlivoResponseException( + $responseContents['error'], + 0, + null, + $response->getContent(), + $response->getStatusCode() + + ); + } else { + return json_encode($response->getContent(), JSON_FORCE_OBJECT); + } + } From e8c0612d51039b06527d00f1c2012960d5937004 Mon Sep 17 00:00:00 2001 From: Rajneesh Katkam Date: Tue, 1 Aug 2023 17:42:30 +0530 Subject: [PATCH 7/8] Sample testcase added --- tests/Resources/VerifySessionTest.php | 158 ++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 tests/Resources/VerifySessionTest.php diff --git a/tests/Resources/VerifySessionTest.php b/tests/Resources/VerifySessionTest.php new file mode 100644 index 00000000..d4845861 --- /dev/null +++ b/tests/Resources/VerifySessionTest.php @@ -0,0 +1,158 @@ +expectPlivoException('Plivo\Exceptions\PlivoValidationException'); + // $body = file_get_contents(__DIR__ . '/../Mocks/messageSendResponse.json'); + + // $this->mock(new PlivoResponse(new PlivoRequest(),200, $body)); + + // $this->client->messages->create(null, ["+919012345678"], "Test", [], null); + + // } + + // public function testMessageCreateWithSrcPowerpackException() + // { + // $this->expectPlivoException('Plivo\Exceptions\PlivoValidationException'); + // $body = file_get_contents(__DIR__ . '/../Mocks/messageSendResponse.json'); + + // $this->mock(new PlivoResponse(new PlivoRequest(),200, $body)); + + // $this->client->messages->create("+919999999999", ["+919012345678"], "Test", [], "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + + // } + + public function testVerifySessionCreate() + { + $request = new PlivoRequest( + 'POST', + 'Account/MAXXXXXXXXXXXXXXXXXX/Message/', + [ + "recipient" => "+919999999999" + ]); + $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionSendResponse.json'); + + $this->mock(new PlivoResponse($request,202, $body)); + + $actual = $this->client->verifySessions->create("+919999999999"); + + self::assertNotNull($actual); + } + + // public function testnewMessageCreate() + // { + // $request = new PlivoRequest( + // 'POST', + // 'Account/MAXXXXXXXXXXXXXXXXXX/Message/', + // [ + // "dst" => "+919012345678", + // "text" => "Test", + // "src" => "+919999999999" + // ]); + // $body = file_get_contents(__DIR__ . '/../Mocks/messageSendResponse.json'); + + // $this->mock(new PlivoResponse($request,200, $body)); + + // $actual = $this->client->messages->create([ "src" => "+919999999999", "dst" => "+919012345678", "text" =>"Test"]); + + // self::assertNotNull($actual); + // } + + // public function testMessageGet() + // { + // $messageUuid = "5b40a428-bfc7-4daf-9d06-726c558bf3b8"; + // $requesterIP = "192.168.1.1"; + // $request = new PlivoRequest( + // 'GET', + // 'Account/MAXXXXXXXXXXXXXXXXXX/Message/'.$messageUuid.'/', + // []); + // $body = file_get_contents(__DIR__ . '/../Mocks/messageGetResponse.json'); + + // $this->mock(new PlivoResponse($request,200, $body)); + + // $actual = $this->client->messages->get($messageUuid); + + // $this->assertRequest($request); + + // self::assertNotNull($actual); + + // self::assertEquals($actual->messageUuid, $messageUuid); + // self::assertEquals($actual->requesterIP, $requesterIP); + // } + + // public function testMessageGetwithPowerpack() + // { + // $messageUuid = "5b40a428-bfc7-4daf-9d06-726c558bf3b8"; + // $expected_ppk = "15c01cc2-4b9f-4d3b-bd15-3c4b38984cc4"; + // $request = new PlivoRequest( + // 'GET', + // 'Account/MAXXXXXXXXXXXXXXXXXX/Message/'.$messageUuid.'/', + // []); + // $body = file_get_contents(__DIR__ . '/../Mocks/messageGetResponse.json'); + + // $this->mock(new PlivoResponse($request,200, $body)); + + // $actual = $this->client->messages->get($messageUuid); + + // self::assertEquals($actual->powerpackID, $expected_ppk); + // } + // public function testMediaList() + // { + // $messageUuid = "5b40a428-bfc7-4daf-9d06-726c558bf3b8"; + // $request = new PlivoRequest( + // 'GET', + // 'Account/MAXXXXXXXXXXXXXXXXXX/Message/'.$messageUuid.'/', + // []); + // $body = file_get_contents(__DIR__ . '/../Mocks/messageGetResponse.json'); + + // $this->mock(new PlivoResponse($request,200, $body)); + + // $actual = $this->client->messages->get($messageUuid); + // $request = new PlivoRequest( + // 'GET', + // 'Account/MAXXXXXXXXXXXXXXXXXX/Message/'.$messageUuid.'/Media/', + // []); + // $body = file_get_contents(__DIR__ . '/../Mocks/mediaListResponse.json'); + + // $this->mock(new PlivoResponse($request,200, $body)); + + // $mediaList = $actual->listMedia(); + // self::assertNotNull($mediaList); + + // } + + // function testMessageList() + // { + // $requesterIP1 = "192.168.1.1"; + // $requesterIP2 = "192.168.1.20"; + // $request = new PlivoRequest( + // 'Get', + // 'Account/MAXXXXXXXXXXXXXXXXXX/Message/', + // []); + // $body = file_get_contents(__DIR__ . '/../Mocks/messageListResponse.json'); + + // $this->mock(new PlivoResponse($request,202, $body)); + + // $actual = $this->client->messages->list; + + // $this->assertRequest($request); + + // self::assertNotNull($actual); + // self::assertEquals($actual->resources[0]->requesterIP, $requesterIP1); + // self::assertEquals($actual->resources[19]->requesterIP, $requesterIP2); + // } + +} \ No newline at end of file From 34c98ffc2407eabacece8bd9037d34532f839179 Mon Sep 17 00:00:00 2001 From: Rajneesh Katkam Date: Thu, 3 Aug 2023 02:00:47 +0530 Subject: [PATCH 8/8] Testcases added for verify APIs --- tests/Mocks/verifySessionCreateResponse.json | 5 + tests/Mocks/verifySessionGetResponse.json | 21 ++ tests/Mocks/verifySessionListResponse.json | 165 ++++++++++++ .../Mocks/verifySessionValidateResponse.json | 4 + tests/Resources/VerifySessionTest.php | 243 +++++++++--------- 5 files changed, 319 insertions(+), 119 deletions(-) create mode 100644 tests/Mocks/verifySessionCreateResponse.json create mode 100644 tests/Mocks/verifySessionGetResponse.json create mode 100644 tests/Mocks/verifySessionListResponse.json create mode 100644 tests/Mocks/verifySessionValidateResponse.json diff --git a/tests/Mocks/verifySessionCreateResponse.json b/tests/Mocks/verifySessionCreateResponse.json new file mode 100644 index 00000000..7fd786c3 --- /dev/null +++ b/tests/Mocks/verifySessionCreateResponse.json @@ -0,0 +1,5 @@ +{ + "api_id": "c1854e14-312b-4883-8ed3-08f57961dec6", + "message": "Session initiated", + "session_uuid": "8ba0ec88-fe61-4999-9215-bac79e6be1a7" +} \ No newline at end of file diff --git a/tests/Mocks/verifySessionGetResponse.json b/tests/Mocks/verifySessionGetResponse.json new file mode 100644 index 00000000..66f57fed --- /dev/null +++ b/tests/Mocks/verifySessionGetResponse.json @@ -0,0 +1,21 @@ +{ + "api_id": "a96ac4a7-81c5-401d-b388-023b0e5a6549", + "session_uuid": "4124e518-a8c9-4feb-8cff-d86636ba9234", + "app_uuid": "eff1854e-2682-4222-a5c0-b1a16d9bb4aa", + "alias": "Test-25", + "recipient": "918097480998", + "channel": "sms", + "status": "expired", + "count": 0, + "requestor_ip": "172.167.8.2", + "destination_country_iso2": "IN", + "destination_network": "AirTel", + "attempt_details": null, + "charges": { + "total_charge": "0.00000", + "validation_charge": "0.0000", + "attempt_charges": null + }, + "created_at": "2023-06-30T12:12:03.187679+05:30", + "updated_at": "0001-01-01T05:53:28+05:53" +} \ No newline at end of file diff --git a/tests/Mocks/verifySessionListResponse.json b/tests/Mocks/verifySessionListResponse.json new file mode 100644 index 00000000..f6468baa --- /dev/null +++ b/tests/Mocks/verifySessionListResponse.json @@ -0,0 +1,165 @@ +{ + "api_id": "c6caa05a-6085-4606-b287-ec3e1bb1cf2c", + "meta": { + "limit": 20, + "offset": 0, + "next": null, + "previous": null + }, + "sessions": [ + { + "session_uuid": "8ba0ec88-fe61-4999-9215-bac79e6be1a7", + "app_uuid": "854f110a-6244-4481-9d28-dddf58c7014b", + "alias": "default_app", + "recipient": "918097480999", + "channel": "sms", + "status": "verified", + "count": 1, + "requestor_ip": "110.226.182.196", + "destination_country_iso2": "IN", + "destination_network": "AirTel", + "attempt_details": [ + { + "channel": "sms", + "attempt_uuid": "3ada0edc-849a-49f4-aae6-2de209955829", + "status": "delivered", + "time": "2023-07-28T17:20:39.278163+05:30" + } + ], + "charges": { + "total_charge": "0.13000", + "validation_charge": "0.05", + "attempt_charges": [ + { + "attempt_uuid": "3ada0edc-849a-49f4-aae6-2de209955829", + "channel": "sms", + "charge": "0.08000" + } + ] + }, + "created_at": "2023-07-28T17:20:39.263819+05:30", + "updated_at": "2023-07-28T17:20:39.278163+05:30" + }, + { + "session_uuid": "04500412-8377-454f-ab6c-52915bfb19d0", + "app_uuid": "854f110a-6244-4481-9d28-dddf58c7014b", + "alias": "default_app", + "recipient": "918097480999", + "channel": "sms", + "status": "verified", + "count": 2, + "requestor_ip": "110.226.182.196", + "destination_country_iso2": "IN", + "destination_network": "AirTel", + "attempt_details": [ + { + "channel": "voice", + "attempt_uuid": "a16eff2f-d40e-467b-9cff-cd0127417f52", + "status": "answer", + "time": "2023-07-28T17:15:00.457475+05:30" + }, + { + "channel": "sms", + "attempt_uuid": "cee2d4b7-ad1a-4bc3-8c94-3b38607366e0", + "status": "delivered", + "time": "2023-07-28T17:15:06.083284+05:30" + } + ], + "charges": { + "total_charge": "0.32300", + "validation_charge": "0.05", + "attempt_charges": [ + { + "attempt_uuid": "a16eff2f-d40e-467b-9cff-cd0127417f52", + "channel": "voice", + "charge": "0.03300" + }, + { + "attempt_uuid": "cee2d4b7-ad1a-4bc3-8c94-3b38607366e0", + "channel": "sms", + "charge": "0.24000" + } + ] + }, + "created_at": "2023-07-28T17:15:00.4336+05:30", + "updated_at": "2023-07-28T17:15:06.083284+05:30" + }, + { + "session_uuid": "b1c4807e-224d-4889-b094-dfb83f4535c9", + "app_uuid": "854f110a-6244-4481-9d28-dddf58c7014b", + "alias": "default_app", + "recipient": "918097480999", + "channel": "voice", + "status": "expired", + "count": 1, + "requestor_ip": "110.226.182.196", + "destination_country_iso2": "IN", + "destination_network": "AirTel", + "attempt_details": [ + { + "channel": "voice", + "attempt_uuid": "cee6635a-4619-41ca-9433-d0799aae917a", + "status": "answer", + "time": "2023-07-28T17:10:45.823715+05:30" + } + ], + "charges": { + "total_charge": "0.03300", + "validation_charge": "0.0000", + "attempt_charges": [ + { + "attempt_uuid": "cee6635a-4619-41ca-9433-d0799aae917a", + "channel": "voice", + "charge": "0.03300" + } + ] + }, + "created_at": "2023-07-28T17:10:45.809902+05:30", + "updated_at": "2023-07-28T17:10:45.823715+05:30" + }, + { + "session_uuid": "91b05ed6-49ea-46e2-afa3-5c475e611699", + "app_uuid": "854f110a-6244-4481-9d28-dddf58c7014b", + "alias": "default_app", + "recipient": "918097480999", + "channel": "sms", + "status": "expired", + "count": 2, + "requestor_ip": "110.226.182.196", + "destination_country_iso2": "IN", + "destination_network": "AirTel", + "attempt_details": [ + { + "channel": "sms", + "attempt_uuid": "c8f5830a-65d2-46db-9088-5001627e65a9", + "status": "delivered", + "time": "2023-07-28T17:07:02.280023+05:30" + }, + { + "channel": "sms", + "attempt_uuid": "eb0ad429-f208-467d-8616-6e541e5fb3b7", + "status": "delivered", + "time": "2023-07-28T17:09:07.870717+05:30" + } + ], + "charges": { + "total_charge": "0.48000", + "validation_charge": "0.0000", + "attempt_charges": [ + { + "attempt_uuid": "c8f5830a-65d2-46db-9088-5001627e65a9", + "channel": "sms", + "charge": "0.24000" + }, + { + "attempt_uuid": "eb0ad429-f208-467d-8616-6e541e5fb3b7", + "channel": "sms", + "charge": "0.24000" + } + ] + }, + "created_at": "2023-07-28T17:07:02.266907+05:30", + "updated_at": "2023-07-28T17:09:07.870717+05:30" + } + ] +} \ No newline at end of file diff --git a/tests/Mocks/verifySessionValidateResponse.json b/tests/Mocks/verifySessionValidateResponse.json new file mode 100644 index 00000000..ea76850d --- /dev/null +++ b/tests/Mocks/verifySessionValidateResponse.json @@ -0,0 +1,4 @@ +{ + "api_id": "522faf1e-ceba-42c4-ab33-b8c4cc443c11", + "message": "session validated successfully." +} \ No newline at end of file diff --git a/tests/Resources/VerifySessionTest.php b/tests/Resources/VerifySessionTest.php index d4845861..afbe3d04 100644 --- a/tests/Resources/VerifySessionTest.php +++ b/tests/Resources/VerifySessionTest.php @@ -13,146 +13,151 @@ */ class VerifySessionTest extends BaseTestCase { - // public function testMessageCreateWithoutSrcPowerpackException() - // { - // $this->expectPlivoException('Plivo\Exceptions\PlivoValidationException'); - // $body = file_get_contents(__DIR__ . '/../Mocks/messageSendResponse.json'); - // $this->mock(new PlivoResponse(new PlivoRequest(),200, $body)); + public function testVerifySessionCreate() + { + $request = new PlivoRequest( + 'POST', + 'Account/MAXXXXXXXXXXXXXXXXXX/Verify/Session/', + [ + "recipient" => "+919999999999" + ]); + $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionCreateResponse.json'); - // $this->client->messages->create(null, ["+919012345678"], "Test", [], null); + $this->mock(new PlivoResponse($request,202, $body)); + $actual = $this->client->verifySessions->create("+919999999999"); + self::assertNotNull($actual); + } - // } + public function testVerifySessionCreateWithRecipientException() + { + $this->expectPlivoException('Plivo\Exceptions\PlivoValidationException'); - // public function testMessageCreateWithSrcPowerpackException() - // { - // $this->expectPlivoException('Plivo\Exceptions\PlivoValidationException'); - // $body = file_get_contents(__DIR__ . '/../Mocks/messageSendResponse.json'); + $request = new PlivoRequest( + 'POST', + 'Account/MAXXXXXXXXXXXXXXXXXX/Verify/Session/', + [ + "recipient" => "+919999999999" + ]); + $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionCreateResponse.json'); - // $this->mock(new PlivoResponse(new PlivoRequest(),200, $body)); + $this->mock(new PlivoResponse($request,202, $body)); + $actual = $this->client->verifySessions->create(""); - // $this->client->messages->create("+919999999999", ["+919012345678"], "Test", [], "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + } - // } + public function testVerifySessionValidateWithSessionUUIDException() + { + $this->expectPlivoException('Plivo\Exceptions\PlivoValidationException'); - public function testVerifySessionCreate() + $sessionUuid = "5b40a428-bfc7-4daf-9d06-726c558bf3b8"; + $otp = "999999"; + $request = new PlivoRequest( + 'POST', + 'Account/MAXXXXXXXXXXXXXXXXXX/Verify/Session/'.$sessionUuid.'/', + [ + "otp" => "999999" + ]); + $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionValidateResponse.json'); + + $this->mock(new PlivoResponse($request,200, $body)); + $actual = $this->client->verifySessions->validate("", $otp); + + } + + public function testVerifySessionValidateWithOTPException() { + $this->expectPlivoException('Plivo\Exceptions\PlivoValidationException'); + + $sessionUuid = "5b40a428-bfc7-4daf-9d06-726c558bf3b8"; + $otp = "999999"; $request = new PlivoRequest( 'POST', - 'Account/MAXXXXXXXXXXXXXXXXXX/Message/', + 'Account/MAXXXXXXXXXXXXXXXXXX/Verify/Session/'.$sessionUuid.'/', [ - "recipient" => "+919999999999" + "otp" => "999999" ]); - $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionSendResponse.json'); + $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionValidateResponse.json'); - $this->mock(new PlivoResponse($request,202, $body)); + $this->mock(new PlivoResponse($request,200, $body)); + $actual = $this->client->verifySessions->validate($sessionUuid, ""); - $actual = $this->client->verifySessions->create("+919999999999"); + } + + + + public function testVerifySessionValidate() + { + $sessionUuid = "5b40a428-bfc7-4daf-9d06-726c558bf3b8"; + $otp = "999999"; + $request = new PlivoRequest( + 'POST', + 'Account/MAXXXXXXXXXXXXXXXXXX/Verify/Session/'.$sessionUuid.'/', + [ + "otp" => "999999" + ]); + $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionValidateResponse.json'); + + $this->mock(new PlivoResponse($request,200, $body)); + $actual = $this->client->verifySessions->validate($sessionUuid, $otp); self::assertNotNull($actual); + self::assertEquals($actual->message, "session validated successfully."); + } - // public function testnewMessageCreate() - // { - // $request = new PlivoRequest( - // 'POST', - // 'Account/MAXXXXXXXXXXXXXXXXXX/Message/', - // [ - // "dst" => "+919012345678", - // "text" => "Test", - // "src" => "+919999999999" - // ]); - // $body = file_get_contents(__DIR__ . '/../Mocks/messageSendResponse.json'); - - // $this->mock(new PlivoResponse($request,200, $body)); - - // $actual = $this->client->messages->create([ "src" => "+919999999999", "dst" => "+919012345678", "text" =>"Test"]); - - // self::assertNotNull($actual); - // } - - // public function testMessageGet() - // { - // $messageUuid = "5b40a428-bfc7-4daf-9d06-726c558bf3b8"; - // $requesterIP = "192.168.1.1"; - // $request = new PlivoRequest( - // 'GET', - // 'Account/MAXXXXXXXXXXXXXXXXXX/Message/'.$messageUuid.'/', - // []); - // $body = file_get_contents(__DIR__ . '/../Mocks/messageGetResponse.json'); - - // $this->mock(new PlivoResponse($request,200, $body)); - - // $actual = $this->client->messages->get($messageUuid); - - // $this->assertRequest($request); - - // self::assertNotNull($actual); - - // self::assertEquals($actual->messageUuid, $messageUuid); - // self::assertEquals($actual->requesterIP, $requesterIP); - // } - - // public function testMessageGetwithPowerpack() - // { - // $messageUuid = "5b40a428-bfc7-4daf-9d06-726c558bf3b8"; - // $expected_ppk = "15c01cc2-4b9f-4d3b-bd15-3c4b38984cc4"; - // $request = new PlivoRequest( - // 'GET', - // 'Account/MAXXXXXXXXXXXXXXXXXX/Message/'.$messageUuid.'/', - // []); - // $body = file_get_contents(__DIR__ . '/../Mocks/messageGetResponse.json'); - - // $this->mock(new PlivoResponse($request,200, $body)); - - // $actual = $this->client->messages->get($messageUuid); - - // self::assertEquals($actual->powerpackID, $expected_ppk); - // } - // public function testMediaList() - // { - // $messageUuid = "5b40a428-bfc7-4daf-9d06-726c558bf3b8"; - // $request = new PlivoRequest( - // 'GET', - // 'Account/MAXXXXXXXXXXXXXXXXXX/Message/'.$messageUuid.'/', - // []); - // $body = file_get_contents(__DIR__ . '/../Mocks/messageGetResponse.json'); - - // $this->mock(new PlivoResponse($request,200, $body)); - - // $actual = $this->client->messages->get($messageUuid); - // $request = new PlivoRequest( - // 'GET', - // 'Account/MAXXXXXXXXXXXXXXXXXX/Message/'.$messageUuid.'/Media/', - // []); - // $body = file_get_contents(__DIR__ . '/../Mocks/mediaListResponse.json'); - - // $this->mock(new PlivoResponse($request,200, $body)); - - // $mediaList = $actual->listMedia(); - // self::assertNotNull($mediaList); - - // } - - // function testMessageList() - // { - // $requesterIP1 = "192.168.1.1"; - // $requesterIP2 = "192.168.1.20"; - // $request = new PlivoRequest( - // 'Get', - // 'Account/MAXXXXXXXXXXXXXXXXXX/Message/', - // []); - // $body = file_get_contents(__DIR__ . '/../Mocks/messageListResponse.json'); - - // $this->mock(new PlivoResponse($request,202, $body)); + public function testVerifySessionGet() + { + $sessionUuid = "4124e518-a8c9-4feb-8cff-d86636ba9234"; + $requesterIP = "172.167.8.2"; + $request = new PlivoRequest( + 'GET', + 'Account/MAXXXXXXXXXXXXXXXXXX/Verify/Session/'.$sessionUuid.'/', + []); + $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionGetResponse.json'); + + $this->mock(new PlivoResponse($request,200, $body)); + + $actual = $this->client->verifySessions->get($sessionUuid); + $this->assertRequest($request); + self::assertNotNull($actual); + self::assertEquals($actual->sessionUuid, $sessionUuid); + self::assertEquals($actual->requesterIP, $requesterIP); + } + + public function testVerifySessionGetSessionUUIDException() + { + $this->expectPlivoException('Plivo\Exceptions\PlivoValidationException'); + + $sessionUuid = "4124e518-a8c9-4feb-8cff-d86636ba9234"; + $request = new PlivoRequest( + 'GET', + 'Account/MAXXXXXXXXXXXXXXXXXX/Verify/Session/'.$sessionUuid.'/', + []); + $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionGetResponse.json'); + + $this->mock(new PlivoResponse($request,200, $body)); + $this->client->verifySessions->get(""); - // $actual = $this->client->messages->list; + } + + function testVerifySessionList() + { + $requesterIP1 = "110.226.182.196"; + $requesterIP2 = "110.226.182.196"; + $request = new PlivoRequest( + 'Get', + 'Account/MAXXXXXXXXXXXXXXXXXX/Verify/Session/', + []); + $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionListResponse.json'); - // $this->assertRequest($request); + $this->mock(new PlivoResponse($request,200, $body)); - // self::assertNotNull($actual); - // self::assertEquals($actual->resources[0]->requesterIP, $requesterIP1); - // self::assertEquals($actual->resources[19]->requesterIP, $requesterIP2); - // } + $actual = $this->client->verifySessions->list(); + $this->assertRequest($request); + self::assertNotNull($actual); + self::assertEquals($actual->resources[0]->requesterIP, $requesterIP1); + self::assertEquals($actual->resources[3]->requesterIP, $requesterIP2); + } } \ No newline at end of file