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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
package Business::OnlinePayment::Cardcom;
use strict;
use Carp;
use Tie::IxHash;
use Business::OnlinePayment 3;
use Business::OnlinePayment::HTTPS 0.03;
#use Data::Dumper;
use vars qw($VERSION $DEBUG @ISA);
@ISA = qw(Business::OnlinePayment::HTTPS);
$VERSION = '0.02';
$DEBUG = 0;
sub set_defaults {
my $self = shift;
$self->server('secure.cardcom.co.il');
$self->path('/BillGoldPost.aspx');
$self->port('443');
}
# XXX?
# -Identity number
# -Configurable currency
# -Configurable deal code
sub submit {
my($self) = @_;
#warn Dumper($self) if $DEBUG > 1;
$self->remap_fields(
card_number => 'cardnumber',
amount => 'Sum',
login => 'Username',
password => 'userpassword',
cvv2 => 'cvv',
);
my $action = $self->{_content}{'action'};
if ( $action =~ /^\s*credit\s*$/i ) {
$self->{_content}{dealtype} = 51;
$self->{_content}{credittype} = 1;
} elsif ( $action !~ /^\s*normal\s*authorization\s*$/i ) {
die "invalid action";
}
$self->{_content}{'expiration'} =~ /^(\d+)\D+\d*(\d{2})$/
or croak "unparsable expiration ". $self->{_content}{expiration};
my( $month, $year ) = ( $1, $2 );
$month = '0'. $month if $month =~ /^\d$/;
$self->{_content}{cardvalidityyear} = $year;
$self->{_content}{cardvaliditymonth} = $month;
$self->{_content}{amount} = sprintf('%.2f', $self->{_content}{amount} );
$self->{_content}{languages} = 'en';
$self->terminalnumber =~ /^\d+$/ or die "invalid TerminalNumber";
$self->{_content}{TerminalNumber} = $self->terminalnumber;
$self->required_fields(
qw( login password TerminalNumber card_number amount )
);
if($self->test_transaction) {
$self->{_content}{'Username'} = 'gali';
$self->{_content}{'userpassword'} = '7654321';
$self->{_content}{'TerminalNumber'} = '1000';
}
tie my %fields, 'Tie::IxHash', $self->get_fields( $self->fields );
my $post_data = join('&', map "$_=$fields{$_}", keys %fields );
warn "POSTING: ".$post_data if $DEBUG > 1;
my( $page, $response, @reply_headers) = $self->https_post( $post_data );
if ($response !~ /^200/) {
# Connection error
$response =~ s/[\r\n]+/ /g; # ensure single line
$self->is_success(0);
my $diag_message = $response || "connection error";
die $diag_message;
}
$self->server_response($page);
unless ( $page =~ /^(\d+);(\d+);(.*?)$/ ) {
die "unparsable response received from gateway" .
( $DEBUG ? ": $page" : '' );
}
my $result = $1;
my $authorization = $2;
my $message = $3;
$self->result_code($result);
if ( $result == 0 ) {
$self->is_success(1);
$self->authorization($authorization);
} else {
$self->is_success(0);
$self->error_message($message);
}
}
sub fields {
my $self = shift;
qw(
TerminalNumber
Sum
cardnumber
cardvalidityyear
cardvaliditymonth
Username
userpassword
languages
dealtype
credittype
cvv
);
}
sub _info {
{
'info_compat' => '0.01',
'gateway_name' => 'Cardcom',
'gateway_url' => 'http://www.cardcom.co.il',
'module_version' => $VERSION,
'supported_types' => [ 'CC' ],
'token_support' => 0, # well technically the gateway supports it, but we haven't implemented it
'test_transaction' => 1,
'supported_actions' => [
'Normal Authorization',
'Credit',
],
};
}
1;
__END__
=head1 NAME
Business::OnlinePayment::Cardcom - Cardcom backend module for Business::OnlinePayment
=head1 SYNOPSIS
use Business::OnlinePayment::Cardcom;
####
# One step transaction, the simple case.
####
my $tx = new Business::OnlinePayment("Cardcom", 'TerminalNumber'=>1234 );
$tx->content(
type => 'CC',
login => 'Cardcom Username',
password => 'Cardcom Password',
action => 'Normal Authorization',
amount => '49.95',
card_number => '4005550000000019',
expiration => '08/06',
cvv2 => '123',
);
$tx->submit();
if($tx->is_success()) {
print "Card processed successfully: ".$tx->authorization."\n";
} else {
print "Card was rejected: ".$tx->error_message."\n";
}
=head1 SUPPORTED TRANSACTION TYPES
=head2 CC
Content required: type, login, password, action, amount, card_number, expiration.
=head1 PREREQUISITES
Tie::IxHash
=head1 DESCRIPTION
For detailed information see L<Business::OnlinePayment>.
=head1 AUTHOR
Original Author: Erik Levinson
Current Maintainer: Ivan Kohler C<< <ivan-cardcom@freeside.biz> >>
=head1 SEE ALSO
perl(1). L<Business::OnlinePayment>.
=head1 ADVERTISEMENT
Need a complete, open-source back-office and customer self-service solution?
The Freeside software includes support for credit card and electronic check
processing, integrated trouble ticketing, and customer signup and self-service
web interfaces.
http://freeside.biz/freeside/
=cut
|