diff --git a/src/Plivo/Resources/Number/Number.php b/src/Plivo/Resources/Number/Number.php index 81c88794..3475ef8d 100644 --- a/src/Plivo/Resources/Number/Number.php +++ b/src/Plivo/Resources/Number/Number.php @@ -76,6 +76,7 @@ function __construct(BaseClient $client, array $response, $authId) 'tollFreeSMSVerification' => $response['toll_free_sms_verification'], 'renewalDate' => $response['renewal_date'], 'cnamLookup' => isset($response['cnam_lookup']) ? $response['cnam_lookup'] : null, + 'cnam' => isset($response['cnam']) ? $response['cnam'] : null, ]; $this->pathParams = [ 'authId' => $authId, diff --git a/src/Plivo/Resources/Number/NumberInterface.php b/src/Plivo/Resources/Number/NumberInterface.php index 6811d062..84a8ccc4 100644 --- a/src/Plivo/Resources/Number/NumberInterface.php +++ b/src/Plivo/Resources/Number/NumberInterface.php @@ -134,7 +134,10 @@ public function get($number) * + [string] app_id - The application id of the application that is to be linked. * + [string] subaccount - The auth_id of the subaccount to which this number should be added. This can only be performed by a main account holder. * + [string] cnam_lookup - The cnam lookup value for the number (Valid values : enabled, disabled). - * @return ResponseUpdate + * + [string] cnam - The cnam attached to the number + * + [string] callback_method - method ot attach the cnam + * + [string] callback_url - url to call callback_method for attching cnam + * @return NumberUpdateResponse output */ public function update($number, $optionalArgs = []) { @@ -144,11 +147,15 @@ public function update($number, $optionalArgs = []) ); $responseContents = $response->getContent(); + $newCNAM = isset($responseContents['new_cnam']) ? $responseContents['new_cnam'] : null; + $cnamUpdateStatus = isset($responseContents['cnam_update_status']) ? $responseContents['cnam_update_status'] : null; if(!array_key_exists("error",$responseContents)){ - return new ResponseUpdate( + return new NumberUpdateResponse( $responseContents['api_id'], $responseContents['message'], + $newCNAM, + $cnamUpdateStatus, $response->getStatusCode() ); } else { diff --git a/src/Plivo/Resources/Number/NumberUpdateResponse.php b/src/Plivo/Resources/Number/NumberUpdateResponse.php new file mode 100644 index 00000000..3a50d9f7 --- /dev/null +++ b/src/Plivo/Resources/Number/NumberUpdateResponse.php @@ -0,0 +1,34 @@ +newCNAM = $newCNAM; + } + if ($cnamUpdateStatus !== null){ + $this->cnamUpdateStatus = $cnamUpdateStatus; + } + } + + +} \ No newline at end of file diff --git a/src/Plivo/Resources/PhoneNumber/PhoneNumberBuyResponse.php b/src/Plivo/Resources/PhoneNumber/PhoneNumberBuyResponse.php index a58c6c24..62cfc9af 100644 --- a/src/Plivo/Resources/PhoneNumber/PhoneNumberBuyResponse.php +++ b/src/Plivo/Resources/PhoneNumber/PhoneNumberBuyResponse.php @@ -19,14 +19,22 @@ class PhoneNumberBuyResponse extends ResponseUpdate * PhoneNumberBuyResponse constructor. * @param $message * @param $number + * @param $newCNAM + * @param $cnamUpdateStatus * @param $numberStatus * @param $status */ - public function __construct($apiID, $message, $number, $numberStatus, $status, $statusCode) + public function __construct($apiID, $message, $number, $newCNAM, $cnamUpdateStatus, $numberStatus, $status, $statusCode) { parent::__construct($apiID, $message, $statusCode); $this->number = $number; + if ($newCNAM !== null){ + $this->newCNAM = $newCNAM; + } + if ($cnamUpdateStatus !== null){ + $this->cnamUpdateStatus = $cnamUpdateStatus; + } $this->numberStatus = $numberStatus; $this->status = $status; } diff --git a/src/Plivo/Resources/PhoneNumber/PhoneNumberInterface.php b/src/Plivo/Resources/PhoneNumber/PhoneNumberInterface.php index 930d70cc..15ca3cf3 100644 --- a/src/Plivo/Resources/PhoneNumber/PhoneNumberInterface.php +++ b/src/Plivo/Resources/PhoneNumber/PhoneNumberInterface.php @@ -90,21 +90,33 @@ public function getList($countryIso, $optionalArgs = []) * @param number $phoneNumber * @param string|null $appId * @param string|null $cnamLookup + * @param string|null $cnam + * @param string|null $callbackMethod + * @param string|null callbackUrl * @return PhoneNumberBuyResponse output */ - public function buy($phoneNumber, $appId = null, $cnamLookup = null) + public function buy($phoneNumber, $appId = null, $cnamLookup = null, $cnam = null, $callbackMethod = null, $callbackUrl = null) { $response = $this->client->update( $this->uri . $phoneNumber . '/', - ['app_id'=>$appId,'cnam_lookup'=>$cnamLookup] + ['app_id'=>$appId,'cnam_lookup'=>$cnamLookup, 'cnam'=>$cnam, 'callback_url' =>$callbackMethod, 'callback_method'=>$callbackMethod] ); $responseContents = $response->getContent(); + + if (array_key_exists("numbers", $responseContents)) { + $numbers = $responseContents['numbers'][0]; + $newCNAM = isset($numbers['new_cnam']) ? $numbers['new_cnam'] : null; + $cnamUpdateStatus = isset($numbers['cnam_update_status']) ? $numbers['cnam_update_status'] : null; + } + if(!array_key_exists("error",$responseContents)){ return new PhoneNumberBuyResponse( $responseContents['api_id'], $responseContents['message'], $responseContents['numbers'][0]['number'], + $newCNAM, + $cnamUpdateStatus, $responseContents['numbers'][0]['status'], $responseContents['status'], $response->getStatusCode() diff --git a/tests/Mocks/numberGetResponse.json b/tests/Mocks/numberGetResponse.json index 03d0b660..4226b8d7 100644 --- a/tests/Mocks/numberGetResponse.json +++ b/tests/Mocks/numberGetResponse.json @@ -19,6 +19,7 @@ "voice_rate": "0.00850", "mms_enabled": true, "mms_rate": "0.00750", + "cnam": "plivo", "cnam_lookup": "enabled", "compliance_application_id": "20372631212782797", "compliance_status": "submitted", diff --git a/tests/Mocks/numberListResponse.json b/tests/Mocks/numberListResponse.json index 370ded1f..d75980a6 100644 --- a/tests/Mocks/numberListResponse.json +++ b/tests/Mocks/numberListResponse.json @@ -28,6 +28,7 @@ "voice_rate": "0.00850", "mms_enabled": true, "mms_rate": "0.00950", + "cnam": "plivo", "cnam_lookup": "enabled", "compliance_application_id": "20372631212782797", "compliance_status": "submitted", @@ -56,6 +57,7 @@ "voice_rate": "0.00850", "mms_enabled": true, "mms_rate": "0.00750", + "cnam": "", "cnam_lookup": "enabled", "compliance_application_id": "20372631212782797", "compliance_status": "submitted", @@ -84,6 +86,7 @@ "voice_rate": "0.00850", "mms_enabled": true, "mms_rate": "0.00850", + "cnam": "plivo", "cnam_lookup": "disabled", "compliance_application_id": "20372631212782799", "compliance_status": "submitted",