Cancel a Recurring Payment: Java

This code cancels a customer's recurring payments.

You can only cancel future recurring payments. If a payment has already been settled, you must issue a refund instead.
For that Go to: Reverse a sale

This code uses BluePay's Rebilling Administration Interface.
For documentation on usage of this interface Go to: Library documentation

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

* BluePay Java Sample code.
* This code sample runs a $0.00 Credit Card Auth transaction
* against a customer using test payment information, sets up
* a rebilling cycle, and also shows how to cancel that rebilling cycle. See comments below
* on the details of the initial setup of the rebilling cycle.

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

public class Cancel_Recurring_Payment {
  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 rebill = new BluePay(

    // Set Customer Information
    HashMap<String, String> customerParams = new HashMap<>();
    customerParams.put("firstName", "Bob");
    customerParams.put("lastName", "Tester");
    customerParams.put("address1", "122 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 recurring payment
    HashMap<String, String> rebillParams = new HashMap<>();
    rebillParams.put("firstDate", "2015-01-01"); // Rebill Start Date: Jan. 1, 2015
    rebillParams.put("expr", "1 MONTH"); // Rebill Frequency: 1 MONTH
    rebillParams.put("cycles", "12"); // Rebill # of Cycles: 12
    rebillParams.put("amount", "15.00"); // Rebill Amount: $15.00

    // Sets a Card Authorization at $0.00
    HashMap<String, String> authParams = new HashMap<>();
    authParams.put("amount", "0.00");

    //  Makes the API Request to create a rebill
    try {
    } catch (Exception ex) {
      System.out.println("Exception: " + ex.toString());

    // Returns true if transaction was successful
    if (rebill.isSuccessful()) {

      // Creates a rebill cancellation
      BluePay rebillCancel = new BluePay(
      //  Find rebill by id and cancel rebilling cycle
      //  Makes the API Request to cancel rebill
      try {
        } catch (Exception ex) {
        System.out.println("Exception: " + ex.toString());

        // Reads the response from BluePay
        System.out.println("Rebill Status: " + rebillCancel.getRebillStatus());
        System.out.println("Rebill ID: " + rebill.getRebillingID());
        System.out.println("Rebill Creation Date: " + rebillCancel.getRebillCreationDate());
        System.out.println("Rebill Next Date: " + rebillCancel.getRebillNextDate());
        System.out.println("Rebill Last Date: " + rebillCancel.getRebillLastDate());
        System.out.println("Rebill Schedule Expression: " + rebillCancel.getRebillSchedExpr());
        System.out.println("Rebill Cycles Remaining: " + rebillCancel.getRebillCyclesRemain());
        System.out.println("Rebill Amount: " + rebillCancel.getRebillAmount());
        System.out.println("Rebill Next Amount: " + rebillCancel.getRebillNextAmount());
        } else {
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.