bryan d foy said to "try quoting the version number." in PREREQ_PM. thanks!
[Business-OnlinePayment-OCV.git] / OCV.pm
1 package Business::OnlinePayment::OCV;
2
3 use strict;
4 use Carp;
5 use Business::OnlinePayment;
6 #use Business::CreditCard;
7 #use Net::SSLeay qw( make_form post_https );
8 use Business::OCV; #qw( :transaction );
9 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG);
10
11 require Exporter;
12
13 @ISA = qw(Exporter AutoLoader Business::OnlinePayment);
14 @EXPORT = qw();
15 @EXPORT_OK = qw();
16 $VERSION = '0.01';
17
18 #Business::OCV exporting is broken
19 use subs qw(TRANS_APPROVED);
20 sub TRANS_APPROVED   (){ '0' }  # transaction status result - approved
21
22 $DEBUG = 0;
23
24
25 sub set_defaults {
26     my $self = shift;
27 #    $self->server('sec.aba.net.au');
28 #    $self->port('443');
29 #    $self->path('/cgi-bin/service/authint');
30     $self->build_subs(qw( account ));
31 }
32
33 sub submit {
34     my $self = shift;
35     my %content = $self->content;
36
37     my $action = lc($content{'action'});
38     if ( $action eq 'normal authorization' ) {
39     } else {
40       croak "$action not (yet) supported";
41     }
42
43     $content{'expiration'} =~ /^(\d+)\D+\d{0,2}(\d{2})$/
44       or croak "unparsable expiration $content{expiration}";
45     my ($month, $year) = ( $1, $2 );
46     $month += 0;
47     $month = "0$month" if $month < 10;
48     my $exp = "$month$year";
49
50     my $ocv = new OCV (
51         Server      => $self->server. ':'. $self->port,
52         ClientID    => $content{login},
53         AccountNum  => $self->account,
54     ) or die "can't create Business::OCV object: $@!";
55
56     my $m = $ocv->purchase(
57       'CardData'   => $content{card_number},
58       'CardExpiry' => $exp,
59       'Amount'     => $content{'amount'} * 100,
60     );
61     croak $@ unless $m;
62
63     warn "Result: ". $m->Result, "\n";
64
65     if ( $m->Result == TRANS_APPROVED ) {
66       $self->is_success(1);
67       $self->result_code($m->Result);
68       $self->authorization($m->PreAuth); #?
69     } else {
70       $self->is_success(0);
71       $self->result_code($m->Result);
72       $self->error_message($m->ResponseText);
73     }
74
75 }
76
77 1;
78 __END__
79
80 =head1 NAME
81
82 Business::OnlinePayment::OCV - OCV backend for Business::OnlinePayment
83
84 =head1 SYNOPSIS
85
86   use Business::OnlinePayment;
87
88   my $tx = new Business::OnlinePayment("OCV");
89   $tx->content(
90       type           => 'CC',
91       login          => 'test', #ClientID
92       action         => 'Authorization Only',
93       description    => 'Business::OnlinePayment test',
94       amount         => '49.95',
95       invoice_number => '100100',
96       name           => 'Tofu Beast',
97       card_number    => '4007000000027',
98       expiration     => '09/02',
99   );
100   $tx->submit();
101
102   if($tx->is_success()) {
103       print "Card processed successfully: ".$tx->authorization."\n";
104   } else {
105       print "Card was rejected: ".$tx->error_message."\n";
106   }
107
108 =head1 DESCRIPTION
109
110 For detailed information see L<Business::OnlinePayment>.
111
112 =head1 NOTE
113
114 =head1 COMPATIBILITY
115
116 This module is a wrapper around Business::OCV written by Benjamin
117 Low <b.d.low@unsw.edu.au>.  Eventually it will be self-contained.
118 See <INSERTURLHERE> for details.
119
120 =head1 AUTHOR
121
122 Ivan Kohler <ivan-ocv@420.am>
123
124 =head1 SEE ALSO
125
126 perl(1). L<Business::OnlinePayment>, L<Business::OCV>.
127
128 =cut
129