Phone ID - Tutorial: Perform a number deactivation check with Telesign PHP SDK

📘

NOTE:

To add Number Deactivation to your account, contact a Telesign expert. This feature is available for full-service accounts only.

This tutorial explains how to check whether a phone number was deactivated using the Phone ID Number Deactivation identity attribute with the Telesign PHP SDK. You can use the check to decide whether to send someone an SMS or Voice message. If someone's number is not active, you can save the cost of attempting to send a message. Skip to the end of this page to see the full sample code.

Before you begin

Make sure you have the following ready:

📘

NOTE:

This tutorial uses the following:

  • MacOS
  • PHP v8.4.2
  • Composer v2.8.4

Please modify accordingly if your developer environment differs from these details.

Set up your project

  1. Follow the Telesign Full-service Ruby SDK install instructions here on GitHub incorporating these details:

    • Use phoneidtest as the project directory.
    • Use project as the Package Type.
    • Use no for defining both your require and require-dev dependencies interactively.
    • Use the default directory src/ for PSR-4 autoload mapping.

    You should end up in the top-level directory for your project in the Terminal.

  2. Create a new file in the "src" directory called phone_id_deactivation_check.php and open it in your editor.

    touch phone_id_deactivation_check.php
    

Make Number Deactivation request

  1. Follow the steps below or copy the sample code into a file and update accordingly.

  2. Add a script opening tag.

    <?php
    
  3. Add the imports after the script opening tag. The telesign\enterprise\sdk\phoneid\PhoneIdClient import pulls selected functionality from the Telesign full-service SDK.

    require __DIR__ . "/../../vendor/autoload.php";
    use telesign\enterprise\sdk\phoneid\PhoneIdClient;
    

    📘

    NOTE:

    The require line may need to be modified depending on the location of "autoload.php" in your file system. By default, Composer generates this file in a "vendor" directory at the top-level of your project, as indicated by the path shown in the example above.

  4. Define variables to store your authentication credentials.

    $customer_id = getenv('CUSTOMER_ID') ? getenv('CUSTOMER_ID') :'FFFFFFFF-EEEE-DDDD-1234-AB1234567890';
    $api_key = getenv('API_KEY') ? getenv('API_KEY') :'ABC12345yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==';
    
  5. Define a variable to hold the phone number you want to perform a number deactivation check on. This should be a string with no spaces or special characters. Use the complete number, including the country code. For example: 16505551212.

    $phone_number = getenv('PHONE_NUMBER') ?? '11234567890';
    

    📘

    NOTE:

    In your production integration, pull the phone number from your recipient database instead of hardcoding it.

  6. Define a variable to hold the ucid which is the use case code that provides information about what kind of transaction you are performing.

    $ucid = "ATCK";
    
  7. Instantiate a PhoneIDClient object containing your Customer ID and API Key.

    $phoneid = new PhoneIdClient($customer_id, $api_key);
    
  8. Perform a number deactivation check, and store the results in the response variable.

    $response = $phoneid->numberDeactivation($phone_number, $ucid);
    
  9. The results stored in the response variable are provided to you in this step as shown in the sample code.

    if ($response->ok) {
      if ($response->json['number_deactivation']['last_deactivated']) {
        echo "Phone number {$response->json["number_deactivation"]["number"]}"
        . " was last deactivated {$response->json["number_deactivation"]["last_deactivated"]}.";
      }
      else {
        echo "Phone number {$response->json['number_deactivation']['number']} has not been deactivated.";
      }
    }
    
  10. Add the closing tag for the script.

?>

Test your integration

  1. Switch from your editor to the terminal and build your project. Make sure you are in the top-level directory of your project.

    php src/phone_id_deactivation_check.php
    

You should receive a response containing details about whether your phone number is active or not. You can use these results to make decisions about what to do with the phone number. For example, if someone is trying to sign up for an account with an inactive number, you might require them to sign up using a different number. Or, if you needed to send the provided number a code via text or voice message, you might opt not to send the message since it will not reach a deactivated number.

Sample code

<?php
require __DIR__ . "/../../vendor/autoload.php";
use telesign\enterprise\sdk\phoneid\PhoneIdClient;
$customer_id = getenv('CUSTOMER_ID') ? getenv('CUSTOMER_ID') :'FFFFFFFF-EEEE-DDDD-1234-AB1234567890';
$api_key = getenv('API_KEY') ? getenv('API_KEY') :'ABC12345yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==';
$phone_number = getenv('PHONE_NUMBER') ?? '11234567890';
$ucid = "ATCK";
$phoneid = new PhoneIdClient($customer_id, $api_key);
$response = $phoneid->numberDeactivation($phone_number, $ucid);
if ($response->ok) {
  if ($response->json['number_deactivation']['last_deactivated']) {
    echo "Phone number {$response->json["number_deactivation"]["number"]}"
    . " was last deactivated {$response->json["number_deactivation"]["last_deactivated"]}.";
  }
  else {
    echo "Phone number {$response->json['number_deactivation']['number']} has not been deactivated.";
  }
};

?>