Fetch Wallet Transactions

Fetch your wallet transactions by sending a HTTP GET request to the following endpoint:

Endpoints

Live:https://payments.africastalking.com/query/wallet/fetch
Sandbox:https://payments.sandbox.africastalking.com/query/wallet/fetch

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.
pageNumber
String
Required
The number of the page you'd like to read results from. Please Note: This STARTS from 1 and NOT 0
count
String
Required
The number of transaction results you would like for this query.Must be > 1 and < 1,000
startDate
String
Optional
Transaction start date you would like to consider in the format YYYY-MM-DD
endDate
String
Optional
Transaction end date you would like to consider in the format YYYY-MM-DD
categories
String
Optional
A comma delimited list of transaction categories you would like to consider. Possible values are: Debit, Credit, Refund and Topup

Fetch Wallet Transaction Response

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

Parameter Description
status
String
This corresponds to the status of the request. Possible values are:
  • Success - The request has been accepted.
  • Failed - The request has failed for some other reason; description field field will have more info in the case of an error.
responses
List
A list of response Entry corresponding to a transaction result.
Entry is a Map with details of wallet transaction being queried
  • description: String - This value contains a detailed description of this transaction, including a more detailed failure reason in the case of failures.
  • balance: String - The remaining wallet balance after the transaction was processed. The format of this string is: (3-digit Currency Code)(space)(Decimal Value) e.g KES 1.50 category: String - This contains the category of the payment. Possible values are: BankCheckout, CardCheckout, MobileCheckout, MobileC2B, MobileB2C, MobileB2B, BankTransfer, WalletTransfer, UserStashTopup
  • transactionData: Map - This contains details of the specific transaction. This is similar to the data objects on the find transaction request.
  • value: String - This string contains the value being exchanged in this transaction. The format of this string is: (3-digit Currency Code)(space)(Decimal Value) e.g KES 1.50 transactionId: String - This is a unique transactionId that we generate for every pay ment sent and received through our APIs.
{
    "status":"Success",
    "responses":[{
        "description":"MobileB2C Payment Request to +254708663158",
        "balance":"KES 47.7191",
        "date":"2018-05-12 18:46:12",
        "category":"Debit",
        "transactionData":{
            "requestMetadata":{
                "reason":"Testing things..."
            },
            "sourceType":"Wallet",
            "source":"PaymentWallet",
            "provider":"Mpesa",
            "destinationType":"PhoneNumber",
            "description":"The service request is processed successfully.",
            "providerChannel":"824879",
            "transactionFee":"KES 1.0000",
            "providerRefId":"SAMPLE_MPESA_CODE",
            "providerMetadata":{
                "recipientIsRegistered":"true",
                "recipientName":"254724XXXYYY - John Doe"
            },
            "status":"Success",
            "productName":"testing",
            "category":"MobileB2C",
            "transactionDate":"12.05.2018 21:46:13",
            "destination":"+254724XXXYYY",
            "value":"KES 2900.0000",
            "transactionId":"ATPid_b9379b671fee8ccf24b2c74f94da0ceb",
            "creationTime":"2018-05-12 18:46:12"
        },
        "value":"KES 2900.0000",
        "transactionId":"ATPid_b9379b671fee8ccf24b2c74f94da0ceb"
    }]
}

Sample fetch wallet transactions request code

The PHP code snippet below shows how to send a fetch wallet transactions request.

The code uses our PHP SDK.

<?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();

