Level 2 & Level 3 Processing: Java

This code steps you through an example of passing Level 2 & Level 3 data with a transaction.

There are three outcomes when processing credit card transactions:

  1. Approved
  2. Declined
  3. Error

'Approved' transactions can be charged against customers' credit cards. 'Declined' transactions can't be charged. As a result, in order to test the process of charging a customer's credit card, you must first pass an odd dollar amount. This returns the transaction with an 'Approved' status. You can then charge the credit card to complete the transaction.

An error could result from a variety of conditions such as missing data, invalid card numbers, and expiration dates provided in invalid formats.

The following sample code calls a routine from our Code Library.
Download BluePay.php
Or, download via GitHub

* BluePay Java Sample code.
* This code sample runs a $3.00 Credit Card Sale transaction
* against a customer using test payment information.
* If using TEST mode, odd dollar amounts will return
* an approval and even dollar amounts will return a decline.

package transactions;
import bluepay.*;
import java.util.HashMap;

public class Charge_Customer_CC_Lvl2_Lvl3 {
  public static void main(String[] args) {
    String ACCOUNT_ID = "Merchant's Account ID Here";
    String SECRET_KEY = "Merchant's Secret Key Here";
    String MODE = "TEST";

    BluePay payment = new BluePay(

    // Set Customer Information 
    HashMap<String, String> customerParams = new HashMap<>();
    customerParams.put("firstName", "Bob");
    customerParams.put("lastName", "Tester");
    customerParams.put("address1", "123 Test St.");
    customerParams.put("address2", "Apt #500");
    customerParams.put("city", "Testville");
    customerParams.put("state", "IL");
    customerParams.put("zip", "54321");
    customerParams.put("country", "USA");
    customerParams.put("phone", "123-123-12345");
    customerParams.put("email", "[email protected]");

    // Set Credit Card Information
    HashMap<String, String> ccParams = new HashMap<>();
    ccParams.put("cardNumber", "4111111111111111");
    ccParams.put("expirationDate", "1225");
    ccParams.put("cvv2", "123");
    // Set Level 2 Information
    // Add Line Item for Level3 Processing
    HashMap<String, String> item1Params = new HashMap<>();
    item1Params.put("quantity", "1"); // The number of units of item. Max: 5 digits.
    item1Params.put("unitCost", "3.00"); // The cost per unit of item. Max: 9 digits decimal.
    item1Params.put("descriptor", "test1"); // Description of the item purchased. Max: 26 character.
    item1Params.put("commodityCode", "123412341234"); // Commodity Codes can be found at http://www.census.gov/svsd/www/cfsdat/2002data/cfs021200.pdf. Max: 12 characters.
    item1Params.put("productCode", "432143214321"); // Merchant-defined code for the product or service being purchased. Max: 12 characters.
    item1Params.put("measureUnits", "EA"); // The unit of measure of the item purchase. Normally EA. Max: 3 characters.
    item1Params.put("taxRate", "7.0"); // Tax rate for the item. Max: 4 digits.
    item1Params.put("taxAmount", "0.21"); // Tax amount for the item. unit_cost * quantity * tax_rate = tax_amount. Max: 9 digits.
    item1Params.put("itemDiscount", "0.00"); // The amount of any discounts on the item. Max: 12 digits.
    item1Params.put("lineItemTotal", "3.21"); // The total amount for the item including taxes and discounts.
    HashMap<String, String> item2Params = new HashMap<>();
    item2Params.put("quantity", "2");
    item2Params.put("unitCost", "5.00");
    item2Params.put("descriptor", "test2");
    item2Params.put("commodityCode", "123412341234");
    item2Params.put("productCode", "098709870987");
    item2Params.put("measureUnits", "EA");
    item2Params.put("taxRate", "7.0");
    item2Params.put("taxAmount", "0.70");
    item2Params.put("itemDiscount", "0.00");
    item2Params.put("lineItemTotal", "10.70");
    // Set sale amount: $13.91
    HashMap<String, String> saleParams = new HashMap<>();
    saleParams.put("amount", "13.91");

    // Makes the API Request with BluePay
    try {
    } catch (Exception ex) {
      System.out.println("Exception: " + ex.toString());
    // If transaction was successful reads the responses from BluePay
    if (payment.isSuccessful()) {
      System.out.println("Transaction Status: " + payment.getStatus());
      System.out.println("Transaction Message: " + payment.getMessage());
      System.out.println("Transaction ID: " + payment.getTransID());
      System.out.println("AVS Response: " + payment.getAVS());
      System.out.println("CVV2 Response: " + payment.getCVV2());
      System.out.println("Masked Payment Account: " + payment.getMaskedPaymentAccount());
      System.out.println("Card Type: " + payment.getCardType());   
      System.out.println("Authorization Code: " + payment.getAuthCode());
    } else {
      System.out.println("Error: " + payment.getMessage());
Can’t find what you’re
looking for? We can help.

Contact 800-350-2684 for Integration Support.

  • Microsoft Gold Partner Badge
  • 2018 American Business Awards Gold Stevie® Winner Badge for Best Payment and Electronic Commerce Solution
  • 2018 CNP Awards Customer Choice Winner Badge for Best E-Commerce Platform/Gateway
  • Best in Biz Awards 2018 Silver Winner Badge for Business Development Department of the Year
  • TSG Gateway Awards 2019 BluePay
BluePay Processing, LLC is a registered ISO of Wells Fargo Bank, N.A., Concord, CA, 94524 U.S.A.
BluePay Canada ULC, is a Registered ISO/MSP of Peoples Trust Company, Vancouver, Canada.