conditionally send port, always send TRANTYPE=00 noise, and be case insensitive to...
[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     my @refkey = grep { /txnref/i } keys %{$data}; # @#$%#@%!
27     my $refkey = $refkey[0] || '';  # please don't give me 2
28     $data->{$refkey} || '';
29 }
30
31 sub submit {
32     my($self) = @_;
33     my %content = $self->content;
34
35     my $action = lc($content{'action'});
36     die 'Interswitchng only supports "Authorization Only" and '.
37         '"Post Authorization" transactions'
38       unless $action eq 'authorization only' || $action eq 'post authorization';
39
40     my @required = qw( login amount reference );
41     unless ($self->transaction_type() eq 'CC' ) {
42       croak("Dummy can't handle transaction type: ".
43             $self->transaction_type());
44     }
45     $self->required_fields(@required);
46
47     $self->remap_fields (
48                           login     => 'CADPID',
49                           password  => 'MERTID',
50                           reference => 'TXNREF',
51                         );
52     %content = $self->content;
53     $content{AMT} = $content{amount} * 100;
54     $content{TRANTYPE} = '00';
55
56     my $url =
57       "https://". $self->server().
58       ($self->port != 443 ? ':'. $self->port() : ''). $self->path(). '?'.
59       join( '&', map { "$_=$content{$_}" }
60                  qw( CADPID MERTID TXNREF AMT TRANTYPE )
61       );
62     $self->popup_url( $url );
63
64     $self->is_success(1);
65 }
66
67 1;
68 __END__
69
70 =head1 NAME
71
72 Business::OnlineThirdPartyPayment::Interswitchng - Interswitchng Webpay backend for Business::OnlineThirdPartyPayment
73
74 =head1 SYNOPSIS
75
76   use Business::OnlineThirdPartyPayment;
77
78   my $tx = new Business::OnlineThirdPartyPayment("Interswitchng");
79   $tx->content(
80       login          => '87654321', 
81       action         => 'Normal Authorization',
82       description    => 'Business::OnlinePayment test',
83       amount         => '49.95',
84       invoice_number => '100100',
85   );
86   $tx->submit();
87
88   if($tx->is_success()) {
89       print "Card processed successfully: ".$tx->authorization."\n";
90   } else {
91       print "Card was rejected: ".$tx->error_message."\n";
92   }
93
94 =head1 DESCRIPTION
95
96 For detailed information see L<Business::OnlineThirdPartyPayment>.
97
98 =head1 NOTE
99
100 =head1 COMPATIBILITY
101
102 This module implements a payment gateway for Interswitchng's Webpay.
103
104 =head1 AUTHOR
105
106 Jeff Finucane <interswitchng@weasellips.com>
107
108 =head1 SEE ALSO
109
110 perl(1). L<Business::OnlineThirdPartyPayment>.
111
112 =cut
113