| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Business::OnlinePayment::SynapseGateway;
|
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
23889
|
use strict;
|
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
46
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings;
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
6
|
1
|
|
|
1
|
|
7
|
use Carp;
|
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
114
|
|
|
7
|
1
|
|
|
1
|
|
1801
|
use Business::OnlinePayment;
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Business::OnlinePayment::HTTPS;
|
|
9
|
|
|
|
|
|
|
use vars qw($VERSION @ISA $me);
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
@ISA = qw(Business::OnlinePayment::HTTPS);
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$VERSION = '0.01'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$me = 'Business::OnlinePayment::SynapseGateway';
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub set_defaults {
|
|
18
|
|
|
|
|
|
|
my $self = shift;
|
|
19
|
|
|
|
|
|
|
$self->server("connect12.synapsegateway.net"); |
|
20
|
|
|
|
|
|
|
$self->port("443");
|
|
21
|
|
|
|
|
|
|
$self->path("/Submit.aspx");
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$self->build_subs(qw( order_number avs_code |
|
24
|
|
|
|
|
|
|
));
|
|
25
|
|
|
|
|
|
|
}
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub map_fields {
|
|
28
|
|
|
|
|
|
|
my($self) = @_;
|
|
29
|
|
|
|
|
|
|
my %content = $self->content();
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my %map;
|
|
32
|
|
|
|
|
|
|
if ($content{'type'} =~ /^(cc)$/i) {
|
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
%map = ( 'normal authorization' => 'S',
|
|
35
|
|
|
|
|
|
|
'authorization only' => 'A',
|
|
36
|
|
|
|
|
|
|
'credit' => 'C',
|
|
37
|
|
|
|
|
|
|
'post authorization' => 'P',
|
|
38
|
|
|
|
|
|
|
'void' => 'V',
|
|
39
|
|
|
|
|
|
|
);
|
|
40
|
|
|
|
|
|
|
}
|
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$content{'action'} = $map{lc($content{'action'})}
|
|
43
|
|
|
|
|
|
|
or croak 'Unknown action: '. $content{'action'};
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$self->transaction_type($content{'type'});
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# stuff it back into content
|
|
48
|
|
|
|
|
|
|
$self->content(%content);
|
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub required_fields { |
|
52
|
|
|
|
|
|
|
my($self,@fields) = @_; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my @missing; |
|
55
|
|
|
|
|
|
|
my %content = $self->content(); |
|
56
|
|
|
|
|
|
|
foreach(@fields) { |
|
57
|
|
|
|
|
|
|
next |
|
58
|
|
|
|
|
|
|
if (exists $content{$_} && defined $content{$_} && $content{$_}=~/\S+/); |
|
59
|
|
|
|
|
|
|
push(@missing, $_); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Carp::croak("missing required field(s): " . join(", ", @missing) . "\n") |
|
63
|
|
|
|
|
|
|
if(@missing); |
|
64
|
|
|
|
|
|
|
}
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub submit {
|
|
67
|
|
|
|
|
|
|
my($gateway) = @_; |
|
68
|
|
|
|
|
|
|
my $tranType; |
|
69
|
|
|
|
|
|
|
my $tranAmt;
|
|
70
|
|
|
|
|
|
|
$gateway->map_fields();
|
|
71
|
|
|
|
|
|
|
$gateway->remap_fields(
|
|
72
|
|
|
|
|
|
|
login => 'Syn_Act',
|
|
73
|
|
|
|
|
|
|
password => 'Syn_Pwd',
|
|
74
|
|
|
|
|
|
|
action => 'Tran_Type',
|
|
75
|
|
|
|
|
|
|
amount => 'Tran_Amt',
|
|
76
|
|
|
|
|
|
|
invoice_number => 'Tran_Inv',
|
|
77
|
|
|
|
|
|
|
customer_id => 'Tran_CNum',
|
|
78
|
|
|
|
|
|
|
description => 'Tran_Note',
|
|
79
|
|
|
|
|
|
|
card_number => 'Card_Num',
|
|
80
|
|
|
|
|
|
|
name => 'Card_Name',
|
|
81
|
|
|
|
|
|
|
expiration => 'Card_Exp',
|
|
82
|
|
|
|
|
|
|
address => 'AVS_Street',
|
|
83
|
|
|
|
|
|
|
zip => 'AVS_Zip',
|
|
84
|
|
|
|
|
|
|
cvv2 => 'CVV_Num',
|
|
85
|
|
|
|
|
|
|
order_number => 'Proc_ID',
|
|
86
|
|
|
|
|
|
|
); |
|
87
|
|
|
|
|
|
|
#Set required fields based on action |
|
88
|
|
|
|
|
|
|
my %required; |
|
89
|
|
|
|
|
|
|
#Sale |
|
90
|
|
|
|
|
|
|
$required{S} = [ qw( Syn_Act Syn_Pwd Tran_Type Tran_Amt Card_Name |
|
91
|
|
|
|
|
|
|
Card_Num Card_Exp ) ]; |
|
92
|
|
|
|
|
|
|
#Credit |
|
93
|
|
|
|
|
|
|
$required{C} = [ qw( Syn_Act Syn_Pwd Tran_Type Tran_Amt Card_Name |
|
94
|
|
|
|
|
|
|
Card_Num Card_Exp ) ]; |
|
95
|
|
|
|
|
|
|
#Void |
|
96
|
|
|
|
|
|
|
$required{V} = [ qw( Syn_Act Syn_Pwd Tran_Type Proc_ID ) ]; |
|
97
|
|
|
|
|
|
|
#Auth |
|
98
|
|
|
|
|
|
|
$required{A} = [ qw( Syn_Act Syn_Pwd Tran_Type Tran_Amt Card_Name |
|
99
|
|
|
|
|
|
|
Card_Num Card_Exp ) ]; |
|
100
|
|
|
|
|
|
|
#Post Auth |
|
101
|
|
|
|
|
|
|
$required{P} = [ qw( Syn_Act Syn_Pwd Tran_Type Tran_Amt Proc_ID ) ]; |
|
102
|
|
|
|
|
|
|
#Mark |
|
103
|
|
|
|
|
|
|
$required{M} = [ qw( Syn_Act Syn_Pwd Tran_Type Tran_Amt Proc_ID ) ]; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#Collect content |
|
106
|
|
|
|
|
|
|
my %trans = $gateway->content(); |
|
107
|
|
|
|
|
|
|
$tranType = $trans{'Tran_Type'}; |
|
108
|
|
|
|
|
|
|
$tranAmt = $trans{'Tran_Amt'}; |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
#Check for post auth |
|
111
|
|
|
|
|
|
|
if ($trans{'Tran_Type'} eq "P"){ |
|
112
|
|
|
|
|
|
|
#Collect content for query |
|
113
|
|
|
|
|
|
|
my %query = $gateway->content(); |
|
114
|
|
|
|
|
|
|
$query{'Tran_Type'} = 'Q'; |
|
115
|
|
|
|
|
|
|
$gateway->content(%query); |
|
116
|
|
|
|
|
|
|
#Send query |
|
117
|
|
|
|
|
|
|
my( $Qpage, $Qresp, %Qresp_headers) = |
|
118
|
|
|
|
|
|
|
$gateway->https_post( $gateway->get_fields( $gateway->fields ) ); |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
$gateway->response_code( $Qresp ); |
|
121
|
|
|
|
|
|
|
$gateway->response_page( $Qpage ); |
|
122
|
|
|
|
|
|
|
$gateway->response_headers( \%Qresp_headers ); |
|
123
|
|
|
|
|
|
|
#parse query response |
|
124
|
|
|
|
|
|
|
my %Qresults = map { s/\s*$//; |
|
125
|
|
|
|
|
|
|
my ($name, $value) = split '=', $_, 2; |
|
126
|
|
|
|
|
|
|
$name =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; |
|
127
|
|
|
|
|
|
|
$value =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; |
|
128
|
|
|
|
|
|
|
$name, $value; |
|
129
|
|
|
|
|
|
|
} split '&', $Qpage; |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
#Check if passed amount and auth amount are the same |
|
132
|
|
|
|
|
|
|
if ($trans{'amount'}+0 eq $Qresults{'Tran_Amt'}+0){ |
|
133
|
|
|
|
|
|
|
#Amounts are the same, change to Mark instead of Post Auth |
|
134
|
|
|
|
|
|
|
$trans{'Tran_Type'} = 'M'; |
|
135
|
|
|
|
|
|
|
$gateway->content(%trans); |
|
136
|
|
|
|
|
|
|
} else { |
|
137
|
|
|
|
|
|
|
#Submit passed values |
|
138
|
|
|
|
|
|
|
$trans{'Tran_type'} = $tranType; |
|
139
|
|
|
|
|
|
|
$trans{'Tran_Amt'} = $tranAmt; |
|
140
|
|
|
|
|
|
|
$gateway->content(%trans); |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
#Check for required |
|
144
|
|
|
|
|
|
|
$gateway->required_fields(@{$required{$trans{'Tran_Type'}}}); |
|
145
|
|
|
|
|
|
|
#Submit |
|
146
|
|
|
|
|
|
|
my( $page, $resp, %resp_headers) = |
|
147
|
|
|
|
|
|
|
$gateway->https_post( $gateway->get_fields( $gateway->fields ) ); |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
$gateway->response_code( $resp ); |
|
150
|
|
|
|
|
|
|
$gateway->response_page( $page ); |
|
151
|
|
|
|
|
|
|
$gateway->response_headers( \%resp_headers ); |
|
152
|
|
|
|
|
|
|
#Get results |
|
153
|
|
|
|
|
|
|
my %results = map { s/\s*$//; |
|
154
|
|
|
|
|
|
|
my ($name, $value) = split '=', $_, 2; |
|
155
|
|
|
|
|
|
|
$name =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; |
|
156
|
|
|
|
|
|
|
$value =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; |
|
157
|
|
|
|
|
|
|
$name, $value; |
|
158
|
|
|
|
|
|
|
} split '&', $page; |
|
159
|
|
|
|
|
|
|
#Parse results |
|
160
|
|
|
|
|
|
|
$gateway->avs_code( $results{ 'AVS_Code' } ); |
|
161
|
|
|
|
|
|
|
$gateway->result_code( $results{ 'Proc_Resp' } ); |
|
162
|
|
|
|
|
|
|
$gateway->order_number( $results{ 'Proc_ID' } ); |
|
163
|
|
|
|
|
|
|
$gateway->authorization( $results{ 'Proc_Code' } ); |
|
164
|
|
|
|
|
|
|
$gateway->error_message( $results{ 'Proc_Mess' } ); |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
#If type is Post Auth send Mark |
|
167
|
|
|
|
|
|
|
if ($results{ 'Proc_Resp' } eq "Approved" && $results{ 'Tran_Type' } eq "P"){ |
|
168
|
|
|
|
|
|
|
#Setup mark transaction |
|
169
|
|
|
|
|
|
|
my %mark = $gateway->content(); |
|
170
|
|
|
|
|
|
|
$mark{'Tran_Type'} = 'M'; |
|
171
|
|
|
|
|
|
|
$mark{'order_number'} = $results{'Proc_ID'}; |
|
172
|
|
|
|
|
|
|
$gateway->content(%mark); |
|
173
|
|
|
|
|
|
|
#Send mark |
|
174
|
|
|
|
|
|
|
my( $page, $resp, %resp_headers) = |
|
175
|
|
|
|
|
|
|
$gateway->https_post( $gateway->get_fields( $gateway->fields ) ); |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
$gateway->response_code( $resp ); |
|
178
|
|
|
|
|
|
|
$gateway->response_page( $page ); |
|
179
|
|
|
|
|
|
|
$gateway->response_headers( \%resp_headers ); |
|
180
|
|
|
|
|
|
|
#Get results |
|
181
|
|
|
|
|
|
|
my %results = map { s/\s*$//; |
|
182
|
|
|
|
|
|
|
my ($name, $value) = split '=', $_, 2; |
|
183
|
|
|
|
|
|
|
$name =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; |
|
184
|
|
|
|
|
|
|
$value =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; |
|
185
|
|
|
|
|
|
|
$name, $value; |
|
186
|
|
|
|
|
|
|
} split '&', $page; |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
#Set success |
|
189
|
|
|
|
|
|
|
if ($results{ 'Proc_Resp' } eq "Approved"){ |
|
190
|
|
|
|
|
|
|
$gateway->is_success(1); |
|
191
|
|
|
|
|
|
|
} else { |
|
192
|
|
|
|
|
|
|
$gateway->is_success(0); |
|
193
|
|
|
|
|
|
|
}
|
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub fields {
|
|
197
|
|
|
|
|
|
|
my $self = shift;
|
|
198
|
|
|
|
|
|
|
my @fields = qw(
|
|
199
|
|
|
|
|
|
|
Syn_Act
|
|
200
|
|
|
|
|
|
|
Syn_Pwd
|
|
201
|
|
|
|
|
|
|
Tran_Type
|
|
202
|
|
|
|
|
|
|
Tran_Amt
|
|
203
|
|
|
|
|
|
|
Tran_Inv
|
|
204
|
|
|
|
|
|
|
Tran_CNum
|
|
205
|
|
|
|
|
|
|
Tran_Note
|
|
206
|
|
|
|
|
|
|
Card_Num
|
|
207
|
|
|
|
|
|
|
Card_Name
|
|
208
|
|
|
|
|
|
|
Card_Exp
|
|
209
|
|
|
|
|
|
|
AVS_Street
|
|
210
|
|
|
|
|
|
|
AVS_Zip
|
|
211
|
|
|
|
|
|
|
CVV_Num
|
|
212
|
|
|
|
|
|
|
Proc_ID
|
|
213
|
|
|
|
|
|
|
);
|
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
return @fields;
|
|
216
|
|
|
|
|
|
|
}
|
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
1;
|
|
219
|
|
|
|
|
|
|
__END__
|