Validate Card Checkout

Payment Card Checkout Validation APIs allow your application to validate card charge requests that deduct money from a customer's Debit or Credit Card. These APIs are currently only available in Nigeria on MasterCard and Verve cards.

Jump to:


How do I initiate an OTP Validation request? [ Go Top]

You can initiate an OTP Validation request by sending a HTTP POST request to: https://payments.africastalking.com/card/checkout/validate.

The following headers will be required for all requests

Header Description
apikey
String
Required
This is your Africa's Talking API Key

The body of the request should be a JSON object containing the following fields:

Field Description Sample Request
username
String
Required
This is your Africa's Talking username

{
"username": "MyUsername"
"transactionId": "ATPid_SampleTxnId1",
"otp": "1234"
}
transactionId
String
Required
This value identifies the transaction that your application wants to validate. This value is contained in the response to the charge request.
otp
String
Required
This contains the One Time Password that the card issuer sent to the client that owns the payment card

How does the API respond to a validation request? [Go Top]

The API responds to a validation request with a JSON response containing the fields shown below.

Field Description Sample Response
status
String
Mandatory
This corresponds to the FINAL status of this request. Possible values are:
  • Success: This means that the request has been accepted and the funds have been credited to your Payment Wallet.
  • Failed: Thie means that the checkout request has failed for some other reason. The description field will have more details on the reason.

{
"status": "Success",
"description": "Payment completed successfully"
}
description
String
Mandatory
This provides a detailed description of the request status
checkoutToken
String
Optional
This contains a checkout token that your application can use to initiate subsequent charges without having to go through the OTP validation process.


Sample OTP Validation code [Go Top

You need your AfricasTalking username and APIKey for any request to our API. If you don't have an APIKey, please click here to get one.
For sandbox APIKey, click here

Card Checkout Validation in PHP

The PHP code snippet below shows how to initiate a Card Checkout Validation request using our API

The code uses our PHP gateway class: AfricasTalkingGateway.php [ Download]

Also, please ensure that you have the php_curl module enabled. To enable it uncomment the line: ;extension=php_curl.dll in php.ini and restart apache

<?php
require_once "AfricasTalkingGateway.php";

//Specify your credentials
$username = "MyAfricasTalkingUsername";
$apiKey   = "MyAfricasTalkingApiKey";

//Create an instance of our awesome gateway class and pass your credentials
$gateway = new AfricasTalkingGateway($username, $apiKey);

/*************************************************************************************
 NOTE: If connecting to the sandbox:

 1. Use "sandbox" as the username
 2. Use the apiKey generated from your sandbox application
	https://account.africastalking.com/apps/sandbox/settings/key
 3. Add the "sandbox" flag to the constructor

$gateway  = new AfricasTalkingGateway($username, $apiKey, "sandbox");
**************************************************************************************/

// Provide the transactionId that was returned by the charge request
$transactionId = "ATPid_e092c250f2bd1bcd6938b05633ba1c13";
// Provide the OTP that the bank sent to the owner of the bank account
$otp           = "1234";

try {
  // Initiate the checkout. If successful, you will get back a checkoutToken
  $checkoutToken = $gateway->cardPaymentCheckoutValidation($transactionId,
			                       		   $otp);
  echo "The checkout token for future transactions is ".$checkoutToken;
}
catch(AfricasTalkingGatewayException $e){
  echo "Received error response: ".$e->getMessage();
}

    

Card Checkout Validation in Python

The python code snippet below shows how to send a card payment checkout request using our API

The code uses our Python gateway class: AfricasTalkingGateway.py [ Download]

# Import the helper gateway class
from AfricasTalkingGateway import AfricasTalkingGateway, AfricasTalkingGatewayException

#Specify your credentials
username = "MyAfricasTalkingUsername"
apiKey   = "MyAfricasTalkingApiKey"

#Create an instance of our awesome gateway class and pass your credentials
gateway = AfricasTalkingGateway(username, apiKey)

#*************************************************************************************
#  NOTE: If connecting to the sandbox:
#
#  1. Use "sandbox" as the username
#  2. Use the apiKey generated from your sandbox application
#     https://account.africastalking.com/apps/sandbox/settings/key
#  3. Add the "sandbox" flag to the constructor
#
#  gateway = AfricasTalkingGateway(username, apiKey);
#**************************************************************************************

try:
    checkoutToken = gateway.cardPaymentCheckoutValidation(
        transactionId_ = "ATPid_d33b9f02741397e25b3c5f1e81e23a5b",
        otp_           = "1234"
        )
    print "The checkoutToken is %s" % checkoutToken

except AfricasTalkingGatewayException, e:
    print 'Encountered an error while sending: %s' % str(e)