Skip to main content

Performing a Cashout via the REST API (Java)

You can use our SDKs in various languages to perform operations with Moala:

In this tutorial, we’ll present a simple approach to integrating the MOALA SDKs to perform a cashout operation.

Prerequisites​

Before you begin, make sure you have the following:

  • An account on the MOALA portal with the required permissions to perform cashouts. You can obtain a Moala account by following the steps here: Get Access Keys
  • A development environment with Java installed
  • The SDK downloaded and integrated from: Moala Java SDK

Installation​

You can install the SDK using Maven:

<dependency>
<groupId>africa.moala</groupId>
<artifactId>sdkmoala</artifactId>
<version>1.0</version>
</dependency>

Add the SDK to your project using the command:

mvn package

1. Authentication​

Authentication with the Moala SDK is done by configuring the SDK client with your API key and secret key.

import africa.moala;

String urlApi = "https://api.moala.africa";
String appKey = "your_app_key";
String secretKey = "your_secret_key";

MoalaClient moalaClient = new MoalaClient(appKey, secretKey, urlApi);

Once configured, you can start using the SDK.

2. Perform the Cashout​

We’ll now perform a cashout operation using the MOALA SDK.

TransactionView transactionView = moalaClient.cashout("phoneNumber", "serviceCode", amount, "partnerId");
System.out.println(transactionView);
info

The allowed serviceCode values for this SDK are:

  • CASHOUT_MTN_CM: Cashout MTN Cameroon
  • CASHOUT_ORANGE_CM: Cashout Orange Cameroon
  • CASHOUT_AIRTEL_GA: Cashout Airtel Gabon
  • CASHOUT_MOOV_GA: Cashout Moov Gabon
  • PAIEMENTMARCHAND_MTN_CM: Merchant Payment MTN Cameroon
  • PAIEMENTMARCHAND_ORANGE_CM: Merchant Payment Orange Cameroon
  • PAIEMENTMARCHAND_AIRTEL_GA: Merchant Payment Airtel Gabon
  • PAIEMENTMARCHAND_MOOV_GA: Merchant Payment Moov Gabon
warning

The partnerId field must be unique for each transaction, otherwise the request will fail.

3. Check the Transaction Status​

After sending the cashout request, you can verify the success of the operation by executing another SDK method.

TransactionView transactionView = moalaClient.checkTransaction("partnerId");
System.out.println(transactionView);

4. Run the Code​

Now let’s run the code above.

We’ll attempt to perform a 500F cashout.

import africa.moala;

String urlApi = "https://api.moala.africa";
String appKey = "your_app_key";
String secretKey = "your_secret_key";

// Initialize the client
MoalaClient moalaClient = new MoalaClient(appKey, secretKey, urlApi);

// Execute the cashout
String phoneNumber = "XXXXXXXX";
String serviceCode = "CASHIN_ORANGE_CM";
Float amount = 500.0f;
String partnerId = "partnerId";
TransactionView transactionView = moalaClient.cashout(phoneNumber, serviceCode, amount, partnerId);
System.out.println(transactionView);

// Check the status of the cashout
TransactionView transactionView = moalaClient.checkTransaction(partnerId);
System.out.println(transactionView);
info

The available service codes for API calls are:

  • CASHIN_MTN_CM: Cashin MTN Cameroon
  • CASHIN_ORANGE_CM: Cashin Orange Cameroon
  • CASHIN_AIRTEL_GA: Cashin Airtel Gabon
  • PAIEMENTMARCHAND_AIRTEL_GA: Merchant Payment Airtel Gabon
  • PAIEMENTMARCHAND_ORANGE_CM: Merchant Payment Orange Cameroon
  • PAIEMENTMARCHAND_MTN_CM: Merchant Payment MTN Cameroon

5. Conclusion​

At the end of this tutorial, you now know how to integrate the MOALA APIs to perform a cashout operation.