(no commit message)
[Business-OnlineThirdPartyPayment-Interswitchng.git] / Interswitchng.pm
1 package Business::OnlineThirdPartyPayment::Interswitchng;
2
3 use strict;
4 use Carp;
5 use Business::OnlineThirdPartyPayment 3;
6 use Business::CreditCard;
7 use vars qw($VERSION @ISA $DEBUG);
8
9 @ISA = qw(Business::OnlineThirdPartyPayment);
10 $VERSION = '0.01';
11
12 $DEBUG = 0;
13
14 sub set_defaults {
15   my $self = shift;
16
17   $self->server('webpay.interswitchng.com') unless $self->server;
18   $self->port('443') unless $self->port;
19   $self->path('/webpay_pilot/purchase.aspx') unless $self->path;
20
21 }
22
23 sub reference {
24     my ($self, $data) = @_;
25     $data->{TXNREF} || '';
26 }
27
28 sub submit {
29     my($self) = @_;
30     my %content = $self->content;
31
32     my $action = lc($content{'action'});
33     die 'Interswitchng only supports "Authorization Only" and '.
34         '"Post Authorization" transactions'
35       unless $action eq 'authorization only' || $action eq 'post authorization';
36
37     my @required = qw( login amount reference );
38     unless ($self->transaction_type() eq 'CC' ) {
39       croak("Dummy can't handle transaction type: ".
40             $self->transaction_type());
41     }
42     $self->required_fields(@required);
43
44     $self->remap_fields (
45                           login     => 'CADPID',
46                           password  => 'MERTID',
47                           reference => 'TXNREF',
48                         );
49     %content = $self->content;
50     $content{AMT} = $content{amount} * 100;
51
52     my $url =
53       "https://". $self->server(). ':'. $self->port(). $self->path(). '?'.
54       join( '&', map { "$_=$content{$_}" } qw( CADPID MERTID TXNREF AMT ) );
55     $self->popup_url( $url );
56
57     $self->is_success(1);
58 }
59
60 1;
61 __END__
62
63 =head1 NAME
64
65 Business::OnlineThirdPartyPayment::Interswitchng - Interswitchng Webpay backend for Business::OnlineThirdPartyPayment
66
67 =head1 SYNOPSIS
68
69   use Business::OnlineThirdPartyPayment;
70
71   my $tx = new Business::OnlineThirdPartyPayment("Interswitchng");
72   $tx->content(
73       login          => '87654321', 
74       action         => 'Normal Authorization',
75       description    => 'Business::OnlinePayment test',
76       amount         => '49.95',
77       invoice_number => '100100',
78   );
79   $tx->submit();
80
81   if($tx->is_success()) {
82       print "Card processed successfully: ".$tx->authorization."\n";
83   } else {
84       print "Card was rejected: ".$tx->error_message."\n";
85   }
86
87 =head1 DESCRIPTION
88
89 For detailed information see L<Business::OnlineThirdPartyPayment>.
90
91 =head1 NOTE
92
93 =head1 COMPATIBILITY
94
95 This module implements a payment gateway for Interswitchng's Webpay.
96
97 =head1 AUTHOR
98
99 Jeff Finucane <interswitchng@weasellips.com>
100
101 =head1 SEE ALSO
102
103 perl(1). L<Business::OnlineThirdPartyPayment>.
104
105 =cut
106