#################### main pod documentation begin ################### =head1 NAME Zymonic::Decryptor::Message::PaymentGateway - Zymonic Decryptor Message. =head1 SYNOPSIS This Message calls a PaymentGateway to authorise a transaction. =head1 DESCRIPTION This Message calls a PaymentGateway to authorise a transaction. Uses a Zymonic::PaymentGateway object to do the call. =head1 USAGE The message should simply be: { messagetype => 'PaymentGateway', payment_gateway_type => 'Xenco', # or another payment gateway implementation ... (other payment gateway settings) ... ... (payment data details) ... ... (transaction details) ... } The response will be: { error => ... } or { response_code => ..., auth_code => ..., auth_message => ..., referral_phone => ..., csc_message => ... csc_response => ... } =head1 BUGS None we're aware of... =head1 SUPPORT As in the license, Zymonic is provided without warranty or support unless purchased separately, however... If you email zymonic-support@zednax.com your issue will be noted and may receive a response. For security issues, please contact zymonic-security@zednax.com and someone will respond within 8 working hours. =head1 AUTHOR Alex Masidlover et al. CPAN ID: MODAUTHOR Zednax Limited alex.masidlover@zednax.com http://www.zednax.com =head1 COPYRIGHT This program is free software licensed under the... Alfresco Public License 1.0 The full text of the license can be found in the LICENSE file included with this module. Other licenses may be acceptable if including parts of Zymonic in larger projects, please contact Zednax for details. =head1 SEE ALSO Zymonic::PaymentGateway perl(1). =cut #################### main pod documentation end ################### package Zymonic::Decryptor::Message::PaymentGateway; use strict; use warnings; BEGIN { use Exporter (); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = '0.01'; @ISA = qw(Exporter); #Give a hoot don't pollute, do not export more than needed by default @EXPORT = qw(); @EXPORT_OK = qw(); %EXPORT_TAGS = (); } use base 'Zymonic::Decryptor::Message'; use Zymonic::PaymentGateway; use Zymonic::Utils qw(death_handler rethrow_exception); use Time::HiRes qw(usleep); #################### subroutine header begin #################### =head2 respond Usage : my $response = $mh->repsond($in) Purpose : This is the response handler method for decryptor messages. Returns : a response hashref Argument : a message hashref Throws : nothing Comment : See Also : =cut #################### subroutine header end #################### sub respond { my $self = shift; my $in = shift; return { error => 'No Payment Gateway type specified.' } unless $in->{payment_gateway_type}; $self->{decryptor_server}->connection_log("$in->{payment_gateway_type} PaymentGateway Requested"); # check module exists then load it my $pg; my $module = "Zymonic::PaymentGateway::$in->{payment_gateway_type}"; eval { eval "require $module"; $pg = $module->new( parent => $self, config => $self->{decryptor_server}->{config}, DB => $self->{decryptor_server}->{DB} ); } or do { my $err = $@; if ( $err =~ /Can't locate/ ) { return { error => "Cannot find PaymentGateway module: $in->{payment_gateway_type}" }; } else { rethrow_exception($err); } }; return { error => "Unable to create PaymentGateway object" } unless $pg; my $result; my $max_tries = $self->{decryptor_server}->{config}->{payment_gateway_retries} || 3; my $wait = ( $self->{decryptor_server}->{config}->{payment_gateway_wait} || 2 ) * 1000; my $try = 0; foreach $try ( 0 .. $max_tries ) { eval { $result = $pg->authorise($in); last if $result; } or do { my $exception = $@; if ( ref($exception) && $exception->isa('Zymonic::Exception::PaymentGateway::TooManyConnections') ) { # wait and try again usleep($wait); } else { my $err = death_handler( $exception, '', 'return' ); return { error => $err->{message}->{content} }; } }; } if ( $try >= $max_tries ) { return { error => "Unable to make call after $max_tries failed attempts." }; } return $result; } 1;