/
Update_Recurring_Payment.pl
executable file
·112 lines (95 loc) · 3.4 KB
/
Update_Recurring_Payment.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
##
# BluePay Perl Sample code.
#
# This code sample runs a $0.00 Credit Card Auth transaction
# against a customer using test payment information.
# Once the rebilling cycle is created, this sample shows how to
# update the rebilling cycle. See comments below
# on the details of the initial setup of the rebilling cycle as well as the
# updated rebilling cycle.
##
use strict;
use lib '..';
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 => '1235 Test St.',
address2 => 'Apt',
city => 'Testville',
state => 'IL',
zip_code => '54321',
country => 'USA',
phone => '123-123-12345',
email => 'test@bluepay.com'
});
$rebill->set_cc_information({
cc_number =>'4111111111111111', # Customer Credit Card Number
cc_expiration => '1225', # 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();
my $payment_information_update = BluePay->new(
$account_id,
$secret_key,
$mode
);
# Sets an updated credit card expiration date
$payment_information_update->set_cc_information({
cc_expiration => '1229' # Card Expiration Date: MMYY
});
# Stores new card expiration date
$payment_information_update->auth({
amount => '0.00',
trans_id => $rebill->{RRNO} # the id of the rebill to update
});
# Makes the API Request to update the payment information
$payment_information_update->process();
# Creates a request to update the rebill
my $rebill_update = BluePay->new(
$account_id,
$secret_key,
$mode
);
# Updates the rebill
$rebill_update->update_rebill({
rebill_id => $rebill->{REBID}, # The ID of the rebill to be updated.
template_id => $rebill->{RRNO}, # Updates the payment information portion of the rebilling cycle with the new card expiration date entered above
next_date => "2015-03-01", # Rebill Start Date: March 1, 2015
reb_expr => "1 MONTH", # Rebill Frequency: 1 MONTH
reb_cycles => "8", # Rebill # of Cycles: 8
reb_amount => "5.15", # Rebill Amount: $5.15
next_amount =>"1.50" # Rebill Next Amount: $1.50
});
# Makes the API Request to update the rebill
$rebill_update->process();
# Reads the response from BluePay
if ($rebill->is_successful_response()){
print "REBILL STATUS: " . $rebill_update->{status} . "\n";
print "REBILL ID: " . $rebill_update->{rebill_id} . "\n";
print "REBILL CREATION DATE: " .$rebill_update->{creation_date} . "\n";
print "REBILL NEXT DATE: " .$rebill_update->{next_date} . "\n";
print "REBILL LAST DATE: " .$rebill_update->{last_date} . "\n";
print "REBILL SCHEDULE EXPRESSION: " .$rebill_update->{sched_expr} . "\n";
print "REBILL CYCLES REMAINING: " .$rebill_update->{cycles_remain} . "\n";
print "REBILL AMOUNT: " .$rebill_update->{reb_amount} . "\n";
print "REBILL NEXT AMOUNT: " .$rebill_update->{next_amount} . "\n";
} else {
print $rebill->{MESSAGE} . "\n";
}