initial import
[Business-OnlinePayment-PayConnect.git] / PayConnect.pm
1 package Business::OnlinePayment::PayConnect;
2
3 use strict;
4 use Carp;
5 use Business::OnlinePayment;
6 #use Business::CreditCard;
7 use Net::SSLeay qw( make_form post_https get_https make_headers );
8 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG);
9
10 require Exporter;
11
12 @ISA = qw(Exporter AutoLoader Business::OnlinePayment);
13 @EXPORT = qw();
14 @EXPORT_OK = qw();
15 $VERSION = '0.01';
16
17 $DEBUG = 0;
18
19 sub set_defaults {
20     my $self = shift;
21
22     #test
23     $self->server('zavijah.e-ebi.net');
24     $self->port('443');
25     $self->path('/rtv/servlet/aio');
26
27     $self->build_subs(qw( partner ));
28 }
29
30 sub revmap_fields {
31     my($self, %map) = @_;
32     my %content = $self->content();
33     foreach(keys %map) {
34         $content{$_} = ref($map{$_})
35                          ? ${ $map{$_} }
36                          : $content{$map{$_}};
37     }
38     $self->content(%content);
39 }
40
41 sub submit {
42     my $self = shift;
43     my %content = $self->content();
44
45     my $action = lc($content{'action'});
46     if ( $action eq 'authorization only' ) {
47     } else {
48       croak "$action not (yet) supported";
49     }
50     
51     my $type = lc($content{'type'});
52     if ( $type eq 'lec' ) {
53     } else {
54       croak "$type not (yet) supported";
55     }
56
57     $content{'zip'} =~ s/\D//g;
58     $content{'zip'} =~ /^(\d{5})(\d*)$/;
59     my($zip, $zip4) = ($1, $2);
60
61     my $phone = $content{'phone'};
62     $phone =~ s/\D//g;
63
64     $self->revmap_fields(
65       ebiinfo   => \'AIO-1.0',
66       clientid  => 'login',
67       password  => 'password',
68       partner   => \($self->partner()),
69       #sysid
70       transtype => \'A', #action
71       paytype   => \'lec', #type
72       trackid   => 'invoice_number',
73       acctid    => 'customer_id',
74       billname  => 'name',
75       billaddr1 => 'address',
76       #billaddr2 =>
77       billcity  => 'city',
78       billstate => 'state',
79       billzip   => \$zip,
80       billzip4  => \$zip4,
81       amt       => 'amount',
82
83       #LEC
84       #ani
85       btn       => \$phone,
86       #dni
87       #traffic
88       #planid
89       #pincode
90     );
91
92     my %post_data = $self->get_fields(qw(
93         ebiinfo clientid password partner transtype paytype trackid acctid
94         billname billaddr1 billcity billstate billzip billzip4 amt btn
95     ));
96
97     my $s = $self->server();
98     my $p = $self->port();
99     my $t = $self->path();
100
101     my $pd = make_form(%post_data);
102     my($page,$server_response,%headers) = post_https($s,$p,$t,'',$pd);
103
104     #warn join('-',%headers);
105     #warn $page;
106     my %response = map { split('=',$_,2) } split(/\|/,$page);
107     #warn "$_: $response{$_}\n" foreach keys %response;
108
109     if ( $response{'response'} eq '0000' ) {
110       $self->is_success(1);
111       $self->result_code('0000');
112       $self->authorization($response{'trackid'});
113     } else {
114       $self->is_success(0);
115       $self->result_code($response{'response'});
116       $self->error_message($response{'respmsg'});
117     }
118
119 }
120
121 1;
122 __END__
123
124 =head1 NAME
125
126 Business::OnlinePayment::PayConnect - PaymentOne (formerly eBillit) PayConnect  backend for Business::OnlinePayment
127
128 =head1 SYNOPSIS
129
130   use Business::OnlinePayment;
131
132   my $tx = new Business::OnlinePayment("PayConnect",
133     'partner' => '',
134   );
135   $tx->content(
136       type           => 'LEC',
137       login          => 'test', #ClientID
138       password       => 'test',
139       action         => 'Authorization Only',
140       description    => 'Business::OnlinePayment test',
141       amount         => '49.95',
142       invoice_number => '100100',
143       name           => 'Tofu Beast',
144       phone          => '4155554321',
145   );
146   $tx->submit();
147
148   if($tx->is_success()) {
149       print "LEC billing authorized successfully: ".$tx->authorization."\n";
150   } else {
151       print "LEC billing was rejected: ".$tx->error_message."\n";
152   }
153
154 =head1 DESCRIPTION
155
156 For detailed information see L<Business::OnlinePayment>.
157
158 =head1 NOTE
159
160 This module only implements 'LEC' (phone bill billing) functionality at this
161 time.  Credit card and ACH transactions are not (yet) supported.
162
163 =head1 COMPATIBILITY
164
165 This module implements an interface the "HTTPS AIO Validation Protocol
166 version 3.0" of PaymentOne (formerly eBillit) PayConnect
167 <http://www.paymentone.com/products/paycon.asp>.  Unfortunately, no
168 documentation is publicly available.
169
170 =head1 AUTHOR
171
172 Ivan Kohler <ivan-jettis@420.am>
173
174 =head1 SEE ALSO
175
176 perl(1). L<Business::OnlinePayment>
177
178 =cut
179