Skip to contentSkip to navigationSkip to topbar
On this page

Verify Transactions for PSD2


(information)

Info

To enable PSD2 mode on your account, contact Twilio Support(link takes you to an external page).


What is PSD2?

what-is-psd2 page anchor

PSD2 is the short name for Payment Service Directive 2(link takes you to an external page), a set of regulations introduced by the European Banking Authority(link takes you to an external page) aimed at combating the rising costs of fraud. PSD2 requires Strong Customer Authentication (SCA) for online transactions involving more than 30 Euros. To learn more about PSD2, SCA, and dynamic linking check out this post.(link takes you to an external page)


Get started with Verify for PSD2

get-started-with-verify-for-psd2 page anchor

Twilio Verify already allows you to quickly verify phone number ownership with one-time passwords (OTP) over SMS. In a few steps, you can extend these capabilities to help comply with PSD2 by verifying transactions using dynamic linking and Strong Customer Authentication (SCA).

Enable PSD2 on your account

enable-psd2-on-your-account page anchor

First, you must contact Twilio Support(link takes you to an external page) to enable PSD2 mode on your account.

Create a Service with PSD2 enabled

create-a-service-with-psd2-enabled page anchor

Next, create a new Service with PSD2 mode enabled, as shown in the code sample below.

Once enabled, requests to start and/or complete verifications require the Payee and Amount parameters.

Create a PSD2 Enabled Verify ServiceLink to code sample: Create a PSD2 Enabled Verify Service
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createService() {
11
const service = await client.verify.v2.services.create({
12
friendlyName: "My PSD2 Service",
13
psd2Enabled: true,
14
});
15
16
console.log(service.psd2Enabled);
17
}
18
19
createService();

Output

1
{
2
"sid": "VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"friendly_name": "My PSD2 Service",
5
"code_length": 4,
6
"lookup_enabled": false,
7
"psd2_enabled": true,
8
"skip_sms_to_landlines": false,
9
"dtmf_input_required": false,
10
"tts_name": "name",
11
"mailer_sid": "MDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
12
"do_not_share_warning_enabled": false,
13
"custom_code_enabled": true,
14
"push": {
15
"include_date": false,
16
"apn_credential_sid": "CRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
17
"fcm_credential_sid": null
18
},
19
"totp": {
20
"issuer": "test-issuer",
21
"time_step": 30,
22
"code_length": 3,
23
"skew": 2
24
},
25
"whatsapp": {
26
"msg_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
27
"from": "whatsapp:+1234567890"
28
},
29
"default_template_sid": "HJaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
30
"verify_event_subscription_enabled": false,
31
"date_created": "2015-07-30T20:00:00Z",
32
"date_updated": "2015-07-30T20:00:00Z",
33
"url": "https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
34
"links": {
35
"verification_checks": "https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/VerificationCheck",
36
"verifications": "https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Verifications",
37
"rate_limits": "https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/RateLimits",
38
"messaging_configurations": "https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/MessagingConfigurations",
39
"entities": "https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Entities",
40
"webhooks": "https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks",
41
"access_tokens": "https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/AccessTokens"
42
}
43
}

Start a transaction verification

start-a-transaction-verification page anchor

To start a transaction verification, send an HTTP POST request to your PSD2-enabled Service's Verifications resource. This request must contain the Amount, Payee, To, and Channel parameters.

This HTTP request causes Twilio to send a verification code to the user. Each verification code is dynamically-linked to the Amount and Payee of each transaction. The code is unique to the To (e.g., the recipient's phone number), Amount, and Payee combination. This ensures that verification fails in the event of code interception or transaction mutations.

Each verification code is valid for 10 minutes. Within that ten-minute time frame, any subsequent HTTP POST requests to the Verifications resource for the transaction cause Twilio send the same verification code.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createVerification() {
11
const verification = await client.verify.v2
12
.services("VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.verifications.create({
14
amount: "€39.99",
15
channel: "sms",
16
payee: "Acme Inc.",
17
to: "+15017122661",
18
});
19
20
console.log(verification.sid);
21
}
22
23
createVerification();

Output

1
{
2
"sid": "VEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"service_sid": "VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5
"to": "+15017122661",
6
"channel": "sms",
7
"status": "pending",
8
"valid": false,
9
"date_created": "2015-07-30T20:00:00Z",
10
"date_updated": "2015-07-30T20:00:00Z",
11
"lookup": {},
12
"amount": "€39.99",
13
"payee": "Acme Inc.",
14
"send_code_attempts": [
15
{
16
"time": "2015-07-30T20:00:00Z",
17
"channel": "SMS",
18
"attempt_sid": "VLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
19
}
20
],
21
"sna": null,
22
"url": "https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Verifications/VEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
23
}
(information)

Info

For some regions, Twilio is unable to return carrier and cellphone data by default. To enable these regions, contact Twilio Support(link takes you to an external page).

More information can be found in the Help Center(link takes you to an external page).

Complete a transaction verification

complete-a-transaction-verification page anchor

To check if a verification code is correct, send an HTTP POST request to your PSD2-enabled Service's Verification Check resource. This request must contain the Code, To (e.g., the user's phone number), Amount, and Payee parameters. A sample request is shown in the example below.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createVerificationCheck() {
11
const verificationCheck = await client.verify.v2
12
.services("VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.verificationChecks.create({
14
amount: "€39.99",
15
code: "1234",
16
payee: "Acme Inc.",
17
to: "+15017122661",
18
});
19
20
console.log(verificationCheck.status);
21
}
22
23
createVerificationCheck();

Output

1
{
2
"sid": "VEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"service_sid": "VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5
"to": "+15017122661",
6
"channel": "sms",
7
"status": "approved",
8
"valid": true,
9
"amount": "€39.99",
10
"payee": "Acme Inc.",
11
"sna_attempts_error_codes": [],
12
"date_created": "2015-07-30T20:00:00Z",
13
"date_updated": "2015-07-30T20:00:00Z"
14
}

Cancel a transaction verification

cancel-a-transaction-verification page anchor

In some instances, the details of a transaction may change before it can be completed. When that occurs, you can cancel an in-progress transaction verification by updating the Status of the Verification resource. An example of this request is shown below.

This prevents a user from verifying an out-of-date transaction.

That transactions that have been successfully verified cannot be canceled.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function updateVerification() {
11
const verification = await client.verify.v2
12
.services("VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.verifications("VEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
14
.update({ status: "canceled" });
15
16
console.log(verification.sid);
17
}
18
19
updateVerification();

Output

1
{
2
"sid": "VEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"service_sid": "VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5
"to": "+15017122661",
6
"channel": "sms",
7
"status": "canceled",
8
"valid": false,
9
"date_created": "2015-07-30T20:00:00Z",
10
"date_updated": "2015-07-30T20:00:00Z",
11
"lookup": {},
12
"amount": null,
13
"payee": null,
14
"send_code_attempts": [
15
{
16
"time": "2015-07-30T20:00:00Z",
17
"channel": "SMS",
18
"attempt_sid": "VLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
19
}
20
],
21
"sna": null,
22
"url": "https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Verifications/VEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
23
}

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.