File Coverage

blib/lib/Business/NETeller/Direct.pm
Criterion Covered Total %
statement 30 59 50.8
branch 2 12 16.6
condition 1 6 16.6
subroutine 7 13 53.8
pod 0 10 0.0
total 40 100 40.0


line stmt bran cond sub pod time code
1             package Business::NETeller::Direct;
2              
3             # $Id: Direct.pm,v 1.4 2003/08/06 02:25:34 sherzodr Exp $
4              
5 1     1   866 use strict;
  1         2  
  1         47  
6 1     1   6 use Carp;
  1         2  
  1         107  
7 1     1   18 use vars ('$GTW', '$VERSION', '$errstr', '$errcode');
  1         2  
  1         1103  
8              
9             $VERSION = '1.00';
10             $GTW = 'https://www.neteller.com/gateway/netdirectv3.cfm';
11              
12             # Preloaded methods go here.
13             sub new {
14 1     1 0 137 my $class = shift;
15 1   33     8 $class = ref($class) || $class;
16              
17 1         10 my $self = {
18             _request_vars => { @_ },
19             _response_vars => { }
20             };
21 1         3 bless $self, $class;
22              
23 1         3 return $self
24             }
25              
26              
27              
28             sub request_vars {
29 2     2 0 79 my $self = shift;
30 2         12 return $self->{_request_vars}
31             }
32              
33             sub response_vars {
34 0     0 0 0 my $self = shift;
35 0         0 return $self->{_response_vars}
36             }
37              
38              
39              
40              
41             sub errstr {
42 0     0 0 0 return $errstr
43             }
44              
45              
46             sub errcode {
47 0     0 0 0 my ($class, $code) = @_;
48              
49 0 0       0 unless ( defined $code ) {
50 0         0 return $errcode
51             }
52              
53             # defining error codes and their respective descriptions
54 0         0 my %codes = (
55             1001 => "incomplete request",
56             1002 => "net_account and/or secure_id fields are not valid",
57             1003 => "net_account, secure_id, merchant_id or amount are not numeric",
58             1004 => "couldn't find merchant id",
59             1005 => "amount is not within the acceptable range",
60             1006 => "problem with your merchant account. Contact the staff",
61             1007 => "no client for given net_account found",
62             1008 => "secure_id doesn't match to provided net_account",
63             1009 => "client account suspended. Contact customer service",
64             1010 => "not enough balance",
65             1011 => "user is not permitted to use his/her account. Contact customer service",
66             1012 => "there is a problem with bank account number. Contact customer service",
67             1013 => "amount is above the limit",
68             1014 => "client account error. Contact customer service"
69             );
70              
71 0         0 return $codes{$code}
72             }
73              
74              
75              
76              
77              
78              
79              
80              
81              
82              
83              
84             # posts the transaction details to $GTW
85             sub post {
86 1     1 0 4 my ($self, %vars) = @_;
87              
88 1         7 while ( my ($k, $v) = each %vars ) {
89 0         0 $self->{_request_vars}->{$k} = $v
90             }
91              
92 1         8 my $ua = $self->user_agent();
93 1         8 my $response = $ua->post($GTW, $self->request_vars);
94              
95 1 50       18809 if ( $response->is_error ) {
96 1         18 $errstr = $response->status_line;
97             return undef
98 1         39 }
99              
100             # if we got this far, transaction details have been posted, and now
101             # is time to parse the details in
102 0         0 $self->{_response_vars} = $self->parse_response_content($response->content_ref);
103              
104 0 0       0 unless ( $self->{_response_vars}->{approval} eq 'yes' ) {
105 0         0 $errcode = $self->{_response_vars}->{error};
106 0         0 $errstr = $self->errcode($errcode);
107             return undef
108 0         0 }
109              
110 0         0 return 1
111             }
112              
113              
114              
115              
116             sub user_agent {
117 1     1 0 3 my $self = shift;
118              
119 1 50       5 if ( defined $self->{_user_agent} ) {
120 0         0 return $self->{_user_agent}
121             }
122              
123 1         1164331 require LWP::UserAgent;
124 1         141200 my $ua = new LWP::UserAgent();
125 1         4365 $ua->agent(sprintf("%s/%.02f (%s)", ref($self), $self->VERSION, $ua->agent));
126              
127 1         122 $self->{_user_agent} = $ua;
128 1         4 return $ua
129             }
130              
131              
132              
133              
134              
135              
136              
137              
138              
139             sub parse_response_content {
140 0     0 0   my ($self, $content) = @_;
141              
142 0 0 0       unless ( defined($content) && (ref($content) eq 'SCALAR') ) {
143 0           croak "parse_reponse_content() usage error"
144             }
145              
146             # this is a lame hack to get it working under < perl.7.1
147 0           $$content =~ s/ISO-8859-1/utf-8/i;
148              
149 0           require XML::Simple;
150 0           my $vars = XML::Simple::XMLin($$content);
151             }
152              
153              
154              
155              
156              
157              
158              
159              
160             sub is_complete {
161 0     0 0   my $self = shift;
162              
163 0 0         my $vars = $self->response_vars() or croak "no response";
164 0           return ($vars->{approval} eq 'yes')
165             }
166              
167              
168              
169              
170              
171              
172              
173              
174              
175             sub dump {
176 0     0 0   my $self = shift;
177              
178 0           require Data::Dumper;
179 0           my $d = new Data::Dumper([$self], [ref $self]);
180 0           return $d->Dump()
181             }
182              
183              
184              
185              
186              
187              
188              
189             package NetDirect;
190             @NetDirect::ISA = ('Business::NETeller::Direct');
191              
192              
193              
194              
195             1;
196             __END__