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 calls a routine from our Code Library.
Download bluepay.pm

Credit Card Recurring Payment

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

use strict;
use bluepay;

my $account_id = "Merchant's Account ID Here";
my $secret_key = "Merchant's Secret Key Here";
my $mode = "TEST";

my $rebill = BluePay->new(
  $account_id,
  $secret_key,
  $mode
);

$rebill->set_customer_information({
  first_name => 'Bob',
  last_name => 'Tester',
  address1 => '123 Test St.',
  address2 => 'Apt',
  city => 'Testville',
  state => 'IL',
  zip_code => '54321',
  country => 'USA',
  phone => '123-123-12345',
  email => '[email protected]'
});

$rebill->set_cc_information({
  cc_number =>'4111111111111111', # Customer Credit Card Number
  cc_expiration => '0815', # 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
});

$rebill->auth({amount => '0.00'}); # Card authorization amount: $0.00

# Makes the API Request with BluePay
$rebill->process();

# Reads the response from BluePay
if ($rebill->is_successful_response()){
  print "TRANSACTION ID: " . $rebill->{RRNO} . "\n";
  print "REBILL ID: " . $rebill->{REBID} . "\n";
  print "TRANSACTION STATUS: " . $rebill->{Result} . "\n";
  print "TRANSACTION MESSAGE: " . $rebill->{MESSAGE} . "\n";
  print "AVS RESULT: " .$rebill->{AVS} . "\n";
  print "CVV2 RESULT: " . $rebill->{CVV2} . "\n";
  print "MASKED PAYMENT ACCOUNT: " . $rebill->{PAYMENT_ACCOUNT} . "\n";
  print "CARD TYPE: " . $rebill->{CARD_TYPE} . "\n";
  print "AUTH CODE: " . $rebill->{AUTH_CODE} . "\n";
} else {
  print $rebill->{MESSAGE} . "\n";
}

ACH Recurring Payment

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


use strict;
use bluepay;

my $account_id = "Merchant's Account ID Here";
my $secret_key = "Merchant's Secret Key Here";
my $mode = "TEST";

my $rebill = BluePay->new(
  $account_id,
  $secret_key,
  $mode
);

$rebill->set_customer_information({
  first_name => 'Bob',
  last_name => 'Tester',
  address1 => '123 Test St.',
  address2 => 'Apt',
  city => 'Testville',
  state => 'IL',
  zip_code => '54321',
  country => 'USA',
  phone => '123-123-12345',
  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'}); # Card authorization amount: $0.00

# Makes the API Request with BluePay
$rebill->process();

# Reads the response from BluePay
if ($rebill->is_successful_response()){
  print "TRANSACTION ID: " . $rebill->{RRNO} . "\n";
  print "REBILL ID: " . $rebill->{REBID} . "\n";
  print "TRANSACTION STATUS: " . $rebill->{Result} . "\n";
  print "TRANSACTION MESSAGE: " . $rebill->{MESSAGE} . "\n";
  print "MASKED PAYMENT ACCOUNT: " . $rebill->{PAYMENT_ACCOUNT} . "\n";
  print "CUSTOMER BANK: " . $rebill->{BANK_NAME} . "\n";
} else {
  print $rebill->{MESSAGE} . "\n";
}
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.