File Coverage

blib/lib/Business/OnlinePayment/Iridium/Action.pm
Criterion Covered Total %
statement 15 45 33.3
branch 0 6 0.0
condition 0 3 0.0
subroutine 5 9 55.5
pod 3 3 100.0
total 23 66 34.8


line stmt bran cond sub pod time code
1             package Business::OnlinePayment::Iridium::Action;
2              
3 1     1   640 use Moose::Role;
  1         3930  
  1         4  
4 1     1   5074 use Template;
  1         13500  
  1         30  
5 1     1   425 use LWP::UserAgent ();
  1         31813  
  1         25  
6 1     1   9 use HTTP::Request ();
  1         2  
  1         18  
7 1     1   569 use XML::Simple ();
  1         6298  
  1         352  
8              
9             # PODNAME: Business::OnlinePayment::Iridium::Action
10             # ABSTRACT: Send / receive data to / from PayVector
11              
12              
13             sub SERVERS {
14 0     0 1   return ( 'https://gw1.iridiumcorp.net/', 'https://gw2.iridiumcorp.net/', 'https://gw3.iridiumcorp.net/' );
15             }
16              
17             has 'MerchantID' => (
18             isa => 'Str',
19             is => 'rw',
20             required => '1'
21             );
22              
23             has 'Password' => (
24             isa => 'Str',
25             is => 'rw',
26             required => '1'
27             );
28              
29             has 'CurrencyCode' => (
30             isa => 'Int',
31             is => 'rw',
32             default => '826' # GBP
33             );
34              
35             has 'PassOutData' => (
36             isa => 'Str',
37             is => 'rw',
38             required => '0'
39             );
40              
41             has '_user_agent' => (
42             isa => 'LWP::UserAgent',
43             is => 'ro',
44             default => sub {
45             return LWP::UserAgent->new( agent => 'Business::OnlinePayment::Iridium',
46             );
47             }
48             );
49              
50             has '_type' => (
51             isa => 'Str',
52             is => 'ro',
53             lazy_build => '1'
54             );
55              
56             requires '_build__type';
57              
58             requires 'template';
59              
60             sub _build_req_content {
61 0     0     my $self = shift;
62             my $vars = {
63             map {
64 0           my $attr_name = $_->name;
  0            
65 0           $attr_name => $self->$attr_name
66             } $self->meta->get_all_attributes
67             };
68 0           my ( $template, $output ) = ( $self->template, '' );
69 0           my $tt = Template->new();
70 0 0         $tt->process( \$template, $vars, \$output ) || confess $tt->error;
71 0           return $output;
72             }
73              
74              
75             sub request {
76 0     0 1   my $self = shift;
77 0           my $content = $self->_build_req_content;
78 0           my $action_url = 'https://www.thepaymentgateway.net/';
79 0           my $ua = $self->_user_agent;
80 0           my @SERVERS = $self->SERVERS;
81              
82 0           my $req = HTTP::Request->new( POST => $SERVERS[0] );
83 0           $req->content_type('text/xml; charset=UTF-8');
84 0           $req->header( 'SOAPAction' => $action_url . $self->_type );
85 0           $req->content($content);
86 0           $req->content_length( length($content) );
87 0           my $res = $ua->request($req);
88              
89 0 0         if ( $res->is_success ) {
90 0           return $self->parse_response( $res->content );
91             }
92             else {
93 0           $req->uri( $SERVERS[1] );
94 0           $res = $ua->request($req);
95              
96 0 0 0       if ( $res->is_success && $res->content ) {
97 0           return $self->parse_response( $res->content );
98             }
99             else {
100 0           confess $res->status_line;
101             }
102             }
103             }
104              
105              
106             sub parse_response {
107 0     0 1   my ( $self, $content ) = @_;
108 0           my $parser = XML::Simple->new;
109 0           return $parser->XMLin($content);
110             }
111              
112             1;
113              
114             __END__
115              
116             =pod
117              
118             =encoding UTF-8
119              
120             =head1 NAME
121              
122             Business::OnlinePayment::Iridium::Action - Send / receive data to / from PayVector
123              
124             =head1 VERSION
125              
126             version 1.03
127              
128             =head2 SERVERS
129              
130             List of 3 servers to send payment attempts to
131              
132             =head2 request
133              
134             Send our request to PayVector
135              
136             =head2 parse_response
137              
138             Turn the PayVector response into XML
139              
140             =head1 AUTHOR
141              
142             [ 'Gavin Henry <ghenry@surevoip.co.uk>', 'Wallace Reis <reis.wallace@gmail.com>' ]
143              
144             =head1 COPYRIGHT AND LICENSE
145              
146             This software is copyright (c) 2017 by [ 'Gavin Henry', 'Wallace Reis' ].
147              
148             This is free software; you can redistribute it and/or modify it under
149             the same terms as the Perl 5 programming language system itself.
150              
151             =cut