require password
[Business-OnlinePayment-IPPay.git] / IPPay.pm
index 963ba5b..3d1582d 100644 (file)
--- a/IPPay.pm
+++ b/IPPay.pm
@@ -11,7 +11,7 @@ use Business::OnlinePayment::HTTPS;
 use vars qw($VERSION $DEBUG @ISA $me);
 
 @ISA = qw(Business::OnlinePayment::HTTPS);
-$VERSION = '0.07_01';
+$VERSION = '0.09_02';
 $VERSION = eval $VERSION; # modperlstyle: convert the string into a number
 
 $DEBUG = 0;
@@ -46,9 +46,9 @@ sub set_defaults {
     my %opts = @_;
 
     # standard B::OP methods/data
-    $self->server('gateway17.jetpay.com') unless $self->server;
+    $self->server('gtwy.ippay.com') unless $self->server;
     $self->port('443') unless $self->port;
-    $self->path('/jetpay') unless $self->path;
+    $self->path('/ippay') unless $self->path;
 
     $self->build_subs(qw( order_number avs_code cvv2_response
                           response_page response_code response_headers
@@ -99,20 +99,25 @@ sub map_fields {
         'void'                            => 'VOIDACH',
         'credit'                          => 'REVERSAL',
       );
+
     if ($self->transaction_type eq 'CC') {
       $content{'TransactionType'} = $actions{$action} || $action;
-    }elsif ($self->transaction_type eq 'ECHECK') {
-      $content{'TransactionType'} = $check_actions{$action} || $action;
-    }
+    } elsif ($self->transaction_type eq 'ECHECK') {
 
+      $content{'TransactionType'} = $check_actions{$action} || $action;
 
-    # ACCOUNT TYPE MAP
-    my %account_types = ('personal checking'   => 'Checking',
-                         'personal savings'    => 'Savings',
-                         'business checking'   => 'BusinessCk',
-                        );
-    $content{'account_type'} = $account_types{lc($content{'account_type'})}
-                               || $content{'account_type'};
+      # ACCOUNT TYPE MAP
+      my %account_types = ('personal checking'   => 'CHECKING',
+                           'personal savings'    => 'SAVINGS',
+                           'business checking'   => 'CHECKING',
+                           'business savings'    => 'SAVINGS',
+                           #not technically B:OP valid i guess?
+                           'checking'            => 'CHECKING',
+                           'savings'             => 'SAVINGS',
+                          );
+      $content{'account_type'} = $account_types{lc($content{'account_type'})}
+                                 || $content{'account_type'};
+    }
 
     $content{Origin} = 'RECURRING' 
       if ($content{recurring_billing} &&$content{recurring_billing} eq 'YES' );
@@ -172,7 +177,7 @@ sub submit {
   $self->is_success(0);
   $self->map_fields();
 
-  my @required_fields = qw(action login type);
+  my @required_fields = qw(action login password type);
 
   my $action = lc($self->{_content}->{action});
   my $type = $self->transaction_type();
@@ -213,6 +218,9 @@ sub submit {
   foreach ( keys ( %{($self->{_defaults})} ) ) {
     $content{$_} = $self->{_defaults}->{$_} unless exists($content{$_});
   }
+  if ($self->test_transaction()) {
+    $content{'login'} = 'TESTTERMINAL';
+  }
   $self->content(%content);
 
   $self->required_fields(@required_fields);
@@ -225,12 +233,6 @@ sub submit {
     }
   }
 
-  if ($self->test_transaction()) {
-    $self->server('test1.jetpay.com');
-    $self->port('443');
-    $self->path('/jetpay');
-  }
-
   my $transaction_id = $content{'order_number'};
   unless ($transaction_id) {
     my ($page, $server_response, %headers) = $self->https_get('dummy' => 1);
@@ -283,6 +285,8 @@ sub submit {
 
   tie my %ach, 'Tie::IxHash',
     $self->revmap_fields(
+                          #wtf, this is a "Type"" attribute of the ACH element,
+                          # not a child element like the others
                           #AccountType         => 'account_type',
                           AccountNumber       => 'account_number',
                           ABA                 => 'routing_code',
@@ -362,7 +366,7 @@ sub submit {
                           UserHost            => 'UserHost',
                           UDField1            => 'UDField1',
                           UDField2            => 'UDField2',
-                          UDField3            => 'UDField3',
+                          UDField3            => \"$me $VERSION", #'UDField3',
                           ActionCode          => 'ActionCode',
                           IndustryInfo        => \%industryinfo,
                           ShippingInfo        => \%shippinginfo,
@@ -395,7 +399,7 @@ sub submit {
     if (  exists($response->{ActionCode}) && !exists($response->{ErrMsg})) {
       $self->error_message($response->{ResponseText});
     }else{
-      $self->error_message($response->{Errmsg});
+      $self->error_message($response->{ErrMsg});
     }
 #  }else{
 #    $self->error_message("Server Failed");
@@ -435,7 +439,16 @@ sub _error_response {
 
 sub _xmlwrite {
   my ($self, $writer, $item, $value) = @_;
-  $writer->startTag($item);
+
+  my %att = ();
+  if ( $item eq 'ACH' ) {
+    $att{'Type'} = $self->{_content}->{'account_type'}
+      if $self->{_content}->{'account_type'}; #necessary so we don't pass empty?
+    $att{'SEC'}  = 'PPD';
+  }
+
+  $writer->startTag($item, %att);
+
   if ( ref( $value ) eq 'HASH' ) {
     foreach ( keys ( %$value ) ) {
       $self->_xmlwrite($writer, $_, $value->{$_});
@@ -443,6 +456,7 @@ sub _xmlwrite {
   }else{
     $writer->characters($value);
   }
+
   $writer->endTag($item);
 }
 
@@ -574,7 +588,6 @@ from content(%content):
       UserHost            => 'UserHost',
       UDField1            => 'UDField1',
       UDField2            => 'UDField2',
-      UDField3            => 'UDField3',
       ActionCode          => 'ActionCode',
       IndustryInfo
         Type                => 'IndustryInfo',
@@ -593,6 +606,8 @@ from content(%content):
 
 =head1 COMPATIBILITY
 
+Version 0.07 changes the server name and path for IPPay's late 2012 update.
+
 Business::OnlinePayment::IPPay uses IPPay XML Product Specifications version
 1.1.2.