Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/theresasogunle/Fintech-flutterwave-Java-Library/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The AccountCharge class enables direct bank account charging in the Flutterwave Rave Java Library. It supports charging Nigerian bank accounts directly, with OTP validation for secure transactions.

Constructor

AccountCharge accountCharge = new AccountCharge();
The AccountCharge class uses a default constructor. Configure the payment by chaining setter methods to build your charge request.

Setter Methods

All setter methods return the AccountCharge instance, enabling method chaining for fluent API usage.

Account Information

setAccountnumber
AccountCharge
public AccountCharge setAccountnumber(String accountnumber)
Sets the customer’s bank account number.Parameters:
  • accountnumber (String): The bank account number to charge
Returns: AccountCharge instance for method chainingExample:
accountCharge.setAccountnumber("0690000031");
setAccountbank
AccountCharge
public AccountCharge setAccountbank(String accountbank)
Sets the bank code for the account.Parameters:
  • accountbank (String): The bank code (e.g., “044” for Access Bank)
Returns: AccountCharge instance for method chainingExample:
accountCharge.setAccountbank("044");
setPasscode
AccountCharge
public AccountCharge setPasscode(String passcode)
Sets the account passcode for authentication.Parameters:
  • passcode (String): Account authentication passcode
Returns: AccountCharge instance for method chainingExample:
accountCharge.setPasscode("09101989");

Transaction Details

setAmount
AccountCharge
public AccountCharge setAmount(String amount)
Sets the transaction amount.Parameters:
  • amount (String): The charge amount
Returns: AccountCharge instance for method chainingExample:
accountCharge.setAmount("100");
setCurrency
AccountCharge
public AccountCharge setCurrency(String currency)
Sets the transaction currency.Parameters:
  • currency (String): Three-letter currency code (e.g., “NGN”)
Returns: AccountCharge instance for method chainingExample:
accountCharge.setCurrency("NGN");
setCountry
AccountCharge
public AccountCharge setCountry(String country)
Sets the country code for the transaction.Parameters:
  • country (String): Two-letter country code (e.g., “NG”)
Returns: AccountCharge instance for method chainingExample:
accountCharge.setCountry("NG");
setTxRef
AccountCharge
public AccountCharge setTxRef(String txRef)
Sets your unique transaction reference.Parameters:
  • txRef (String): Unique transaction reference for tracking
Returns: AccountCharge instance for method chainingExample:
accountCharge.setTxRef("ACC-" + System.currentTimeMillis());

Customer Information

setEmail
AccountCharge
public AccountCharge setEmail(String email)
Sets the customer’s email address.Parameters:
  • email (String): Customer email address
Returns: AccountCharge instance for method chainingExample:
accountCharge.setEmail("customer@example.com");
setFirstname
AccountCharge
public AccountCharge setFirstname(String firstname)
Sets the customer’s first name.Parameters:
  • firstname (String): Customer first name
Returns: AccountCharge instance for method chainingExample:
accountCharge.setFirstname("John");
setLastname
AccountCharge
public AccountCharge setLastname(String lastname)
Sets the customer’s last name.Parameters:
  • lastname (String): Customer last name
Returns: AccountCharge instance for method chainingExample:
accountCharge.setLastname("Doe");
setPhonenumber
AccountCharge
public AccountCharge setPhonenumber(String phonenumber)
Sets the customer’s phone number.Parameters:
  • phonenumber (String): Customer phone number
Returns: AccountCharge instance for method chainingExample:
accountCharge.setPhonenumber("+2348012345678");

Security & Tracking

setIP
AccountCharge
public AccountCharge setIP(String IP)
Sets the customer’s IP address for fraud prevention.Parameters:
  • IP (String): Customer IP address
Returns: AccountCharge instance for method chainingExample:
accountCharge.setIP("103.238.105.185");
setDevice_fingerprint
AccountCharge
public AccountCharge setDevice_fingerprint(String device_fingerprint)
Sets the device fingerprint for enhanced security.Parameters:
  • device_fingerprint (String): Unique device identifier
Returns: AccountCharge instance for method chainingExample:
accountCharge.setDevice_fingerprint("69e6b7f0b72037aa8428b70fbe03986c");

Validation Parameters

setTransaction_reference
AccountCharge
public AccountCharge setTransaction_reference(String transaction_reference)
Sets the Flutterwave transaction reference for validation.Parameters:
  • transaction_reference (String): The flwRef returned from charge response
Returns: AccountCharge instance for method chainingExample:
accountCharge.setTransaction_reference("FLW-MOCK-0987654321");
setOtp
AccountCharge
public AccountCharge setOtp(String otp)
Sets the OTP for transaction validation.Parameters:
  • otp (String): One-time password sent to customer
Returns: AccountCharge instance for method chainingExample:
accountCharge.setOtp("12345");

Charge Methods

chargeAccount()

public JSONObject chargeAccount()
Charges a Nigerian bank account directly. The payment type is automatically set to “account”.
Return Value
JSONObject
Returns a JSON response containing the charge status and validation requirements.Required Fields:
  • Account number and bank code
  • Amount, currency, country
  • Email, firstname, lastname
  • Transaction reference
  • Passcode
  • IP address
  • Device fingerprint
Example:
AccountCharge accountCharge = new AccountCharge();