function fetchWalletTransactions() {
    // Set the pageNumber and count you'll be fetching from
    $pageNumber = 1;
    $count      = 50;

    // Set your fetch wallet transactions filters
    $filters    = [
        "pageNumber" => $pageNumber,
        "count"      => $count,
        "startDate"  => "2018-01-01",
        "endDate"    => "2018-06-25",
        "categories" => "Debit,Credit"
    ];

    try {
        // Fetch the wallet transactions
        $transactions = $payments->fetchWalletTransactions([
            "filters" => $filters
        ]);

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

fetchWalletTransactions();

The Javascript code snippet below shows how to fetch wallet transactions.

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 fetchMyWalletTransactions() {

    let options = {
        // Set the name of your Africa's Talking payment product
        productName: "TestProduct",
        filters: {
            // Set the pageNumber and count you'll be fetching from
            pageNumber: "1",
            count: "25",
            // Set your other fetch wallet transactions filters
        }
    };

    // Fetch the wallet transactions
    payments.fetchWalletTransactions(options)
        .then(resp => {
            console.log(resp.status);

            resp.responses.forEach(transaction => {
                console.log(transaction);
            });
        })
        .catch(error => {
            console.log(error);
        });
}

fetchMyWalletTransactions();

The Java code snippet below shows how to fetch wallet transactions

The code uses our Java SDK.

/* Import SDK classes */
import com.africastalking.Callback;
import com.africastalking.PaymentService;
import com.africastalking.payment.WalletTransaction;
import com.africastalking.AfricasTalking;

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

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

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

		/* Get an instance of the PaymentService */
        PaymentService payment = AfricasTalking.getService(AfricasTalking.SERVICE_PAYMENT);

        /* Filter query */
        HashMap<String, String> filters = new HashMap();

        // pageNumber start from 1 and NOT 0
        filters.put("pageNumber", "1");
        filters.put("count", "100");

        // Date format has to be YYYY-MM-DD
        filters.put("startDate", "2018-01-01");
        filters.put("endDate", "2018-12-31");

        // Possible categories are:
        //      Debit, Credit, Refund, Topup
        // A comma delimited list of transaction categories you would like to consider.
        filters.put("categories", "Debit,Credit");
        

		/* And fetch the transactions (synchronously) */
		try {
            List<WalletTransaction> transactions = payment.fetchWalletTransactions(filters);
            System.out.println("Fetched " + transactions.size() + " transactions");
			for (WalletTransaction tx : transactions) {
                System.out.print(tx.transactionId);
                System.out.print(" : ");
                System.out.println(tx.toString());
            }
		} catch(Exception ex) {
			ex.printStackTrace();
		}
   	}
}

The Python code snippet below shows how to fetch your wallet transactions.

The code uses our Python SDK.

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

import africastalking

class PAYMENTS:
    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 wallet_transactions(self):
		Set your fetch wallet transactions filters
        filters = {
            # pageNumber start from 1 and NOT 0
            "pageNumber": "1",
            "count": "100",
            # Date format has to be YYYY-MM-DD
            "startDate": "2018-01-01",
            "endDate": "2018-12-31",
            # Possible categories are: Debit, Credit, Refund, Topup
            "category": "Debit,Credit", # A comma delimited list of transaction categories you would like to consider.
        }
        try:
			Fetch the wallet transactions
            res = self.payment.wallet_transactions(filters)
            print (res)
        except Exception as e:
            print ("Received error response:%s" %str(e))

if __name__ == '__main__':
    PAYMENTS().wallet_transactions()    

The Ruby code snippet below shows how to fetch wallet transactions.

The code uses our Ruby SDK.

require 'AfricasTalking'

# Your app credentials
username = "MyApp_Username"
apikey   = "MyApp_APIKey"

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

# Get an instance of the PaymentService 
payments = AT.payments

# pageNumber start from 1 and NOT 0
pageNumber = '1'
count = 1

# Date format has to be YYYY-MM-DD
startDate = '2018-07-17'
endDate = '2018-07-23'

# A comma delimited list of transaction categories you would like to consider.
# Possible categories are:
# Debit, Credit, Refund, Topup
categories = 'Debit,Credit,Refund,Topup'

options = {
    'filters' => {
        'pageNumber' => pageNumber,
        'count' => count,
        'startDate' => startDate,
        'endDate' => endDate,
        'categories' => categories,
    }
}
# And fetch the transactions
begin
    transaction = payments.fetchWalletTransactions options
    if transaction.status === 'Success' && transaction.responses.length > 0
        transaction.responses.each {|x|
            puts x.to_yaml
            if x.transactionData.status === "Success"
                puts x.transactionData.to_yaml
            end
        }
    else
        puts 'status=' + transaction.status
    end
rescue Exception => ex
    puts "Encountered an error: " + ex.message
end