Added UUID support
[Business-OnlinePayment-InternetSecure.git] / InternetSecure.pm
index 85bb05e..34acc97 100755 (executable)
@@ -37,8 +37,9 @@ sub set_defaults {
        $self->path('/process.cgi');
 
        $self->build_subs(qw(
-                               receipt_number  sales_number
-                               card_type
+                               receipt_number  sales_number    uuid    guid
+                               date
+                               card_type       cardholder
                                total_amount
                                avs_response    cvv2_response
                        ));
@@ -56,18 +57,6 @@ sub get_fields {
        return %new;
 }
 
-# OnlinePayment's remap_fields is buggy, so we simply rewrite it
-#
-sub remap_fields {
-       my ($self, %map) = @_;
-
-       my %content = $self->content();
-       foreach (keys %map) {
-               $content{$map{$_}} = delete $content{$_};
-       }
-       $self->content(%content);
-}
-
 # Combine get_fields and remap_fields for convenience
 #
 sub get_remap_fields {
@@ -212,10 +201,11 @@ sub to_xml {
        }
 
        xml_out(\%data,
-               NoAttr => 1,
-               RootName => 'TranxRequest',
-               SuppressEmpty => undef,
-               XMLDecl => '<?xml version="1.0" encoding="utf-8" standalone="yes"?>',
+               NoAttr          => 1,
+               NumericEscape   => 2,
+               RootName        => 'TranxRequest',
+               SuppressEmpty   => undef,
+               XMLDecl         => '<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>',
        );
 }
 
@@ -227,7 +217,7 @@ sub infuse {
 
        while (my ($k, $v) = each %map) {
                no strict 'refs';
-               $self->$v($data->{$k});
+               $self->$k($data->{$v});
        }
 }
 
@@ -237,6 +227,8 @@ sub parse_response {
        my ($self, $response) = @_;
 
        $self->server_response($response);
+
+       local $/ = "\n";  # Make sure to avoid bug #17687
        
        $response = xml_in($response,
                        ForceArray => [qw(product flag)],
@@ -248,17 +240,23 @@ sub parse_response {
        my $code = $self->result_code($response->{Page});
        $self->is_success($code eq '2000' || $code eq '90000' || $code eq '900P1');
 
-       $self->infuse($response, qw(
-                       ReceiptNumber           receipt_number
-                       SalesOrderNumber        sales_number
-                       CardType                card_type
-                       Page                    result_code
-                       ApprovalCode            authorization
-                       Verbiage                error_message
-                       TotalAmount             total_amount
-                       AVSResponseCode         avs_response
-                       CVV2ResponseCode        cvv2_response
-               ));
+       $self->infuse($response,
+                       result_code     => 'Page',
+                       error_message   => 'Verbiage',
+                       authorization   => 'ApprovalCode',
+                       avs_response    => 'AVSResponseCode',
+                       cvv2_response   => 'CVV2ResponseCode',
+
+                       receipt_number  => 'ReceiptNumber',
+                       sales_number    => 'SalesOrderNumber',
+                       uuid            => 'GUID',
+                       guid            => 'GUID',
+
+                       date            => 'Date',
+                       cardholder      => 'xxxName',
+                       card_type       => 'CardType',
+                       total_amount    => 'TotalAmount',
+                       );
        
        # Completely undocumented field that sometimes override <Verbiage>
        $self->error_message($response->{Error}) if $response->{Error};
@@ -284,15 +282,16 @@ sub submit {
                                undef,
                                make_form(
                                        xxxRequestMode => 'X',
-                                       xxxRequestData => Encode::encode_utf8(
-                                                               $self->to_xml
-                                                         ),
+                                       xxxRequestData => $self->to_xml,
                                )
                        );
 
        croak 'Error connecting to server' unless $page;
        croak 'Server responded, but not in XML' unless $page =~ /^<\?xml/;
 
+       # The response is marked UTF-8, but it's really Latin-1.  Sigh.
+       $page =~ s/^(<\?xml.*?) encoding="utf-8"/$1 encoding="iso-8859-1"/si;
+
        $self->parse_response($page);
 }
 
@@ -470,10 +469,28 @@ InternetSecure transactions.
 Sales order number of this transaction.  This is a number, unique to each
 merchant, which is incremented by 1 each time.
 
+=item uuid()
+
+Universally Unique Identifier associated to this transaction.  This is a
+128-bit value returned as a 36-character string such as
+C<f81d4fae-7dec-11d0-a765-00a0c91e6bf6>.  See RFC 4122 for more details on
+UUIDs.
+
+B<guid>() is provided as an alias to this method.
+
+=item date()
+
+Date and time of the transaction.  Format is C<YYYY/MM/DD hh:mm:ss>.
+
 =item total_amount()
 
 Total amount billed for this order, including taxes.
 
+=item cardholder()
+
+Cardholder's name.  This is currently a mere copy of the B<name> field passed
+to B<submit()>.
+
 =item card_type()
 
 Type of the credit card used for the submitted order, being one of the