Send payment authentication code
Verify API supports Strong Customer Authentication for payments. To begin the process, supply the customer's telephone number (in E.164 format ), the payee that will receive the payment, and the amount (in Euro) of the transaction, to the PSD2 endpoint.
The Verify API returns a request_id
. Use this to identify a specific verification request in subsequent calls to the API, such as when making a check request to see if the user provided the correct code.
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). |
RECIPIENT_NUMBER |
The phone number to verify |
PAYEE |
Included in the message to describe the payment recipient |
AMOUNT |
How much the payment is for (always in Euro) |
Write the code
Add the following to send-psd2-code.sh
:
curl -X POST "https://api.nexmo.com/verify/psd2/json" -d api_key=$VONAGE_API_KEY -d api_secret=$VONAGE_API_SECRET -d number=$RECIPIENT_NUMBER -d payee="$PAYEE" -d amount=$AMOUNT
Run your code
Save this file to your machine and run it:
sh send-psd2-code.sh
Prerequisites
npm install @vonage/server-sdk
Create a file named psd2.js
and add the following code:
const Vonage = require('@vonage/server-sdk');
const vonage = new Vonage({
apiKey: VONAGE_API_KEY,
apiSecret: VONAGE_API_SECRET
});
Write the code
Add the following to psd2.js
:
vonage.verify.psd2({
number: RECIPIENT_NUMBER,
payee: PAYEE,
amount: AMOUNT
}, (err, result) => {
if (err) {
console.error(err);
} else {
const verifyRequestId = result.request_id;
console.log('request_id', verifyRequestId);
}
});
Run your code
Save this file to your machine and run it:
node psd2.js
Prerequisites
Add the following to `build.gradle`:
compile 'com.vonage:client:6.2.0'
Create a class named StartPsd2Verification
and add the following code to the main
method:
VonageClient client = VonageClient.builder().apiKey(VONAGE_API_KEY).apiSecret(VONAGE_API_SECRET).build();
Write the code
Add the following to the main
method of the StartPsd2Verification
class:
VerifyResponse response = client.getVerifyClient().psd2Verify(RECIPIENT_NUMBER, AMOUNT, PAYEE_NAME);
if (response.getStatus() == VerifyStatus.OK) {
System.out.printf("Request ID: %s", response.getRequestId());
} else {
System.out.printf("Error: %s: %s", response.getStatus(), response.getErrorText());
}
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 StartPsd2Verification
:
gradle run -Pmain=com.vonage.quickstart.verify.StartPsd2Verification
Prerequisites
Install-Package Vonage
Create a file named SendPsd2.cs
and add the following code:
using Vonage;
using Vonage.Request;
using Vonage.Verify;
Add the following to SendPsd2.cs
:
var creds = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
var client = new VonageClient(creds);
Write the code
Add the following to SendPsd2.cs
:
var request = new Psd2Request { Amount = AMOUNT, Payee = PAYEE_NAME, Number = RECIPIENT_NUMBER };
var response = client.VerifyClient.VerifyRequestWithPSD2(request);
Prerequisites
composer require vonage/client
Create a file named send_psd2_request.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));
Write the code
Add the following to send_psd2_request.php
:
$request = new \Vonage\Verify\RequestPSD2(RECIPIENT_NUMBER, PAYEE_NAME, AMOUNT);
$response = $client->verify()->requestPSD2($request);
echo "Started verification, `request_id` is " . $response['request_id'];
Run your code
Save this file to your machine and run it:
php send_psd2_request.php
Prerequisites
pip install vonage python-dotenv
Create a file named psd2_request.py
and add the following code:
import os
from os.path import join, dirname
from dotenv import load_dotenv
from vonage import Client, Verify
Add the following to psd2_request.py
:
client = Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)
verify = Verify(client)
Write the code
Add the following to psd2_request.py
:
response = verify.psd2(number=RECIPIENT_NUMBER, payee=PAYEE, amount=AMOUNT)
if response["status"] == "0":
print("Started PSD2 verification request_id is %s" % (response["request_id"]))
else:
print("Error: %s" % response["error_text"])
Run your code
Save this file to your machine and run it:
python psd2_request.py
Prerequisites
gem install vonage
Create a file named send_psd2_code.rb
and add the following code:
client = Vonage::Client.new(
api_key: VONAGE_API_KEY,
api_secret: VONAGE_API_SECRET
)
Write the code
Add the following to send_psd2_code.rb
:
response = client.verify.psd2(
number: TO_NUMBER,
payee: 'AcmeInc',
amount: 12.34
)
if response
# display the Verify PSD2 `request_id`
puts response.request_id
end
Run your code
Save this file to your machine and run it:
ruby send_psd2_code.rb