Class NumberVerificationClient

java.lang.Object
com.vonage.client.camara.NetworkApiClient
com.vonage.client.camara.numberverification.NumberVerificationClient

A client for communicating with the Vonage Number Verification API. The standard way to obtain an instance of this class is to use VonageClient.getNumberVerificationClient().
  • Constructor Details

    • NumberVerificationClient

      Create a new NumberVerificationClient.
      Parameters:
      wrapper - Http Wrapper used to create requests.
  • Method Details

    • initiateVerification

      public URI initiateVerification(String phoneNumber, URI redirectUrl, String state)
      Sets up the client for verifying the given phone number. This method will cache the provided number and redirect URL for verification when calling verifyNumber(String). The intended usage is to call this method first, and follow the returned URL on the target device which the phone number is supposed to be associated with. When the URL is followed, it will trigger an inbound request to the redirectUrl with two query parameters: CODE and STATE (if provided as a parameter to this method). The code should then be extracted from the query parameters and passed to verifyNumber(String).
      Parameters:
      phoneNumber - The MSISDN to verify.
      redirectUrl - Redirect URL, as set in your Vonage application for Network APIs.
      state - An optional string for identifying the request. For simplicity, this could be set to the same value as phoneNumber, or it may be null.
      Returns:
      A link with appropriate parameters which should be followed on the end user's device. The link should be followed when using the SIM card associated the provided phone number. Therefore, on the target device, Wi-Fi should be disabled when doing this, otherwise the result of verifyNumber(String) will be false.
    • verifyNumber

      public boolean verifyNumber(String code)
      Exchanges the code for an access token, makes the API call to the Number Verification API's "verify" endpoint and extracts the result.
      Parameters:
      code - The code obtained from the inbound callback's query parameters.
      Returns:
      true if the device that followed the link was using the SIM card associated with the phone number provided in initiateVerification(String, URI, String), false otherwise (e.g. it was unknown, the link was not followed, the device that followed the link didn't use the SIM card with that phone number when doing so).
      Throws:
      NetworkAuthResponseException - If there was an error exchanging the code for an access token when using the Vonage Network Auth API.
      CamaraResponseException - If there was an error in communicating with the Number Verification API.
    • verifyNumber

      public boolean verifyNumber(String phoneNumber, URI redirectUri, String code)
      Stateless implementation of verifyNumber(String), which creates a new request without having to call initiateVerification(String, URI, String) first. This is useful in cases where concurrent verifications are required, or the URL is obtained another way.
      Parameters:
      phoneNumber - MSISDN of the target device to verify.
      redirectUri - Redirect URL, as set in your Vonage application for Network APIs.
      code - The code obtained from the inbound callback's query parameters.
      Returns:
      true if the device that followed the link was using the SIM card associated with the phone number provided in initiateVerification(String, URI, String), false otherwise (e.g. it was unknown, the link was not followed, the device that followed the link didn't use the SIM card with that phone number when doing so).
      Throws:
      NetworkAuthResponseException - If there was an error exchanging the code for an access token when using the Vonage Network Auth API.
      CamaraResponseException - If there was an error in communicating with the Number Verification API.