Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cnam-storage sdk changes #324

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Plivo/Resources/Number/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions src/Plivo/Resources/Number/NumberInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
{
Expand All @@ -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 {
Expand Down
34 changes: 34 additions & 0 deletions src/Plivo/Resources/Number/NumberUpdateResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Plivo\Resources\Number;


use Plivo\Resources\ResponseUpdate;

/**
* Class NumberUpdateResponse
* @package Plivo\Resources\Number
*/
class NumberUpdateResponse extends ResponseUpdate
{

/**
* NumberUpdateResponse constructor.
* @param $message
* @param $newCNAM
* @param $cnamUpdateStatus
*/
public function __construct($apiId, $message, $newCNAM, $cnamUpdateStatus, $statusCode = 200)
{
parent::__construct($apiId, $message, $statusCode);

if ($newCNAM !== null){
$this->newCNAM = $newCNAM;
}
if ($cnamUpdateStatus !== null){
$this->cnamUpdateStatus = $cnamUpdateStatus;
}
}


}
10 changes: 9 additions & 1 deletion src/Plivo/Resources/PhoneNumber/PhoneNumberBuyResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 14 additions & 2 deletions src/Plivo/Resources/PhoneNumber/PhoneNumberInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions tests/Mocks/numberGetResponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions tests/Mocks/numberListResponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down