这份文档还在翻译中,预期年底前完成。欢迎您提供宝贵的意见及建议。

Cancel verification request

If the user decides to cancel the verification process, you should send a control request to the Verify API. This will terminate the verification process even if the user supplied the correct code.

Note: You can only cancel a verification request after 30 seconds, but before any second attempt is made.

Replace the following variables in the sample code with your own values:

Key Description
VONAGE_API_KEY Your Vonage API key (see it on your dashboard).
VONAGE_API_SECRET Your Vonage API secret (also available on your dashboard).
REQUEST_ID The ID of the Verify request (this is returned in the API response when you send a verification code)

Write the code

Add the following to cancel-verification-code.sh:

curl -X GET "https://api.nexmo.com/verify/control/json?api_key=$VONAGE_API_KEY&api_secret=$VONAGE_API_SECRET&request_id=$REQUEST_ID&cmd=cancel"

View full source

Run your code

Save this file to your machine and run it:

sh cancel-verification-code.sh

Prerequisites

npm install @vonage/server-sdk

Create a file named cancel.js and add the following code:

const Vonage = require('@vonage/server-sdk');
const vonage = new Vonage({
  apiKey: VONAGE_API_KEY,
  apiSecret: VONAGE_API_SECRET
}, {
  debug: true
});

View full source

Write the code

Add the following to cancel.js:

vonage.verify.control({
  request_id: REQUEST_ID,
  cmd: 'cancel'
}, (err, result) => {
  if (err) {
    console.error(err);
  } else {
    console.log(result);
  }
});

View full source

Run your code

Save this file to your machine and run it:

node cancel.js

Prerequisites

Add the following to `build.gradle`:

compile 'com.vonage:client:5.5.0'

Create a class named CancelVerification and add the following code to the main method:

VonageClient client = VonageClient.builder().apiKey(VONAGE_API_KEY).apiSecret(VONAGE_API_SECRET).build();

View full source

Write the code

Add the following to the main method of the CancelVerification class:

client.getVerifyClient().cancelVerification(REQUEST_ID);
System.out.println("Verification cancelled.");

View full source

Run your code

We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:

  apply plugin: 'application'
  mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

Run the following gradle command to execute your application, replacing com.vonage.quickstart.verify with the package containing CancelVerification:

gradle run -Pmain=com.vonage.quickstart.verify.CancelVerification

Prerequisites

Install-Package Vonage

Create a file named CancelVerificationRequest.cs and add the following code:

using Vonage;
using Vonage.Request;
using Vonage.Verify;

View full source

Add the following to CancelVerificationRequest.cs:

var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
var client = new VonageClient(credentials);

View full source

Write the code

Add the following to CancelVerificationRequest.cs:

var request = new VerifyControlRequest() { RequestId = REQUEST_ID, Cmd = "cancel" };

var response = client.VerifyClient.VerifyControl(request);

View full source

Prerequisites

composer require vonage/client

Create a file named cancel.php and add the following code:

$basic  = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Container($basic));

View full source

Write the code

Add the following to cancel.php:

try {
    $result = $client->verify()->cancel(REQUEST_ID);
    var_dump($result->getResponseData());
}

catch(Exception $e) {
    echo 'Message: ' .$e->getMessage();
}

View full source

Run your code

Save this file to your machine and run it:

php cancel.php

Prerequisites

pip install vonage

Create a file named cancel.py and add the following code:

verify = Verify (
        Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)
    )

View full source

Write the code

Add the following to cancel.py:

response = verify.cancel(REQUEST_ID)

if response["status"] == "0":
    print("Cancellation successful")
else:
    print("Error: %s" % response["error_text"])

View full source

Run your code

Save this file to your machine and run it:

python cancel.py

Prerequisites

gem install vonage

Create a file named cancel.rb and add the following code:

client = Vonage::Client.new(
  api_key: VONAGE_API_KEY,
  api_secret: VONAGE_API_SECRET
)

View full source

Write the code

Add the following to cancel.rb:

response = client.verify.cancel(REQUEST_ID)

View full source

Run your code

Save this file to your machine and run it:

ruby cancel.rb