Create a Recurring Payment

This code steps you through the process of storing a payment method for a customer and using it to set up recurring payments. When this recurring payment information is stored, a $0 authorization is used for the initial transaction. As a result, the customer is not charged until the rebilling cycle begins.

For sample code that charges customers at the same point of establishing rebilling Go to: Run a credit card transaction with recurring payments or ACH processing with recurring payments

The following sample code makes method calls utilizing our ruby gem.
Download BluePay gem

Credit Card

##
# BluePay Ruby Sample code.
#
# This code sample creates a recurring payment charging $15.00 per month for one year.
##

require "bluepay"

ACCOUNT_ID = "Merchant's Account ID Here"
SECRET_KEY = "Merchant's Secret Key Here"
MODE = "TEST" 

rebill = BluePay.new(
  account_id: ACCOUNT_ID , 
  secret_key: SECRET_KEY, 
  mode: MODE
)

rebill.set_customer_information(
  first_name: "Bob",
  last_name: "Tester",
  address1: "123 Test St.",
  address2: "Apt #500",
  city: "Testville",
  state: "IL",
  zip_code: "54321",
  country: "USA",
  phone: "123-123-1234", 
  email: "[email protected]
)

rebill.set_cc_information(
  cc_number: "4111111111111111", # Customer Credit Card Number
  cc_expiration: "1215", # Card Expiration Date: MMYY
  cvv2: "123" # Card CVV2
)

rebill.set_recurring_payment(
  reb_first_date: "2015-01-01", # Rebill Start Date: Jan. 1, 2015
  reb_expr: "1 MONTH", # Rebill Frequency: 1 MONTH
  reb_cycles: "12", # Rebill # of Cycles: 12
  reb_amount: "15.00" # Rebill Amount: $15.00
)

# Sets a Card Authorization at $0.00
rebill.auth(amount: "0.00")

# Makes the API Request
rebill.process

# If transaction was successful reads the responses from BluePay
if rebill.successful_transaction?
  puts "TRANSACTION ID: " + rebill.get_trans_id
  puts "REBILL ID: " + rebill.get_rebill_id
  puts "TRANSACTION STATUS: " + rebill.get_status
  puts "TRANSACTION MESSAGE: " + rebill.get_message
  puts "AVS RESPONSE: " + rebill.get_avs_code
  puts "CVV2 RESPONSE: " + rebill.get_cvv2_code
  puts "MASKED PAYMENT ACCOUNT: " + rebill.get_masked_account
  puts "CARD TYPE: " + rebill.get_card_type
  puts "AUTH CODE: " + rebill.get_auth_code
else
  puts rebill.get_message
end

ACH

##
# BluePay Ruby Sample code.
#
# This code sample creates a recurring payment charging $15.00 per month for one year.
##

require "bluepay.rb"

ACCOUNT_ID = "Merchant's Account ID Here"
SECRET_KEY = "Merchant's Secret Key Here"
MODE = "TEST" 

rebill = BluePay.new(
  account_id: ACCOUNT_ID , 
  secret_key: SECRET_KEY, 
  mode: MODE
)

rebill.set_customer_information(
  first_name: "Bob",
  last_name: "Tester",
  address1: "123 Test St.",
  address2: "Apt #500",
  city: "Testville",
  state: "IL",
  zip_code: "54321",
  country: "USA",
  phone: "123-123-1234", 
  email: "[email protected]
)

rebill.set_ach_information(
  ach_routing: "123123123", # Routing Number: 123123123
  ach_account: "123456789", # Account Number: 123456789
  ach_account_type: 'C', # Account Type: Checking
  doc_type: "WEB" # ACH Document Type: WEB
)

rebill.set_recurring_payment(
  reb_first_date: "2015-01-01", # Rebill Start Date: Jan. 1, 2015
  reb_expr: "1 MONTH", # Rebill Frequency: 1 MONTH
  reb_cycles: "12", # Rebill # of Cycles: 12
  reb_amount: "15.00" # Rebill Amount: $15.00
)

rebill.auth(amount: "0.00")

# Makes the API Request with BluePay
rebill.process

# If transaction was successful reads the responses from BluePay
if rebill.successful_transaction?
  puts "TRANSACTION ID: " + rebill.get_trans_id
  puts "REBILL ID: " + rebill.get_rebill_id
  puts "TRANSACTION STATUS: " + rebill.get_status
  puts "TRANSACTION MESSAGE: " + rebill.get_message
  puts "MASKED PAYMENT ACCOUNT: " + rebill.get_masked_account
  puts "CUSTOMER BANK NAME: " + rebill.get_bank_name
else
  puts rebill.get_message
end
BluePay Processing, LLC is a registered ISO of Wells Fargo Bank, N.A., Walnut Creek, CA, U.S.A.
BluePay Canada ULC, is a Registered ISO/MSP of Peoples Trust Company, Vancouver, Canada.