Card Checkout Validate

Below is an illustration on how the payment card checkout validate service works

CARD CHECKOUT VALIDATION

Card checkout validation APIs allow your application to validate card checkout charge requests. Initiate a card checkout validate request by making a HTTP POST request to one of the following endpoint:

Endpoints

Live:https://payments.africastalking.com/card/checkout/validate
Sandbox:https://payments.sandbox.africastalking.com/card/checkout/validate

Please note: These APIs are currently only available in Nigeria on MasterCard and Verve cards.

Request Parameters

In addition to the standard request header, the body of the request should be a JSON object containing the following fields:

Parameter Description
username
String
Required
Africa's Talking application username.
transactionId
String
Required
The id of the transaction that your application wants to validate. This value is contained in the response to a card checkout charge request.
opt
String
Required
The One Time Password that the card provider sent to the client that owns the payment card being charged.
{
  "username": "MY-APPS-USERNAME",
  "transactionId": "ATPid_SampleTxnId123",
  "otp": "1234"
}

Card Checkout Validate Response

The body of the response will be a JSON object containing the following fields:

Parameter Description
status
String
This corresponds to the final status of this request. Possible values are:
  • Success: The request has been accepted and the funds have been credited to your applications payment wallet.
  • Failed: The request failed for some other reason. The description filed will contain more information.
description
String
A detailed description of the request status.
checkoutToken
String
Optional
Contains a token that your application can use to initiate subsequent charges without having to go through the card checkout validation process.
{
    "status": "Success",
    "description": "Payment completed successfully",
    "checkoutToken": "ATCdTkn_SampleCdTknId123"
}

Initiate Card Checkout Validation Sample code

The Php code snippet below shows how to initiate a card checkout validate request.

The code uses our PHP SDK.

<?php
require 'vendor/autoload.php';
use AfricasTalking\SDK\AfricasTalking;

// Set your app credentials
$username   = "MyAppsUsername";
$apikey     = "MyAppAPIKey";

// Initialize the SDK
$AT         = new AfricasTalking($username, $apiKey);

// Get the payments service
$payments   = $AT->payments();

// Set the transactionId you got from the
// card checkout charge request
$transactionId = "someTransactionId";

// Set the OTP given to you by the user you're charging
$otp           = "1234",

try {
    // That's it, hit send and we'll take care of the rest
    $result = $payments->cardCheckoutValidate([
        "transactionId" => $transactionId,
        "otp"           => $otp
    ]);

    print_r($result);
} catch (Exception $e) {
    echo "Error: ".$e->getMessage();
}

The Ruby code snippet below shows how to initiate a checkout validation request using our API

The code uses our Ruby SDK.

require 'AfricasTalking'

# Set your app credentials
username = "MyApp_Username"
apikey   = "MyApp_APIKey"

# Initialize the SDK
AT=AfricasTalking::Initialize.new username, apikey

# Get the payments service
payments = AT.payments

# Set the transactionId you got from the card checkout charge request
transactionid = "ATPid_7444b64859882d23c9ee9621276fc7c7f"

# Set the OTP given to you by the user you're charging
otp = "1342"
options = {
    "otp"           => otp,
    "transactionId" => transactionId,
}
begin
	# That's it, hit send and we'll take care of the rest
    transaction = payments.cardCheckoutValidate options
    puts transaction.to_yaml
rescue Exception => ex
    puts "Encountered an error: " + ex.message
end

The Java code snippet below shows how to initiate a checkout validation request using our API

The code uses our Java SDK.

/* Import SDK classes */
import com.africastalking.Callback;
import com.africastalking.AfricasTalking;
import com.africastalking.PaymentService;
import com.africastalking.payment.response.CheckoutResponse;
import com.africastalking.payment.response.CheckoutValidateResponse;

import java.util.HashMap;
import java.util.List;
import java.io.IOException;

public class TestCardCheckoutValidate
{
    public static void main(String[] args)
    {
		/* Set your app credentials */
		String USERNAME = "sandbox";
		String API_KEY = "";

		/* Initialize SDK */
		AfricasTalking.initialize(USERNAME, API_KEY);

		/* Get the payments service */
		PaymentService payment = AfricasTalking.getService(AfricasTalking.SERVICE_PAYMENT);

        /* Set the transactionId you got from the card checkout charge request */
        String transactionId = "someTransacionsId";

		/* Set the OTP given to you by the user you're charging */
		String otp = "some_otp_from_user";

		/* That's it, hit send and we'll take care of the rest */
		try {
            CheckoutValidateResponse validation = payment.cardCheckoutValidate(transactionId, otp);
            System.out.println(validation.toString());
		} catch(Exception ex) {
			ex.printStackTrace();
		}
   	}
}

The Python code snippet below shows how to initiate a checkout validation request using our API

The code uses our Python SDK.

# works with both python 2 and 3
from __future__ import print_function

import africastalking

class CARD:
    def __init__(self):
		# Set your app credentials
        self.username = "YOUR_USERNAME"
        self.api_key = "YOUR_API_KEY"
		# Initialize the SDK
        africastalking.initialize(self.username, self.api_key)
		# Get the payments service
        self.payment = africastalking.Payment

    def validate(self):
        try:
			# Set the transactionId you got from the card checkout charge request
			transaction_id = "ATPid_7444b64859882d23c9ee9621276fc7c7f"
			# Set the OTP given to you by the user you're charging
			otp = "1342"
			# That's it, hit send and we'll take care of the rest
            res = self.payment.validate_card_checkout(transaction_id, otp)
            print (res)
        except Exception as e:
            print ("Received error response:%s" %str(e))

if __name__ == '__main__':
    CARD().validate()

The JavaScript code snippet below shows how to initiate a checkout validation request using our API

The code uses our Node SDK.

// Set your app credentials
const credentials = {
    apiKey: 'MyAppAPIkey',
    username: 'MyAppUsername'
}

// Initialize the SDK
const AfricasTalking = require('africastalking')(credentials);

// Get the payments service
const payments       = AfricasTalking.PAYMENTS;

function validateCheckout() {

    const options = {
        // Set the transactionId you got from the card checkout charge request
        transacitonId: 'ATCdTkn_869e7b6126f0deb4b31eebe039a2e5f2d99be',
        // Set the OTP given to you by the user you're charging
        otp: '1234'
    }

    // That's it, hit send and we'll take care of the rest
    payments.cardCheckoutValidate(options)
        .then(response => {
            console.log(response);
        }).catch(error => {
            console.log(error);
        });
}

validateCheckout();