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
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,
$DEBUG = exists($options{debug}) ? $options{debug} : $DEBUG;
- $self->port(443);
+ $self->port($options{'port'});
$self->server($options{'url'});
$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;
}
# 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);
# (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)');
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
sub _get_xml_template {
my $action = shift;
- my $xml_template;
+ my $xml_template = q|<Request >
+ <MerchantData>
+ <Platform>[% auth.platform %]</Platform>
+ <UserID>[% auth.userid %]</UserId>
+ <GID>[% auth.gid %]</GID>
+ <Tid>[% auth.tid %]</Tid>
+ </MerchantData>
+ |;
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</Request>";
+
return $xml_template;
}
sub _get_xml_template_charge {
- my $xml_template = q|<Request >
- <MerchantData>
- <Platform>[% auth.platform %]</Platform>
- <UserID>[% auth.userid %]</UserId>
- <GID>[% auth.gid %]</GID>
- <Tid>[% auth.tid %]</Tid>
- </MerchantData>
- <ProcessPayment>
+ my $xml_template = q|<ProcessPayment>
<Amount>[% payment.amount %]</Amount>
<Trk1>[% payment.track1 %]</Trk1>
<Trk2>[% payment.track2 %]</Trk2>
<PurchaseItems>
[% level3.purchase_items %]
</PurchaseItems>
- </Level3PurchaseInfo>
-</Request>|;
+ </Level3PurchaseInfo>|;
return $xml_template;
}
}
sub _get_xml_template_void {
- my $xml_template = q|<Request >
- <MerchantData>
- <Platform>[% auth.platform %]</Platform>
- <UserID>[% auth.userid %]</UserId>
- <GID>[% auth.gid %]</GID>
- <Tid>[% auth.tid %]</Tid>
- </MerchantData>
- <ProcessVoid>
- <Amount></Amount>
+ my $xml_template = q|<ProcessVoid>
+ <Amount>[% payment.amount %]</Amount>
<AccountNumber>[% payment.account_number %]</AccountNumber>
<ExpirationMonth>[% payment.exp_month %]</ExpirationMonth>
<ExpirationYear>[% payment.exp_year %]</ExpirationYear>
<TransactionDate/>
<IndustryType1>[% payment.industry_type %]</IndustryType1>
<ApplicationId>[% payment.appid %]</ApplicationId>
- </ProcessVoid>
-</Request>|;
+ </ProcessVoid>|;
return $xml_template;
}
sub _get_xml_template_refund {
- my $xml_template = q|<Request>
- <MerchantData>
- <Platform>[% auth.platform %]</Platform>
- <UserID>[% auth.userid %]</UserId>
- <GID>[% auth.gid %]</GID>
- <Tid>[% auth.tid %]</Tid>
- </MerchantData>
- <ProcessRefund>
+ my $xml_template = q|<ProcessRefund>
<Amount>[% payment.amount %]</Amount>
<AccountNumber>[% payment.account_number %]</AccountNumber>
<ExpirationMonth>[% payment.exp_month %]</ExpirationMonth>
<ExpirationYear>[% payment.exp_year %]</ExpirationYear>
<ApplicationId>[% payment.appid %]</ApplicationId>
- </ProcessRefund>
-</Request>|;
+ </ProcessRefund>|;
return $xml_template;
}
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?