JSONObject response = accountCharge
    .setAccountnumber("0690000031")
    .setAccountbank("044")
    .setAmount("100")
    .setCurrency("NGN")
    .setCountry("NG")
    .setEmail("customer@example.com")
    .setFirstname("John")
    .setLastname("Doe")
    .setPasscode("09101989")
    .setTxRef("ACC-" + System.currentTimeMillis())
    .setIP("103.238.105.185")
    .setDevice_fingerprint("69e6b7f0b72037aa8428b70fbe03986c")
    .chargeAccount();

System.out.println(response.toString());

chargeAccount(boolean polling)

public JSONObject chargeAccount(boolean polling)
Charges a bank account with timeout handling via polling.
polling
boolean
Enable polling for timeout scenarios
Return Value
JSONObject
Returns a JSON response with charge status, handling network timeouts gracefully.
Example:
JSONObject response = accountCharge
    .setAccountnumber("0690000031")
    .setAccountbank("044")
    // ... other fields ...
    .chargeAccount(true);

System.out.println(response.toString());

Validation Methods

validateAccountCharge()

public JSONObject validateAccountCharge()
Validates an account charge using OTP sent to the customer.
Return Value
JSONObject
Returns validation result indicating success or failure.Required Fields Before Calling:
  • Transaction reference (flwRef from charge response)
  • OTP (from customer)
Example:
// After initial charge
JSONObject chargeResponse = accountCharge.chargeAccount();
String flwRef = chargeResponse.getJSONObject("data").getString("flwRef");

// Customer receives OTP and provides it
String otp = "12345"; // from customer input

// Validate the charge
JSONObject validationResponse = accountCharge
    .setTransaction_reference(flwRef)
    .setOtp(otp)
    .validateAccountCharge();

System.out.println(validationResponse.toString());

validateAccountCharge(boolean polling)

public JSONObject validateAccountCharge(boolean polling)
Validates an account charge with timeout handling.
polling
boolean
Enable polling for timeout scenarios
Return Value
JSONObject
Returns validation result with polling support.
Example:
JSONObject validationResponse = accountCharge
    .setTransaction_reference(flwRef)
    .setOtp(otp)
    .validateAccountCharge(true);

System.out.println(validationResponse.toString());

Complete Payment Flow Example

import com.github.theresasogunle.AccountCharge;
import org.json.JSONObject;
import java.util.Scanner;

public class AccountPaymentFlow {
    public static void main(String[] args) {
        AccountCharge accountCharge = new AccountCharge();
        Scanner scanner = new Scanner(System.in);
        
        try {
            // Step 1: Initiate account charge
            JSONObject chargeResponse = accountCharge
                .setAccountnumber("0690000031")
                .setAccountbank("044")
                .setAmount("100")
                .setCurrency("NGN")
                .setCountry("NG")
                .setEmail("customer@example.com")
                .setFirstname("John")
                .setLastname("Doe")
                .setPasscode("09101989")
                .setTxRef("ACC-" + System.currentTimeMillis())
                .setIP("103.238.105.185")
                .setDevice_fingerprint("69e6b7f0b72037aa8428b70fbe03986c")
                .chargeAccount();
            
            System.out.println("Charge Response: " + chargeResponse.toString());
            
            // Step 2: Check if OTP is required
            String status = chargeResponse.getString("status");
            if ("success".equals(status)) {
                JSONObject data = chargeResponse.getJSONObject("data");
                String flwRef = data.getString("flwRef");
                String chargeResponseCode = data.getString("chargeResponseCode");
                
                // "02" means OTP is required
                if ("02".equals(chargeResponseCode)) {
                    System.out.println("OTP sent to customer. Please enter OTP:");
                    
                    // Step 3: Get OTP from customer
                    String otp = scanner.nextLine();
                    
                    // Step 4: Validate with OTP
                    JSONObject validationResponse = accountCharge
                        .setTransaction_reference(flwRef)
                        .setOtp(otp)
                        .validateAccountCharge();
                    
                    System.out.println("Validation Response: " + validationResponse.toString());
                    
                    // Step 5: Check final status
                    String validationStatus = validationResponse.getString("status");
                    if ("success".equals(validationStatus)) {
                        System.out.println("Payment successful!");
                    } else {
                        System.out.println("Payment failed: " + validationResponse.getString("message"));
                    }
                }
            } else {
                System.out.println("Charge failed: " + chargeResponse.getString("message"));
            }
            
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            scanner.close();
        }
    }
}

Response Handling

status
string
The status of the charge (e.g., “success”, “error”)
message
string
Description of the charge result
data
object
Contains transaction details including:
  • flwRef: Flutterwave transaction reference
  • chargeResponseCode: Response code (“02” indicates OTP required)
  • chargeResponseMessage: Message from processor
  • amount: Transaction amount
  • currency: Transaction currency

Bank Codes Reference

Common Nigerian bank codes:
  • Access Bank: 044
  • GTBank: 058
  • Zenith Bank: 057
  • First Bank: 011
  • UBA: 033
  • Wema Bank: 035
For a complete list of bank codes, refer to the Flutterwave documentation.

Notes

  • All setter methods return the AccountCharge instance for fluent chaining
  • The payment type is automatically set to “account”
  • Account charging is primarily supported for Nigerian banks
  • OTP validation is typically required for account charges
  • Always provide IP address and device fingerprint for enhanced security
  • The passcode is specific to the customer’s bank account setup
  • Use polling variants for better timeout handling in production environments
  • Response code “02” indicates OTP is required for validation
  • Response code “00” indicates successful charge

Build docs developers (and LLMs) love