Skip to main content

Overview

Before you can use the Rave Java Library to process payments, you need to configure it with your Flutterwave API credentials and choose the appropriate environment. This guide covers all configuration options and best practices.

RaveConstant class

The RaveConstant class is the central configuration point for the library. It holds three critical static properties that must be set before making any API calls:
public class RaveConstant {
    public static String SECRET_KEY;
    public static String PUBLIC_KEY;
    public static Environment ENVIRONMENT;
}

Required configuration

You must configure these three properties at the start of your application:
1

Set your public key

Your public key identifies your application to Flutterwave:
RaveConstant.PUBLIC_KEY = "FLWPUBK-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-X";
2

Set your secret key

Your secret key is used to encrypt sensitive payment data:
RaveConstant.SECRET_KEY = "FLWSECK-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-X";
Never commit your secret key to version control or expose it in client-side code.
3

Set the environment

Choose between staging (testing) and live (production) environments:
RaveConstant.ENVIRONMENT = Environment.STAGING;

Environment enumeration

The Environment enum defines two possible values:
public enum Environment {
    STAGING,
    LIVE
}

STAGING environment

Use the staging environment for development and testing:
RaveConstant.ENVIRONMENT = Environment.STAGING;
In staging mode:
  • No real money is charged
  • Test cards and accounts can be used
  • API calls go to Flutterwave’s test servers
  • Use your test API keys from the test dashboard

LIVE environment

Use the live environment for production:
RaveConstant.ENVIRONMENT = Environment.LIVE;
In live mode:
  • Real money is charged
  • Only real cards and accounts work
  • API calls go to Flutterwave’s production servers
  • Use your live API keys from the production dashboard

Complete configuration example

Here’s a complete configuration example:
Configuration.java
import com.github.theresasogunle.RaveConstant;
import com.github.theresasogunle.Environment;

public class Configuration {
    public static void configure() {
        // Set public key
        RaveConstant.PUBLIC_KEY = "FLWPUBK-8ba286388b24dbd6c20706def0b4ea23-X";
        
        // Set secret key
        RaveConstant.SECRET_KEY = "FLWSECK-c45e0f704619e673263844e584bba013-X";
        
        // Set environment
        RaveConstant.ENVIRONMENT = Environment.STAGING;
    }
    
    public static void main(String[] args) {
        configure();
        System.out.println("Rave configured successfully!");
    }
}

Getting your API keys

You need to obtain API keys from your Flutterwave dashboard:
1

Sign up for an account

Create a Flutterwave account:
2

Access your dashboard

Log in to your Flutterwave dashboard after account verification.
3

Navigate to API settings

Go to Settings > API in the dashboard menu.
4

Copy your keys

You’ll find two sets of keys:
  • Test keys: For use with Environment.STAGING
  • Live keys: For use with Environment.LIVE
Copy both the public key and secret key.
Keep your test and live keys separate. Consider using environment variables or configuration files to manage them.

Security best practices

Follow these best practices to keep your integration secure:

1. Never expose your secret key

// ❌ BAD: Hardcoding keys in source code
RaveConstant.SECRET_KEY = "FLWSECK-c45e0f704619e673263844e584bba013-X";

// ✅ GOOD: Loading from environment variables
RaveConstant.SECRET_KEY = System.getenv("FLUTTERWAVE_SECRET_KEY");

2. Use environment variables

Store your API keys in environment variables instead of hardcoding them:
SecureConfiguration.java
import com.github.theresasogunle.RaveConstant;
import com.github.theresasogunle.Environment;

public class SecureConfiguration {
    public static void configure() {
        // Load from environment variables
        RaveConstant.PUBLIC_KEY = System.getenv("FLUTTERWAVE_PUBLIC_KEY");
        RaveConstant.SECRET_KEY = System.getenv("FLUTTERWAVE_SECRET_KEY");
        
        // Determine environment from config
        String env = System.getenv("FLUTTERWAVE_ENV");
        RaveConstant.ENVIRONMENT = "LIVE".equals(env) 
            ? Environment.LIVE 
            : Environment.STAGING;
    }
}

3. Use configuration files

