diff --git a/CHANGELOG.md b/CHANGELOG.md index 51fc6814..4258c0fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## [4.59.0](https://github.com/plivo/plivo-php/tree/v4.59.0) (2023-10-31) +**Feature - TollFree Verification API Support** +- API support for Create, Update, Get, Delete and List Tollfree Verification. +- Added New Param `toll_free_sms_verification_id` and `toll_free_sms_verification_order_status `in to the response of the [list all numbers API], [list single number API] +- Added `toll_free_sms_verification_order_status` filter to AccountPhoneNumber - list all my numbers API. + ## [4.58.0](https://github.com/plivo/plivo-php/tree/v4.58.0) (2023-10-18) **Feature - Verify Caller Id API support** -API support for verifying, updating, getting and deleting caller IDs. diff --git a/src/Examples/TollfreeVerification.php b/src/Examples/TollfreeVerification.php new file mode 100644 index 00000000..d90b9ac5 --- /dev/null +++ b/src/Examples/TollfreeVerification.php @@ -0,0 +1,81 @@ +client->setTimeout(40); + + +// Get TollfreeVerification by uuid +echo "########## Get TollfreeVerification ###################\n"; +try { + $response = $client->tollfreeVerification->get( + "03420d77-4fa8-45e1-6aad-f37d41a2ee4a" + ); + + print_r($response->properties); +} +catch (PlivoRestException $ex) { + print_r($ex); +} + + +// List TollfreeVerification +echo "########## List TollfreeVerification ###################\n"; +try { + $response = $client->tollfreeVerification->getList(); + + print_r($response); +} +catch (PlivoRestException $ex) { + print_r($ex); +} + +// // Create TollfreeVerification +// echo "########## Create TollfreeVerification ###################\n"; +// try { +// $response = $client->tollfreeVerification->create( +// "18554950186", +// "2FA", +// "42f92135-6ec2-4110-8da4-71171f6aad44", +// "VERBAL", +// "100", +// "hbv", +// "message_sample", +// "http://google.com", +// "https://plivobin-prod-usw1.plivops.com/1pcfjrt1", +// "POST", +// "this is additional_information", +// "this is extra_data" +// ); +// +// print_r($response); +// } +// catch (PlivoRestException $ex) { +// print_r($ex); +// } +// +// +// // // Update TollfreeVerification by TollfreeVerification +// // echo "########## Update TollfreeVerification ###################\n"; +// // try { +// // $response = $client->tollfreeVerification->update( +// // "81fc8b2d-1ab8-47c9-7245-e454227b7b7b", +// // ["3FA"] +// // ); +// // +// // print_r($response); +// // } +// // catch (PlivoRestException $ex) { +// // print_r($ex); +// // } +// diff --git a/src/Plivo/Resources/Number/Number.php b/src/Plivo/Resources/Number/Number.php index 81c88794..817b984a 100644 --- a/src/Plivo/Resources/Number/Number.php +++ b/src/Plivo/Resources/Number/Number.php @@ -74,6 +74,8 @@ function __construct(BaseClient $client, array $response, $authId) 'tendlcCampaignId' => $response['tendlc_campaign_id'], 'tendlcRegistrationStatus' => $response['tendlc_registration_status'], 'tollFreeSMSVerification' => $response['toll_free_sms_verification'], + 'tollFreeSmsVerificationId' => $response['toll_free_sms_verification_id'], + 'tollFreeSmsVerificationOrderStatus' => $response['toll_free_sms_verification_order_status'], 'renewalDate' => $response['renewal_date'], 'cnamLookup' => isset($response['cnam_lookup']) ? $response['cnam_lookup'] : null, ]; diff --git a/src/Plivo/Resources/TollfreeVerification/TollfreeVerification.php b/src/Plivo/Resources/TollfreeVerification/TollfreeVerification.php new file mode 100644 index 00000000..4eaab6c5 --- /dev/null +++ b/src/Plivo/Resources/TollfreeVerification/TollfreeVerification.php @@ -0,0 +1,64 @@ +properties = [ + 'created' => $response['created'], + 'number' => $response['number'], + 'lastModified' => $response['last_modified'], + 'callbackMethod' => $response['callback_method'], + 'callbackUrl' => $response['callback_url'], + 'extraData' => $response['extra_data'], + 'additionalInformation' => $response['additional_information'], + 'messageSample' => $response['message_sample'], + 'optinImageUrl' => $response['optin_image_url'], + 'optinType' => $response['optin_type'], + 'profileUuid' => $response['profile_uuid'], + 'errorMessage' => $response['error_message'], + 'status' => $response['status'], + 'usecase' => $response['usecase'], + 'usecaseSummary' => $response['usecase_summary'], + 'uuid' => $response['uuid'], + 'volume' => $response['volume'], + ]; + + $this->pathParams = [ + 'authId' => $authId, + 'uuid' => $response['uuid'] + ]; + + $this->id = $response['uuid']; + } +} \ No newline at end of file diff --git a/src/Plivo/Resources/TollfreeVerification/TollfreeVerificationCreateResponse.php b/src/Plivo/Resources/TollfreeVerification/TollfreeVerificationCreateResponse.php new file mode 100644 index 00000000..f22c1b40 --- /dev/null +++ b/src/Plivo/Resources/TollfreeVerification/TollfreeVerificationCreateResponse.php @@ -0,0 +1,33 @@ +uuid = $uuid; + } +} \ No newline at end of file diff --git a/src/Plivo/Resources/TollfreeVerification/TollfreeVerificationInterface.php b/src/Plivo/Resources/TollfreeVerification/TollfreeVerificationInterface.php new file mode 100644 index 00000000..70db7eaa --- /dev/null +++ b/src/Plivo/Resources/TollfreeVerification/TollfreeVerificationInterface.php @@ -0,0 +1,246 @@ +pathParams = [ + 'authId' => $authId + ]; + $this->uri = "Account/".$authId."/TollfreeVerification/"; + } + + + /** + * This method lets you create a new TollfreeVerification entry + * @param string $number + * @param string $usecase + * @param string $profile_uuid + * @param string $optin_type + * @param string $volume + * @param string $usecase_summary + * @param string $message_sample + * @param string $optin_image_url + * @param null|string $callback_url + * @param null|string $callback_method + * @param null|string $additional_information + * @param null|string $extra_data + * @return JSON output + * @throws PlivoValidationException + */ + public function create($number, $usecase, $profile_uuid, $optin_type, $volume, $usecase_summary, $message_sample, $optin_image_url, $callback_url = null, $callback_method = null, $additional_information = null, $extra_data = null) + { + $mandatoryArgs = [ + 'number' => $number, + 'usecase' => $usecase, + 'profile_uuid' => $profile_uuid, + 'optin_type' => $optin_type, + 'volume' => $volume, + 'usecase_summary' => $usecase_summary, + 'message_sample' => $message_sample, + 'optin_image_url' => $optin_image_url, + ]; + + if (ArrayOperations::checkNull($mandatoryArgs)) { + throw new PlivoValidationException( + "Mandatory parameters cannot be null"); + } + + $response = $this->client->update( + $this->uri, + array_merge($mandatoryArgs, ['callback_url' => $callback_url, 'callback_method' => $callback_method, + 'additional_information' => $additional_information, 'extra_data' => $extra_data]) + ); + $responseContents = $response->getContent(); + if(!array_key_exists("error", $responseContents)){ + + return new TollfreeVerificationCreateResponse( + $responseContents['uuid'], + $responseContents['message'], + $responseContents['api_id'], + $response->getStatusCode() + ); + } else { + throw new PlivoResponseException( + "", + 0, + null, + $response->getContent(), + $response->getStatusCode() + ); + } + } + + /** + * This method lets you get details of a single TollfreeVerification on your account using the $uuid. + * @param $uuid + * @return TollfreeVerification + * @throws PlivoValidationException + */ + public function get($uuid) + { + if (ArrayOperations::checkNull([$uuid])) { + throw + new PlivoValidationException( + 'uuid is mandatory'); + } + $response = $this->client->fetch( + $this->uri . $uuid .'/', + [] + ); + + if(!array_key_exists("error", $response->getContent())){ + return new TollfreeVerification( + $this->client, $response->getContent(), + $this->pathParams['authId'] + ); + } else { + throw new PlivoResponseException( + $response->getContent()['error'], + 0, + null, + $response->getContent(), + $response->getStatusCode() + ); + } + } + + /** + * This method lets you get details of all TollfreeVerification numbers. + * @param array $optionalArgs + * + Valid arguments + * + [string] number - The type of number you are filtering. You can filter by tollfree numbers. + * + [string] profile_uuid - This is the uuid of the profile. + * + [string] status - This is the status of verification number. + * + [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] created__gt - Used to filter on the basis of this param. If this parameter is included in the request, all numbers greater than created date are displayed. + * + [string] created__gte - Used to filter on the basis of this param. If this parameter is included in the request, all numbers greater than equal created date are displayed. + * + [string] created__lt - Used to filter on the basis of this param. If this parameter is included in the request, all numbers less than created date are displayed. + * + [string] created__lte - Used to filter on the basis of this param. If this parameter is included in the request, all numbers less than equal created date are displayed. + * @return ResourceList + */ + public function getList($optionalArgs = []) + { +// print_r($this->uri); + $response = $this->client->fetch( + $this->uri, + $optionalArgs + ); + + if(!array_key_exists("error", $response->getContent())){ + $tollfreeVericationObj = []; + foreach ($response->getContent()['objects'] as $tollfreeVerification) { + $newTfObj = new TollfreeVerification($this->client, $tollfreeVerification, $this->pathParams['authId']); + array_push($tollfreeVericationObj, $newTfObj); + } + return new ResourceList($this->client, $response->getContent()['meta'], $tollfreeVericationObj); + } else { + throw new PlivoResponseException( + $response->getContent()['error'], + 0, + null, + $response->getContent(), + $response->getStatusCode() + ); + } + } + + /** + * Modify an TollfreeVerification + * + * @param $uuid + * @param array $optionalArgs + * + Valid arguments + * + [string] profile_uuid - The profile_uuid of your TollfreeVerification. + * + [string] usecase - The usecase of your TollfreeVerification. + * + [string] usecase_summary - The usecase summary of the TollfreeVerification. + * + [string] message_sample - The message sample of the TollfreeVerification. + * + [string] optin_image_url - The optin image url of the TollfreeVerification. + * + [string] optin_type - The optin type of the TollfreeVerification. + * + [string] volume - The volume of the TollfreeVerification. + * + [string] additional_information - The additional information of the TollfreeVerification. + * + [string] extra_data - The extra data of the TollfreeVerification. + * + [string] callback_url - The callback url of the TollfreeVerification. + * + [string] callback_method - The callback method of the TollfreeVerification. + * @return ResponseUpdate + */ + public function update($uuid, array $optionalArgs = []) + { + $response = $this->client->update( + $this->uri . $uuid . '/', + $optionalArgs + ); + + $responseContents = $response->getContent(); + + if(!array_key_exists("error",$responseContents)){ + return new ResponseUpdate( + $responseContents['api_id'], + $responseContents['message'], + $response->getStatusCode() + ); + } else { + throw new PlivoResponseException( + "", + 0, + null, + $response->getContent(), + $response->getStatusCode() + ); + } + } + + /** + * Delete an TollfreeVerification + * + * @param $uuid + * @throws PlivoValidationException + */ + public function delete($uuid) + { + if (ArrayOperations::checkNull([$uuid])) { + throw + new PlivoValidationException( + 'uuid is mandatory'); + } + $response = $this->client->delete( + $this->uri . $uuid . '/', + [] + ); + if(array_key_exists("error", $response->getContent()) && strlen($response->getContent()['error']) > 0) { + throw new PlivoResponseException( + $response->getContent()['error'], + 0, + null, + $response->getContent(), + $response->getStatusCode() + ); + } + } +} diff --git a/src/Plivo/RestClient.php b/src/Plivo/RestClient.php index df494568..9f25ca7a 100644 --- a/src/Plivo/RestClient.php +++ b/src/Plivo/RestClient.php @@ -34,6 +34,8 @@ use Plivo\Resources\Token\TokenInterface; use Plivo\Resources\Zentrunk\ZentrunkInterface; use Plivo\Resources\VerifyCallerId\VerifyInterface; +use Plivo\Resources\TollfreeVerification\TollfreeVerificationInterface; + /** * Class RestClient @@ -66,8 +68,9 @@ * @property ZentrunkInterface Zentrunk Interface to handle all Zentrunk Call related api * @property MaskingSessionInterface Masking session Interface to handle all session related api calls * @property VerifyInterface verify Interface to handle all verify caller ID related api calls - * + * @property TollfreeVerificationInterface verify Interface to handle all tollfree verification */ + class RestClient { /** @@ -201,6 +204,11 @@ class RestClient */ protected $_complianceApplication; + /** + * @var TollfreeVerificationInterface + */ + protected $_tollfreeVerification; + /** * @var HostedMessageLOAInterface */ @@ -611,4 +619,15 @@ protected function getVerifyCallerId() } return $this->_verifyCallerID; } + + /** + * @return TollfreeVerificationInterface + */ + public function getTollfreeVerification() + { + if (!$this->_tollfreeVerification) { + $this->_tollfreeVerification = new TollfreeVerificationInterface($this->client, $this->client->getAuthId()); + } + return $this->_tollfreeVerification; + } } diff --git a/src/Plivo/Version.php b/src/Plivo/Version.php index 6ad4b3e9..6762040d 100644 --- a/src/Plivo/Version.php +++ b/src/Plivo/Version.php @@ -20,12 +20,12 @@ class Version /** * @const int PHP helper library minor version number */ - const MINOR = 58; + const MINOR = 59; /** * @const int PHP helper library patch number */ - const PATCH = 1; + const PATCH = 0; /** * @return string */ diff --git a/tests/Mocks/numberGetResponse.json b/tests/Mocks/numberGetResponse.json index 03d0b660..751359fc 100644 --- a/tests/Mocks/numberGetResponse.json +++ b/tests/Mocks/numberGetResponse.json @@ -25,5 +25,7 @@ "renewal_date": "2014-03-14", "tendlc_campaign_id": "CWDPZZX", "tendlc_registration_status": "UNREGISTERED", - "toll_free_sms_verification": null + "toll_free_sms_verification": null, + "toll_free_sms_verification_id": null, + "toll_free_sms_verification_order_status": null } \ No newline at end of file diff --git a/tests/Mocks/numberListResponse.json b/tests/Mocks/numberListResponse.json index 370ded1f..b527e1fd 100644 --- a/tests/Mocks/numberListResponse.json +++ b/tests/Mocks/numberListResponse.json @@ -34,7 +34,9 @@ "renewal_date": "2014-09-05", "tendlc_campaign_id": "CWDPZZX", "tendlc_registration_status": "COMPLETED", - "toll_free_sms_verification": null + "toll_free_sms_verification": null, + "toll_free_sms_verification_id": null, + "toll_free_sms_verification_order_status": null }, { "active": true, @@ -62,7 +64,9 @@ "renewal_date": "2013-02-01", "tendlc_campaign_id": "CWDPZZX", "tendlc_registration_status": "PROCESSING", - "toll_free_sms_verification": null + "toll_free_sms_verification": null, + "toll_free_sms_verification_id": null, + "toll_free_sms_verification_order_status": null }, { "active": true, @@ -90,7 +94,9 @@ "renewal_date": "2013-04-25", "tendlc_campaign_id": null, "tendlc_registration_status": null, - "toll_free_sms_verification": "unverified" + "toll_free_sms_verification": "unverified", + "toll_free_sms_verification_id": null, + "toll_free_sms_verification_order_status": null } ] } diff --git a/tests/Mocks/tollfreeVerificationCreateResponse.json b/tests/Mocks/tollfreeVerificationCreateResponse.json new file mode 100644 index 00000000..cf963de4 --- /dev/null +++ b/tests/Mocks/tollfreeVerificationCreateResponse.json @@ -0,0 +1,5 @@ +{ + "api_id": "8540e282-7335-11ee-a39b-0242ac110004", + "message": "created", + "uuid": "7f4deae2-5d79-46ec-5088-218504abf664" +} \ No newline at end of file diff --git a/tests/Mocks/tollfreeVerificationListResponse.json b/tests/Mocks/tollfreeVerificationListResponse.json new file mode 100644 index 00000000..28ebcdd6 --- /dev/null +++ b/tests/Mocks/tollfreeVerificationListResponse.json @@ -0,0 +1,50 @@ +{ + "api_id": "e7f4a232-74ad-11ee-a860-0242ac110002", + "meta": { + "limit": 20, + "next": null, + "offset": 0, + "previous": null, + "total_count": 2 + }, + "objects": [ + { + "additional_information": "additional update1", + "callback_method": "POST", + "callback_url": "https://www.callbackurl1.com", + "created": "2023-10-25T06:28:45.168185Z", + "extra_data": "extra updated1", + "message_sample": "sample update1", + "number": "18557312530", + "optin_image_url": "https://wwww.updatedur1.com", + "optin_type": "VERBAL", + "profile_uuid": "fb239ee1-fb5c-4dd9-b55c-5cf10170e756", + "error_message": "", + "status": "SUBMITTED", + "last_modified": "2023-10-26T06:06:40.052089Z", + "usecase": "FRAUD_ALERT", + "usecase_summary": "summary up1", + "uuid": "aa5eab21-4931-468e-7502-2d8d18311fcc", + "volume": "10" + }, + { + "additional_information": "this is additional_information", + "callback_method": "POST", + "callback_url": "http://plivobin-prod-usw1.plivops.com/14ha4pv1", + "created": "2023-10-25T06:10:46.650776Z", + "extra_data": "this is extra_data", + "message_sample": "mes", + "number": "18449034555", + "optin_image_url": "https://www.aa.com,http://google.com", + "optin_type": "VERBAL", + "profile_uuid": "fb239ee1-fb5c-4dd9-b55c-5cf10170e756", + "error_message": "", + "status": "SUBMITTED", + "last_modified": "2023-10-25T07:40:34.402899Z", + "usecase": "2FA,FRAUD_ALERT,HIGHER_EDUCATION,PUBLIC_SERVICE_ANNOUNCEMENT", + "usecase_summary": "use ", + "uuid": "4e86e627-a12f-4bb6-601f-c47ec7f5e367", + "volume": "10" + } + ] +} \ No newline at end of file diff --git a/tests/Mocks/tollfreeVerificationUpdateResponse.json b/tests/Mocks/tollfreeVerificationUpdateResponse.json new file mode 100644 index 00000000..575e52a3 --- /dev/null +++ b/tests/Mocks/tollfreeVerificationUpdateResponse.json @@ -0,0 +1,4 @@ +{ + "api_id": "2c3be616-74af-11ee-a860-0242ac110002", + "message": "Tollfree verification request for uuid 81fc8b2d-1ab8-47c9-7245-e454227b7b7b updated successfully." +} \ No newline at end of file diff --git a/tests/Mocks/tollfreeverificationGetResponse.json b/tests/Mocks/tollfreeverificationGetResponse.json new file mode 100644 index 00000000..569f9a0a --- /dev/null +++ b/tests/Mocks/tollfreeverificationGetResponse.json @@ -0,0 +1,20 @@ +{ + "additional_information": "this is additional_information", + "api_id": "88c394da-74ad-11ee-a860-0242ac110002", + "callback_method": "POST", + "callback_url": "https://plivobin-prod-usw1.plivops.com/1pcfjrt1", + "created": "2023-10-25T12:53:40.598379Z", + "extra_data": "this is extra_data", + "message_sample": "message_sample", + "number": "18554950186", + "optin_image_url": "http://google.com", + "optin_type": "VERBAL", + "profile_uuid": "42f92135-6ec2-4110-8da4-71171f6aad44", + "error_message": "Number not provisioned to submitting org", + "status": "REJECTED", + "last_modified": "2023-10-25T12:53:44.56875Z", + "usecase": "2FA", + "usecase_summary": "hbv", + "uuid": "7f4deae2-5d79-46ec-5088-218504abf664", + "volume": "100" +} \ No newline at end of file diff --git a/tests/Resources/TollfreeVerificationTest.php b/tests/Resources/TollfreeVerificationTest.php new file mode 100644 index 00000000..f290a983 --- /dev/null +++ b/tests/Resources/TollfreeVerificationTest.php @@ -0,0 +1,66 @@ +mock(new PlivoResponse($request,200, $body)); + + $actual = $this->client->tollfreeVerification->getList(); + + $this->assertRequest($request); + + self::assertNotNull($actual); + + self::assertGreaterThan(0, count($actual->get())); + } + +// function testTollfreeVerificationCreate() +// { +// $request = new PlivoRequest( +// 'POST', +// 'Account/MAXXXXXXXXXXXXXXXXXX/TollfreeVerification/', +// [ +// "number"=>"18554950186", +// "usecase"=>"2FA", +// "profile_uuid"=>"42f92135-6ec2-4110-8da4-71171f6aad44", +// "optin_type"=>"VERBAL", +// "volume"=> "100", +// "usecase_summary"=>"hbv", +// "message_sample"=> "message_sample", +// "callback_url"=> "https://plivobin-prod-usw1.plivops.com/1pcfjrt1", +// "callback_method"=> "POST", +// "optin_image_url"=> "http://google.com", +// "additional_information"=> "this is additional_information", +// "extra_data"=>"this is extra_data" +// +// ]); +// $body = file_get_contents(__DIR__ . '/../Mocks/tollfreeVerificationCreateResponse.json'); +// +// $this->mock(new PlivoResponse($request,201, $body)); +// +// $actual = $this->client->tollfreeVerification->create('18554950186', '2FA', '42f92135-6ec2-4110-8da4-71171f6aad44', 'VERBAL', '100', 'hbv', 'message_sample', 'http://google.com', "https://plivobin-prod-usw1.plivops.com/1pcfjrt1", "POST", "this is additional_information", "this is extra_data"); +// +// $this->assertRequest($request); +// +// self::assertNotNull($actual); +// } + +} \ No newline at end of file