From c9bda79a9217f134190a2d5633cfe62d793162d6 Mon Sep 17 00:00:00 2001 From: Alex Brelsfoard Date: Tue, 3 Feb 2015 05:50:47 -0500 Subject: [PATCH] cleaning some of the code and converting to using B::OP::HTTPS --- vSecureProcessing.pm | 152 +++++++++++++++++++++++++-------------------------- 1 file changed, 73 insertions(+), 79 deletions(-) diff --git a/vSecureProcessing.pm b/vSecureProcessing.pm index fcd6e69..cd1e30f 100644 --- a/vSecureProcessing.pm +++ b/vSecureProcessing.pm @@ -1,22 +1,20 @@ package Business::OnlinePayment::vSecureProcessing; use strict; -use Data::Dumper; use URI::Escape; use Carp; -use Business::OnlinePayment; -use LWP::UserAgent; -use HTTP::Request::Common; - -use Template; # construct XML requests -use XML::Simple; # parse XML responses +use Template; +use XML::Simple; +use Data::Dumper; -use vars qw($VERSION $DEBUG @ISA $myself $server_root $port); +use Business::OnlinePayment; +use Business::OnlinePayment::HTTPS; +use vars qw($VERSION $DEBUG @ISA $me); -@ISA = qw(Business::OnlinePayment); -$DEBUG = 0; +@ISA = qw(Business::OnlinePayment::HTTPS); +$DEBUG = 3; $VERSION = '0.01'; -$myself = 'Business::OnlinePayment::vSecureProcessing'; +$me = 'Business::OnlinePayment::vSecureProcessing'; # $server: http://dvrotsos2.kattare.com @@ -73,7 +71,17 @@ my %action_mapping = ( sub set_defaults { my $self = shift; my %options = @_; - + + # inistialize standard B::OP attributes + $self->is_success(0); + $self->$_( '' ) for qw/authorization + result_code + error_message + server + port + path + server_response/; + # B::OP creates the following accessors: # server, port, path, test_transaction, transaction_type, # server_response, is_success, authorization, @@ -86,7 +94,7 @@ sub set_defaults { $DEBUG = exists($options{debug}) ? $options{debug} : $DEBUG; - $self->port(443); + $self->port($options{'port'}); $self->server($options{'url'}); @@ -149,11 +157,8 @@ sub submit { $self->$_( '' ) for qw/authorization result_code error_message - server - port - path server_response/; - + # clean and process the $self->content info $self->process_content(); my %content = $self->content; @@ -251,28 +256,21 @@ sub submit { } # read in the appropriate xml template - my $xml_template = _get_xml_template( $action ); + my $xml_template .= _get_xml_template( $action ); # create a template object. my $tt = Template->new(); # populate the XML template. my $xml_data; $tt->process( \$xml_template, $template_vars, \$xml_data ) || croak $tt->error(); - warn "XML:\n$xml_data\n" if $DEBUG > 2; - - - my $ua = LWP::UserAgent->new; - my $page = $ua->post( $self->url . $self->path, - [ - 'param' => uri_escape($xml_data), - ], - 'content-type' => 'multipart/form-data' - ); - - warn "HTTPS Response: \n".Dumper($page)."\n" if $DEBUG > 1; + 44rewdwarn "XML:\n$xml_data\n" if $DEBUG > 2; + + my $opts = {'headers' => {}, 'Content-Type' => 'multipart/form-data'}; + my $params = {param => $xml_data}; + my ( $page, $server_response, %headers ) = $self->https_post( $opts, $params ); # store the server response. - $self->server_response($page->status_line); + $self->server_response($server_response); # parse the result page. $self->parse_response($page); @@ -282,8 +280,10 @@ sub submit { # (vSecureProcessing seems to have a failure mode where they return the full # original request including card number) $self->error_message( - "(HTTPS response: ".$page->status_line.") ". - "(Raw HTTPS content: ".$page->content.")" + "(HTTPS response: ".$server_response.") ". + "(HTTPS headers: ". + join(", ", map { "$_ => ". $headers{$_} } keys %headers ). ") ". + "(Raw HTTPS content: ".$page.")" ); } else { $self->error_message('No error information was returned by vSecureProcessing (enable debugging for raw HTTPS response)'); @@ -297,13 +297,13 @@ sub parse_response { my $self = shift; my $page = shift; - if ($page->is_success) { - my $response = XMLin($page->content); + if ($self->server_response =~ /^200/) { + my $response = XMLin($page); $self->result_code($response->{Status}); $self->avs_response($response->{AvsResponse}); $self->cvv_response($response->{CvvResponse}); $self->is_success($self->result_code() eq '0' ? 1 : 0); - if ($self->is_success) { + if ($self->is_success()) { $self->authorization($response->{AuthIdentificationResponse}); } # fill in error_message if there is is an error @@ -325,44 +325,46 @@ sub parse_response { sub _get_xml_template { my $action = shift; - my $xml_template; + my $xml_template = q| + + [% auth.platform %] + [% auth.userid %] + [% auth.gid %] + [% auth.tid %] + + |; if ($action eq 'charge') { - $xml_template = _get_xml_template_charge(); + $xml_template .= _get_xml_template_charge(); }elsif($action eq 'void') { - $xml_template = _get_xml_template_void(); + $xml_template .= _get_xml_template_void(); }elsif($action eq 'authorize') { - $xml_template = _get_xml_template_auth(); + $xml_template .= _get_xml_template_auth(); }elsif($action eq 'authorize_cancel') { - $xml_template = _get_xml_template_auth_cancel(); + $xml_template .= _get_xml_template_auth_cancel(); }elsif($action eq 'refund') { - $xml_template = _get_xml_template_refund(); + $xml_template .= _get_xml_template_refund(); }elsif($action eq 'capture') { - $xml_template = _get_xml_template_capture(); + $xml_template .= _get_xml_template_capture(); }elsif($action eq 'create_token') { - $xml_template = _get_xml_template_create_token(); + $xml_template .= _get_xml_template_create_token(); }elsif($action eq 'delete_token') { - $xml_template = _get_xml_template_delete_token(); + $xml_template .= _get_xml_template_delete_token(); }elsif($action eq 'query_token') { - $xml_template = _get_xml_template_query_token(); + $xml_template .= _get_xml_template_query_token(); }elsif($action eq 'update_exp_date') { - $xml_template = _get_xml_template_update_exp_date(); + $xml_template .= _get_xml_template_update_exp_date(); }elsif($action eq 'update_token') { - $xml_template = _get_xml_template_update_token(); + $xml_template .= _get_xml_template_update_token(); } + $xml_template .= "\n"; + return $xml_template; } sub _get_xml_template_charge { - my $xml_template = q| - - [% auth.platform %] - [% auth.userid %] - [% auth.gid %] - [% auth.tid %] - - + my $xml_template = q| [% payment.amount %] [% payment.track1 %] [% payment.track2 %] @@ -409,8 +411,7 @@ sub _get_xml_template_charge { [% level3.purchase_items %] - -|; + |; return $xml_template; } @@ -446,15 +447,8 @@ sub _parse_line_items { } sub _get_xml_template_void { - my $xml_template = q| - - [% auth.platform %] - [% auth.userid %] - [% auth.gid %] - [% auth.tid %] - - - + my $xml_template = q| + [% payment.amount %] [% payment.account_number %] [% payment.exp_month %] [% payment.exp_year %] @@ -462,28 +456,19 @@ sub _get_xml_template_void { [% payment.industry_type %] [% payment.appid %] - -|; + |; return $xml_template; } sub _get_xml_template_refund { - my $xml_template = q| - - [% auth.platform %] - [% auth.userid %] - [% auth.gid %] - [% auth.tid %] - - + my $xml_template = q| [% payment.amount %] [% payment.account_number %] [% payment.exp_month %] [% payment.exp_year %] [% payment.appid %] - -|; + |; return $xml_template; } @@ -646,6 +631,15 @@ Original author: Alex Brelsfoard Current maintainer: Alex Brelsfoard +=head1 COPYRIGHT + +Copyright (c) 2015 Freeside Internet Services, Inc. + +All rights reserved. + +This program is free software; you can redistribute it and/or modify it under +the same terms as Perl itself. + =head1 ADVERTISEMENT Need a complete, open-source back-office and customer self-service solution? -- 2.11.0