Alternatively, use a properties file (excluded from version control):
config.properties
flutterwave.public.key=FLWPUBK-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-X
flutterwave.secret.key=FLWSECK-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-X
flutterwave.environment=STAGING
ConfigLoader.java
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import com.github.theresasogunle.RaveConstant;
import com.github.theresasogunle.Environment;

public class ConfigLoader {
    public static void loadConfiguration(String configPath) throws IOException {
        Properties props = new Properties();
        props.load(new FileInputStream(configPath));
        
        RaveConstant.PUBLIC_KEY = props.getProperty("flutterwave.public.key");
        RaveConstant.SECRET_KEY = props.getProperty("flutterwave.secret.key");
        
        String env = props.getProperty("flutterwave.environment");
        RaveConstant.ENVIRONMENT = "LIVE".equalsIgnoreCase(env)
            ? Environment.LIVE
            : Environment.STAGING;
    }
}
Add config.properties to your .gitignore file to prevent accidentally committing your API keys to version control.

4. Validate configuration

Always validate that configuration is complete before processing payments:
ConfigValidator.java
import com.github.theresasogunle.RaveConstant;

public class ConfigValidator {
    public static void validateConfiguration() throws IllegalStateException {
        if (RaveConstant.PUBLIC_KEY == null || RaveConstant.PUBLIC_KEY.isEmpty()) {
            throw new IllegalStateException("PUBLIC_KEY is not configured");
        }
        
        if (RaveConstant.SECRET_KEY == null || RaveConstant.SECRET_KEY.isEmpty()) {
            throw new IllegalStateException("SECRET_KEY is not configured");
        }
        
        if (RaveConstant.ENVIRONMENT == null) {
            throw new IllegalStateException("ENVIRONMENT is not configured");
        }
        
        System.out.println("Configuration validated successfully");
        System.out.println("Environment: " + RaveConstant.ENVIRONMENT);
    }
}

5. Separate test and production configurations

EnvironmentConfig.java
import com.github.theresasogunle.RaveConstant;
import com.github.theresasogunle.Environment;

public class EnvironmentConfig {
    public static void configureStaging() {
        RaveConstant.PUBLIC_KEY = System.getenv("FLUTTERWAVE_TEST_PUBLIC_KEY");
        RaveConstant.SECRET_KEY = System.getenv("FLUTTERWAVE_TEST_SECRET_KEY");
        RaveConstant.ENVIRONMENT = Environment.STAGING;
    }
    
    public static void configureProduction() {
        RaveConstant.PUBLIC_KEY = System.getenv("FLUTTERWAVE_LIVE_PUBLIC_KEY");
        RaveConstant.SECRET_KEY = System.getenv("FLUTTERWAVE_LIVE_SECRET_KEY");
        RaveConstant.ENVIRONMENT = Environment.LIVE;
    }
}

Configuration checklist

Before going live, verify your configuration:
1

Test environment works

Verify that you can successfully process payments in staging mode with test keys.
2

Live keys obtained

Ensure you have valid live API keys from your production dashboard.
3

Keys are secured

Confirm that secret keys are stored in environment variables or secure configuration files, not in source code.
4

Environment switching

Verify that your application correctly switches between staging and live environments based on configuration.
5

Error handling

Test that your application handles missing or invalid configuration gracefully.
The library automatically handles encryption and API endpoints based on your environment setting. You don’t need to configure these manually.

Common configuration issues

Issue: NullPointerException when making API calls

Cause: Configuration was not set before making API calls. Solution: Ensure you set all three RaveConstant properties before creating any charge objects.

Issue: “Invalid key” errors

Cause: Using test keys in live environment or vice versa. Solution: Verify that your keys match your environment setting:
  • Test keys with Environment.STAGING
  • Live keys with Environment.LIVE

Issue: API calls failing in production

Cause: Environment is still set to STAGING in production. Solution: Ensure RaveConstant.ENVIRONMENT = Environment.LIVE is set when deploying to production.

Next steps

Quickstart

Process your first payment with your configured credentials

Card payments

Learn about all card payment options and methods

Authentication

Learn about authentication and API keys

Error handling

Handle configuration and API errors gracefully