Verify the status of a transaction

It is crucial to verify that every payment made is successful with Bank3D before giving value to a customer on your website.

Though Bank3D Inline verifies from the client-side, it is strongly recommended that a server-side verification is done, to eliminate all criminal activity during the the payment flow.

Below are vital points to look out for when validating transaction:

  • Acertain that the transaction reference has already been given a value.
  • Verify the transaction via our API.
  • Verify the code of the transaction to be 00
  • Verify the currencyCode to be the expected currency.
  • Validate the amount paid to be equal to or at least greater than the amount of the value to be given.

Code snippets that shows you how to verify transactions. Copy and add to your page

var http = require('http');
var axios = require('axios');

var hostname = "127.0.0.1";
var port = 8080;
//Replace with your bank3d merchant credentials
var bank3d_username = 'xxxxxxxxxxxxxxxxxx';
var bank3d_password = 'xxxxxxxxxxxxxxxxxx';
var reference = 'THE_PAYMENT_REFERENCE_THAT_NEEDS_VERIFICATION';
//node server creation
var nodeServ = http.createServer(function(req, res) {

  res.statusCode = 200;
  // Setup axios
  // Ref: https://www.npmjs.com/package/axios
  axios({
    method: 'post',
    url: 'https://paywithbank3d.com/api/payment/verify/'+reference,
    auth: {
      username:bank3d_username,
      password:bank3d_password
    }
  }).then(function(resolve) {
    // If we got here, it was successful
    // Payment information such as status, amount, etc can be found inside [resolve.data]
    console.log(resolve.data);
    res.end('OK');
  }).catch(function(reason) {
    // If we got here, then it failed
    // Exception handling logic
    console.log(reason.data);
    res.end('FAIL');
  });
});

nodeServ.listen(port, hostname, function() {
  console.log("Listening on " + hostname + ":" + port);
});
// Replace with you bank3d merchant credentials
$bank3d_username = 'xxxxxxxxxxxxxxxxxxxxxxx';
$bank3d_password = 'xxxxxxxxxxxxxxxxxxxxxxx';
$reference = 'THE_PAYMENT_REFERENCE_THAT_NEEDS_VERIFICATION';

// Setup http client (GuzzleHttp\Client)
// Ref: http://docs.guzzlephp.org/en/stable/
$client = new Client([
  'base_uri' => 'https://paywithbank3d.com/api',
  'auth' => [ $bank3d_username, $bank3d_password]
]);
try {
  $response_object = $client->request('GET', sprintf('payment/verify/%s', $reference));
  $responseData = json_decode($response_object->getBody(), true);
  // If we got here, it was successful
  // Payment information such as status, amount, etc can be found inside [$responseData]
  var_dump($responseData);
} catch (GuzzleHttp\Exception\GuzzleException $exception) {
  // Handle exception
  if ($exception instanceof GuzzleHttp\Exception\BadResponseException && $exception->hasResponse()) {
  $response = $exception->getResponse();
  $status_code = $response->getStatusCode();
  $data = json_decode($response->getBody(), true);
  // Request failed with [status_code = $status_code] and returned [data = $data]
}
// Confirm if the transaction with the specified reference was successful
public async void VerifyTransaction(string reference)
{
  var username = "USERNAME"; //replace username with your merchant uniqueId
  var password = "PASSWORD"; //replace password with your merchant secret key

  var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}"));
  using (var client = new HttpClient())
  {
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials);
    var responseMessage = await client.GetAsync($"https://paywithbank3d.com/api/payment/verify/{reference}");
    if (responseMessage.StatusCode == HttpStatusCode.OK)
    {
      var responseStr = await responseMessage.Content.ReadAsStringAsync();
      var response = JsonConvert.DeserializeObject<ResponseData>(responseStr);
      if (response.Code == "00")
      {
        //transaction successful
        //give value
      }
      else
      {
        //transaction failed
      }
    }
  }
}
Language
Credentials
Header
Click Try It! to start a request and see the response here!