Set webhook to confirm payment

The below steps explain how to set a payment confirmation webhook linked to your Viva Wallet account.

Step 1: Generate webhook verification key

Before you can receive a webhook notification to your website you need to create a unique verification code for Viva Wallet to identify you as a merchant. To do this, call the following API action with standard API authentication headers setting the response to application/json.

Request example

The example below uses basic auth for authentication.

curl -L -X GET 'https://demo.vivapayments.com/api/messages/config/token' \
-H 'Authorization: Basic ZDdjZDhmMGQtYjRiNy00MmE3LWI0M2QtM2Y4MzRmMDQ3OWU2OjtecmkxQA=='

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://demo.vivapayments.com/api/messages/config/token',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Authorization: Basic ZDdjZDhmMGQtYjRiNy00MmE3LWI0M2QtM2Y4MzRmMDQ3OWU2OjtecmkxQA=='
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Run in Postman

Response example

{
    "Key": "CB0567F3B4FCFC5141F72F7A5352004529941706"
}

Step 2: Create webook URL

Now create a URL in your server that listens for GET and POST requests, e.g. https://en2xr7mg8em4bwq.m.pipedream.net.

During the webhook notification process, a GET call will be made to your chosen URL. In order for the webhook to be verified, the URL should provide the following JSON response:

{
    "Key": "verification_key_value"
}

This value is static and unique per merchant, as a result it can be retrieved and stored for use later.

If required, you can restrict to visits from Viva Wallet IP addresses only; this is known as whitelisting.  

Step 3: Verify webhook URL

Once you have correctly created the URL, you need to carry out a verification process from within the Viva Wallet banking app:

  1. Log in to Viva Wallet, demo or live , and select the required account.

  2. Choose the required account (if you have more than one).

  3. Go to Settings > API Access.

  4. Click on the Webhooks tab.

  5. Click on the Create Webhook link.
    The New Webhook dialog box is displayed.

  6. Enter your webhook URL (from step 2) in the URL field.

  7. Choose Transaction Payment Created from the Event Type dropdown:

    Edit webhook

  8. Click on the Verify link and you will receive a confirmation message if your destination page has been correctly set up to generate the verification code.

  9. Select the Active checkbox to activate the webhook then click on the Save button to finalise.

In the above working example with the webhook URL generated using Pipedream , en2xr7mg8em4bwq.m.pipedream.net successfully returns a verification code when you open it in a browser.

The Node JS for that is given below and may be useful as an example of the code you can use.

if (steps.webhookEndpoint.event.method === 'POST') {
  console.dir(steps.webhookEndpoint.event.body);
  $respond({
    status: 200,
    body: { message: 'ok' }
  })
  return;
}

const axios = require("axios");

var merchantId = '[your demo Viva Wallet Merchant ID]';
var apiKey = '[your demo Viva Wallet API key]';

var credentials = Buffer.from(merchantId + ':' + apiKey).toString('base64');

const resp = await axios({
  method: "GET",
  url: `https://demo.vivapayments.com/api/messages/config/token/`,
  headers: {
    "Authorization": "Basic " + credentials,
  }
});

var code = resp.data.Key;

$respond({
  status: 200,
  headers: { "test-header": "value" },
  body: { key: code }
})
console.log('Webhook has been validated')