| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WebSphere::Payment; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 1360 | use HTTP::Headers; | 
|  | 1 |  |  |  |  | 8398 |  | 
|  | 1 |  |  |  |  | 31 |  | 
| 4 | 1 |  |  | 1 |  | 770 | use HTTP::Request; | 
|  | 1 |  |  |  |  | 17158 |  | 
|  | 1 |  |  |  |  | 35 |  | 
| 5 | 1 |  |  | 1 |  | 987 | use LWP::UserAgent; | 
|  | 1 |  |  |  |  | 24276 |  | 
|  | 1 |  |  |  |  | 36 |  | 
| 6 | 1 |  |  | 1 |  | 10 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 46 |  | 
| 7 | 1 |  |  |  |  | 2679 | use vars qw($VERSION $defaultpmurl $defaultcurrency $ua $h $defaultpmadmin $defaultgwhost | 
| 8 |  |  |  |  |  |  | $defaultgwport $defaultsetprof $defaultsignbrand $defaultaccountnumber $defaultcassette | 
| 9 | 1 |  |  | 1 |  | 6 | $defaultmerole $defaultpmhost $defaultaccounttitle); | 
|  | 1 |  |  |  |  | 2 |  | 
| 10 |  |  |  |  |  |  | $VERSION = '1.21'; | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | #Default Values | 
| 14 |  |  |  |  |  |  | $defaultpmadmin  = 'YWRtaW46YWRtaW4=';  #('user:password' base64 encoded) | 
| 15 |  |  |  |  |  |  | $defaultpmurl = 'http://localhost/webapp/PaymentManager/PaymentServlet'; | 
| 16 |  |  |  |  |  |  | $defaultpmhost = 'localhost'; | 
| 17 |  |  |  |  |  |  | $defaultmerole = 2; # Supervisor | 
| 18 |  |  |  |  |  |  | $defaultgwhost = '200.3.3.142'; | 
| 19 |  |  |  |  |  |  | $defaultgwport = '10010'; | 
| 20 |  |  |  |  |  |  | $defaultsetprof = 8; | 
| 21 |  |  |  |  |  |  | $defaultsignbrand = 'VISA'; | 
| 22 |  |  |  |  |  |  | $defaultaccountnumber = 1000; | 
| 23 |  |  |  |  |  |  | $defaultcassette = 'SET'; | 
| 24 |  |  |  |  |  |  | $defaultcurrency = 862; | 
| 25 |  |  |  |  |  |  | $defaultaccounttitle = 'Default Account'; | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | # | 
| 28 |  |  |  |  |  |  | # Public Methods | 
| 29 |  |  |  |  |  |  | # | 
| 30 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 31 |  |  |  |  |  |  | # Subroutine:  new | 
| 32 |  |  |  |  |  |  | # Author: Luis Moreno | 
| 33 |  |  |  |  |  |  | # Date: 20010612 | 
| 34 |  |  |  |  |  |  | # Modified: | 
| 35 |  |  |  |  |  |  | # Description: | 
| 36 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 37 |  |  |  |  |  |  | sub new() { | 
| 38 | 1 |  |  | 1 | 1 | 53 | my ($type, $class, $timeout, $pmhost) = (); | 
| 39 | 1 |  |  |  |  | 2 | my $defaulttimeout = 120; | 
| 40 | 1 |  |  |  |  | 2 | my $self = {}; | 
| 41 | 1 |  |  |  |  | 3 | ($ua, $h) = (); | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 1 |  |  |  |  | 2 | $type = shift; | 
| 44 | 1 |  | 33 |  |  | 6 | $class = ref($type) || $type; | 
| 45 | 1 |  |  |  |  | 3 | bless($self, $class); | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 1 |  | 33 |  |  | 8 | $self->{pmurl} = shift || $defaultpmurl; | 
| 48 | 1 |  | 33 |  |  | 4 | $self->{pmadmin} = shift || $defaultpmadmin; | 
| 49 | 1 |  | 33 |  |  | 6 | $self->{currency} = shift || $defaultcurrency; | 
| 50 | 1 |  |  |  |  | 2 | $self->{prirc} = -2; | 
| 51 | 1 |  |  |  |  | 2 | $self->{secrc} = -2; | 
| 52 | 1 |  | 33 |  |  | 5 | $timeout = shift || $defaulttimeout; | 
| 53 | 1 |  |  |  |  | 11 | $ua = LWP::UserAgent->new; | 
| 54 | 1 |  |  |  |  | 3409 | $ua->timeout($timeout); | 
| 55 | 1 |  |  |  |  | 23 | $h = new HTTP::Headers; | 
| 56 | 1 |  |  |  |  | 13 | $h->header(Connection => 'Keep-Alive', | 
| 57 |  |  |  |  |  |  | Accept => 'application/XML', | 
| 58 |  |  |  |  |  |  | Accept_Language => 'en-US', | 
| 59 |  |  |  |  |  |  | Authorization => 'Basic ' . $self->{pmadmin}, | 
| 60 |  |  |  |  |  |  | Content_Type => 'application/x-www-form-urlencoded', | 
| 61 |  |  |  |  |  |  | Host => 'localhost', | 
| 62 |  |  |  |  |  |  | User_Agent => 'Java PaymentServerClient', | 
| 63 |  |  |  |  |  |  | Content_Encoding => '8859_1'); | 
| 64 | 1 |  |  |  |  | 215 | return $self; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 71 |  |  |  |  |  |  | # Subroutine:  acceptPayment | 
| 72 |  |  |  |  |  |  | # Author: Luis Moreno | 
| 73 |  |  |  |  |  |  | # Date: 20010612 | 
| 74 |  |  |  |  |  |  | # Modified: | 
| 75 |  |  |  |  |  |  | # Description: Send a transaction using the Payment Manager engine, with the data | 
| 76 |  |  |  |  |  |  | # specified in the hash referenced by paydataref | 
| 77 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 78 |  |  |  |  |  |  | sub acceptPayment() { | 
| 79 | 0 |  |  | 0 | 1 | 0 | my ($answer, $postcontent, $request, $inittime, $response, $deltatime) = (); | 
| 80 | 0 |  |  |  |  | 0 | my $self = shift; | 
| 81 | 0 |  |  |  |  | 0 | my $paydataref = shift; | 
| 82 |  |  |  |  |  |  |  | 
| 83 | 0 | 0 |  |  |  | 0 | if (ref($paydataref) eq "HASH") { | 
| 84 | 0 |  |  |  |  | 0 | $paydataref->{operation} = 'ACCEPTPAYMENT'; | 
| 85 | 0 |  |  |  |  | 0 | $paydataref->{paymenttype} = 'SET'; | 
| 86 | 0 |  |  |  |  | 0 | $paydataref->{etapiversion} = 3; | 
| 87 | 0 | 0 |  |  |  | 0 | $paydataref->{currency} = $self->{currency} if (! $paydataref->{currency}); | 
| 88 | 0 | 0 |  |  |  | 0 | $paydataref->{paymentamount} = $paydataref->{amount} if (! $paydataref->{paymentamount}); | 
| 89 | 0 | 0 |  |  |  | 0 | $paydataref->{paymentnumber} = 1 if (! $paydataref->{paymentnumber}); | 
| 90 |  |  |  |  |  |  |  | 
| 91 | 0 |  |  |  |  | 0 | $postcontent = hash2content($paydataref); | 
| 92 | 0 |  |  |  |  | 0 | $h->content_length(length ($postcontent)); | 
| 93 | 0 |  |  |  |  | 0 | $request = HTTP::Request->new(POST => $self->{pmurl},$h); | 
| 94 | 0 |  |  |  |  | 0 | $request->content($postcontent); | 
| 95 |  |  |  |  |  |  |  | 
| 96 | 0 |  |  |  |  | 0 | $inittime = time; | 
| 97 | 0 |  |  |  |  | 0 | $response = $ua->request($request); | 
| 98 | 0 |  |  |  |  | 0 | $deltatime = time - $inittime; | 
| 99 |  |  |  |  |  |  |  | 
| 100 | 0 | 0 |  |  |  | 0 | if ($response->is_success) { | 
| 101 | 0 |  |  |  |  | 0 | $response->content =~ /$/; | 
| 102 | 0 |  |  |  |  | 0 | $self->{prirc} = $1; | 
| 103 | 0 |  |  |  |  | 0 | $self->{secrc} = $2; | 
| 104 | 0 |  |  |  |  | 0 | $self->{pmmessage} = $4; | 
| 105 | 0 |  |  |  |  | 0 | $answer = 1; | 
| 106 |  |  |  |  |  |  | } else { | 
| 107 | 0 |  |  |  |  | 0 | $self->{error}  = $response->message; | 
| 108 |  |  |  |  |  |  | } | 
| 109 | 0 |  |  |  |  | 0 | undef $request; | 
| 110 | 0 |  |  |  |  | 0 | undef $response; | 
| 111 |  |  |  |  |  |  | } | 
| 112 |  |  |  |  |  |  | else { | 
| 113 | 0 |  |  |  |  | 0 | $self->{error} = "Invalid payment data reference" | 
| 114 |  |  |  |  |  |  | } | 
| 115 | 0 |  |  |  |  | 0 | return($answer); | 
| 116 |  |  |  |  |  |  | } | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 119 |  |  |  |  |  |  | # Subroutine:  batchClose | 
| 120 |  |  |  |  |  |  | # Author: Luis Moreno | 
| 121 |  |  |  |  |  |  | # Date: 20010926 | 
| 122 |  |  |  |  |  |  | # Modified: | 
| 123 |  |  |  |  |  |  | # Description: Closes a batch given the merchantnumber within a hash reference and the | 
| 124 |  |  |  |  |  |  | # number of the batch to be closed | 
| 125 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 126 |  |  |  |  |  |  | sub batchClose() { | 
| 127 | 0 |  |  | 0 | 1 | 0 | my ($answer, $postcontent, $request, $inittime, $response, $deltatime) = (); | 
| 128 | 0 |  |  |  |  | 0 | my $self = shift; | 
| 129 | 0 |  |  |  |  | 0 | my $paydataref = shift; | 
| 130 | 0 |  |  |  |  | 0 | my $batchnumber = shift; | 
| 131 |  |  |  |  |  |  |  | 
| 132 | 0 | 0 | 0 |  |  | 0 | if (ref($paydataref) eq "HASH" and ($batchnumber >= 1)) { | 
| 133 | 0 |  |  |  |  | 0 | $paydataref->{operation} = 'BatchClose'; | 
| 134 | 0 |  |  |  |  | 0 | $paydataref->{force} = 1; | 
| 135 | 0 |  |  |  |  | 0 | $paydataref->{etapiversion} = 3; | 
| 136 | 0 |  |  |  |  | 0 | $paydataref->{batchnumber} = $batchnumber; | 
| 137 |  |  |  |  |  |  |  | 
| 138 | 0 |  |  |  |  | 0 | $postcontent = hash2content($paydataref); | 
| 139 | 0 |  |  |  |  | 0 | $h->content_length(length ($postcontent)); | 
| 140 | 0 |  |  |  |  | 0 | $request = HTTP::Request->new(POST => $self->{pmurl},$h); | 
| 141 | 0 |  |  |  |  | 0 | $request->content($postcontent); | 
| 142 |  |  |  |  |  |  |  | 
| 143 | 0 |  |  |  |  | 0 | $inittime = time; | 
| 144 | 0 |  |  |  |  | 0 | $response = $ua->request($request); | 
| 145 | 0 |  |  |  |  | 0 | $deltatime = time - $inittime; | 
| 146 |  |  |  |  |  |  |  | 
| 147 | 0 | 0 |  |  |  | 0 | if ($response->is_success) { | 
| 148 | 0 |  |  |  |  | 0 | $response->content =~ /$/; | 
| 149 | 0 |  |  |  |  | 0 | $self->{prirc} = $1; | 
| 150 | 0 |  |  |  |  | 0 | $self->{secrc} = $2; | 
| 151 | 0 |  |  |  |  | 0 | $self->{pmmessage} = $4; | 
| 152 | 0 |  |  |  |  | 0 | $answer = 1; | 
| 153 |  |  |  |  |  |  | } else { | 
| 154 | 0 |  |  |  |  | 0 | $self->{error}  = $response->message; | 
| 155 |  |  |  |  |  |  | } | 
| 156 | 0 |  |  |  |  | 0 | undef $request; | 
| 157 | 0 |  |  |  |  | 0 | undef $response; | 
| 158 |  |  |  |  |  |  | } | 
| 159 |  |  |  |  |  |  | else { | 
| 160 | 0 |  |  |  |  | 0 | $self->{error} = "Invalid payment data reference"; | 
| 161 |  |  |  |  |  |  | } | 
| 162 | 0 |  |  |  |  | 0 | return($answer); | 
| 163 |  |  |  |  |  |  | } | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 166 |  |  |  |  |  |  | # Subroutine:  getOpenBatchNumber | 
| 167 |  |  |  |  |  |  | # Author: Luis Moreno | 
| 168 |  |  |  |  |  |  | # Date: 20010926 | 
| 169 |  |  |  |  |  |  | # Modified: | 
| 170 |  |  |  |  |  |  | # Description: Given the merchantnumber within a hash reference returns the number of the | 
| 171 |  |  |  |  |  |  | # batch if exists | 
| 172 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 173 |  |  |  |  |  |  | sub getOpenBatchNumber() { | 
| 174 | 0 |  |  | 0 | 1 | 0 | my ($answer, $postcontent, $request, $inittime, $response, $deltatime) = (); | 
| 175 | 0 |  |  |  |  | 0 | my $self = shift; | 
| 176 | 0 |  |  |  |  | 0 | my $paydataref = shift; | 
| 177 |  |  |  |  |  |  |  | 
| 178 | 0 | 0 |  |  |  | 0 | if (ref($paydataref) eq "HASH") { | 
| 179 | 0 |  |  |  |  | 0 | $paydataref->{operation} = 'QueryBatches'; | 
| 180 | 0 |  |  |  |  | 0 | $paydataref->{state} = 'batch_open'; | 
| 181 | 0 | 0 |  |  |  | 0 | $paydataref->{accountnumber} = $defaultaccountnumber | 
| 182 |  |  |  |  |  |  | if (! $paydataref->{accountnumber}); | 
| 183 | 0 |  |  |  |  | 0 | $paydataref->{etapiversion} = 3; | 
| 184 |  |  |  |  |  |  |  | 
| 185 | 0 |  |  |  |  | 0 | $postcontent = hash2content($paydataref); | 
| 186 | 0 |  |  |  |  | 0 | $h->content_length(length ($postcontent)); | 
| 187 | 0 |  |  |  |  | 0 | $request = HTTP::Request->new(POST => $self->{pmurl},$h); | 
| 188 | 0 |  |  |  |  | 0 | $request->content($postcontent); | 
| 189 |  |  |  |  |  |  |  | 
| 190 | 0 |  |  |  |  | 0 | $inittime = time; | 
| 191 | 0 |  |  |  |  | 0 | $response = $ua->request($request); | 
| 192 | 0 |  |  |  |  | 0 | $deltatime = time - $inittime; | 
| 193 |  |  |  |  |  |  |  | 
| 194 | 0 | 0 |  |  |  | 0 | if ($response->is_success) { | 
| 195 | 0 |  |  |  |  | 0 | $response->content =~ / | 
| 196 | 0 |  |  |  |  | 0 | $self->{prirc} = $1; | 
| 197 | 0 |  |  |  |  | 0 | $self->{secrc} = $2; | 
| 198 | 0 | 0 |  |  |  | 0 | if ($3 >= 1) { | 
| 199 | 0 |  |  |  |  | 0 | $answer = 1; | 
| 200 | 0 |  |  |  |  | 0 | $response->content =~ /batchNumber="(\d*)"/; | 
| 201 | 0 |  |  |  |  | 0 | $answer = $1; | 
| 202 |  |  |  |  |  |  | } | 
| 203 |  |  |  |  |  |  | } else { | 
| 204 | 0 |  |  |  |  | 0 | $self->{error}  = $response->message; | 
| 205 |  |  |  |  |  |  | } | 
| 206 | 0 |  |  |  |  | 0 | undef $request; | 
| 207 | 0 |  |  |  |  | 0 | undef $response; | 
| 208 |  |  |  |  |  |  | } | 
| 209 |  |  |  |  |  |  | else { | 
| 210 | 0 |  |  |  |  | 0 | $self->{error} = "Invalid payment data reference"; | 
| 211 |  |  |  |  |  |  | } | 
| 212 | 0 |  |  |  |  | 0 | return($answer); | 
| 213 |  |  |  |  |  |  | } | 
| 214 |  |  |  |  |  |  |  | 
| 215 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 216 |  |  |  |  |  |  | # Subroutine:  createMerchant | 
| 217 |  |  |  |  |  |  | # Author: Luis Moreno | 
| 218 |  |  |  |  |  |  | # Date: 20010926 | 
| 219 |  |  |  |  |  |  | # Modified: | 
| 220 |  |  |  |  |  |  | # Description: Create a new merchant in the payment manager system | 
| 221 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 222 |  |  |  |  |  |  | sub createMerchant() { | 
| 223 | 0 |  |  | 0 | 1 | 0 | my ($answer, $postcontent, $request, $inittime, $response, $deltatime) = (); | 
| 224 | 0 |  |  |  |  | 0 | my $self = shift; | 
| 225 | 0 |  |  |  |  | 0 | my $paydataref = shift; | 
| 226 |  |  |  |  |  |  |  | 
| 227 | 0 | 0 |  |  |  | 0 | if (ref($paydataref) eq "HASH") { | 
| 228 | 0 |  |  |  |  | 0 | $paydataref->{operation} = 'CreateMerchant'; | 
| 229 | 0 |  |  |  |  | 0 | $paydataref->{etapiversion} = 3; | 
| 230 | 0 |  |  |  |  | 0 | $paydataref->{enabled} = 1; | 
| 231 |  |  |  |  |  |  |  | 
| 232 | 0 |  |  |  |  | 0 | $postcontent = hash2content($paydataref); | 
| 233 | 0 |  |  |  |  | 0 | $h->content_length(length ($postcontent)); | 
| 234 | 0 |  |  |  |  | 0 | $request = HTTP::Request->new(POST => $self->{pmurl},$h); | 
| 235 | 0 |  |  |  |  | 0 | $request->content($postcontent); | 
| 236 | 0 |  |  |  |  | 0 | $inittime = time; | 
| 237 | 0 |  |  |  |  | 0 | $response = $ua->request($request); | 
| 238 | 0 |  |  |  |  | 0 | $deltatime = time - $inittime; | 
| 239 |  |  |  |  |  |  |  | 
| 240 |  |  |  |  |  |  |  | 
| 241 | 0 | 0 |  |  |  | 0 | if ($response->is_success) { | 
| 242 | 0 |  |  |  |  | 0 | $response->content =~ /$/; | 
| 243 | 0 |  |  |  |  | 0 | $self->{prirc} = $1; | 
| 244 | 0 |  |  |  |  | 0 | $self->{secrc} = $2; | 
| 245 | 0 |  |  |  |  | 0 | $self->{pmmessage} = $4; | 
| 246 | 0 |  |  |  |  | 0 | $answer = 1; | 
| 247 |  |  |  |  |  |  | } else { | 
| 248 | 0 |  |  |  |  | 0 | $self->{error}  = $response->message; | 
| 249 |  |  |  |  |  |  | } | 
| 250 | 0 |  |  |  |  | 0 | undef $request; | 
| 251 | 0 |  |  |  |  | 0 | undef $response; | 
| 252 |  |  |  |  |  |  | } | 
| 253 |  |  |  |  |  |  | else { | 
| 254 | 0 |  |  |  |  | 0 | $self->{error} = "Invalid payment data reference"; | 
| 255 |  |  |  |  |  |  | } | 
| 256 | 0 |  |  |  |  | 0 | return($answer); | 
| 257 |  |  |  |  |  |  | } | 
| 258 |  |  |  |  |  |  |  | 
| 259 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 260 |  |  |  |  |  |  | # Subroutine:  createPaySystem | 
| 261 |  |  |  |  |  |  | # Author: Luis Moreno | 
| 262 |  |  |  |  |  |  | # Date: 20010926 | 
| 263 |  |  |  |  |  |  | # Modified: | 
| 264 |  |  |  |  |  |  | # Description: Authorize a merchant to use a pay system (SET for example). | 
| 265 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 266 |  |  |  |  |  |  | sub createPaySystem() { | 
| 267 | 0 |  |  | 0 | 1 | 0 | my ($answer, $postcontent, $request, $inittime, $response, $deltatime) = (); | 
| 268 | 0 |  |  |  |  | 0 | my $self = shift; | 
| 269 | 0 |  |  |  |  | 0 | my $paydataref = shift; | 
| 270 |  |  |  |  |  |  |  | 
| 271 | 0 | 0 |  |  |  | 0 | if (ref($paydataref) eq "HASH") { | 
| 272 | 0 |  |  |  |  | 0 | $paydataref->{operation} = 'CreatePaySystem'; | 
| 273 | 0 |  |  |  |  | 0 | $paydataref->{etapiversion} = 3; | 
| 274 | 0 |  |  |  |  | 0 | $paydataref->{enabled} = 1; | 
| 275 |  |  |  |  |  |  |  | 
| 276 | 0 |  |  |  |  | 0 | $postcontent = hash2content($paydataref); | 
| 277 | 0 |  |  |  |  | 0 | $h->content_length(length ($postcontent)); | 
| 278 | 0 |  |  |  |  | 0 | $request = HTTP::Request->new(POST => $self->{pmurl},$h); | 
| 279 | 0 |  |  |  |  | 0 | $request->content($postcontent); | 
| 280 | 0 |  |  |  |  | 0 | $inittime = time; | 
| 281 | 0 |  |  |  |  | 0 | $response = $ua->request($request); | 
| 282 | 0 |  |  |  |  | 0 | $deltatime = time - $inittime; | 
| 283 |  |  |  |  |  |  |  | 
| 284 |  |  |  |  |  |  |  | 
| 285 | 0 | 0 |  |  |  | 0 | if ($response->is_success) { | 
| 286 | 0 |  |  |  |  | 0 | $response->content =~ /$/; | 
| 287 | 0 |  |  |  |  | 0 | $self->{prirc} = $1; | 
| 288 | 0 |  |  |  |  | 0 | $self->{secrc} = $2; | 
| 289 | 0 |  |  |  |  | 0 | $self->{pmmessage} = $4; | 
| 290 | 0 |  |  |  |  | 0 | $answer = 1; | 
| 291 |  |  |  |  |  |  | } | 
| 292 |  |  |  |  |  |  | else { | 
| 293 | 0 |  |  |  |  | 0 | $self->{error}  = $response->message; | 
| 294 |  |  |  |  |  |  | } | 
| 295 | 0 |  |  |  |  | 0 | undef $request; | 
| 296 | 0 |  |  |  |  | 0 | undef $response; | 
| 297 |  |  |  |  |  |  | } | 
| 298 |  |  |  |  |  |  | else { | 
| 299 | 0 |  |  |  |  | 0 | $self->{error} = "Invalid payment data reference"; | 
| 300 |  |  |  |  |  |  | } | 
| 301 | 0 |  |  |  |  | 0 | return($answer); | 
| 302 |  |  |  |  |  |  | } | 
| 303 |  |  |  |  |  |  |  | 
| 304 |  |  |  |  |  |  |  | 
| 305 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 306 |  |  |  |  |  |  | # Subroutine:  createAccount | 
| 307 |  |  |  |  |  |  | # Author: Luis Moreno | 
| 308 |  |  |  |  |  |  | # Date: 20011001 | 
| 309 |  |  |  |  |  |  | # Modified: | 
| 310 |  |  |  |  |  |  | # Description: Create a new Account for a merchant. An account represents the relationship | 
| 311 |  |  |  |  |  |  | # between a merchant and an acquirer | 
| 312 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 313 |  |  |  |  |  |  | sub createAccount() { | 
| 314 | 0 |  |  | 0 | 1 | 0 | my ($answer, $postcontent, $request, $inittime, $response, $deltatime) = (); | 
| 315 | 0 |  |  |  |  | 0 | my $self = shift; | 
| 316 | 0 |  |  |  |  | 0 | my $paydataref = shift; | 
| 317 |  |  |  |  |  |  |  | 
| 318 | 0 | 0 |  |  |  | 0 | if (ref($paydataref) eq "HASH") { | 
| 319 | 0 |  |  |  |  | 0 | $paydataref->{operation} = 'CreateAccount'; | 
| 320 | 0 | 0 |  |  |  | 0 | $paydataref->{accountnumber} = $defaultaccountnumber | 
| 321 |  |  |  |  |  |  | if (! $paydataref->{accountnumber}); | 
| 322 | 0 | 0 |  |  |  | 0 | $paydataref->{'%24acquirersetprofile'} = $defaultsetprof | 
| 323 |  |  |  |  |  |  | if (! $paydataref->{'%24acquiresetprofile'}); | 
| 324 | 0 | 0 |  |  |  | 0 | $paydataref->{'%24gatewayhostname'} = $defaultgwhost | 
| 325 |  |  |  |  |  |  | if (! $paydataref->{'%24gatewayhostname'}); | 
| 326 | 0 | 0 |  |  |  | 0 | $paydataref->{'%24gatewayport'} = $defaultgwport | 
| 327 |  |  |  |  |  |  | if (! $paydataref->{'%24gatewayport'}); | 
| 328 | 0 | 0 |  |  |  | 0 | $paydataref->{'%24signingbrandid'} = $defaultsignbrand | 
| 329 |  |  |  |  |  |  | if (! $paydataref->{'%24signingbrandid'}); | 
| 330 | 0 | 0 |  |  |  | 0 | $paydataref->{'accounttitle'} = $defaultaccounttitle | 
| 331 |  |  |  |  |  |  | if (! $paydataref->{'accounttitle'}); | 
| 332 | 0 | 0 |  |  |  | 0 | $paydataref->{'financialinstitution'} = $defaultaccounttitle | 
| 333 |  |  |  |  |  |  | if (! $paydataref->{'financialinstitution'}); | 
| 334 | 0 |  |  |  |  | 0 | $paydataref->{etapiversion} = 3; | 
| 335 | 0 |  |  |  |  | 0 | $paydataref->{enabled} = 1; | 
| 336 |  |  |  |  |  |  |  | 
| 337 | 0 |  |  |  |  | 0 | $postcontent = hash2content($paydataref); | 
| 338 | 0 |  |  |  |  | 0 | $h->content_length(length ($postcontent)); | 
| 339 | 0 |  |  |  |  | 0 | $request = HTTP::Request->new(POST => $self->{pmurl},$h); | 
| 340 | 0 |  |  |  |  | 0 | $request->content($postcontent); | 
| 341 | 0 |  |  |  |  | 0 | $inittime = time; | 
| 342 | 0 |  |  |  |  | 0 | $response = $ua->request($request); | 
| 343 | 0 |  |  |  |  | 0 | $deltatime = time - $inittime; | 
| 344 |  |  |  |  |  |  |  | 
| 345 |  |  |  |  |  |  |  | 
| 346 | 0 | 0 |  |  |  | 0 | if ($response->is_success) { | 
| 347 | 0 |  |  |  |  | 0 | $response->content =~ /$/; | 
| 348 | 0 |  |  |  |  | 0 | $self->{prirc} = $1; | 
| 349 | 0 |  |  |  |  | 0 | $self->{secrc} = $2; | 
| 350 | 0 |  |  |  |  | 0 | $self->{pmmessage} = $4; | 
| 351 | 0 |  |  |  |  | 0 | $answer = 1; | 
| 352 |  |  |  |  |  |  | } | 
| 353 |  |  |  |  |  |  | else { | 
| 354 | 0 |  |  |  |  | 0 | $self->{error}  = $response->message; | 
| 355 |  |  |  |  |  |  | } | 
| 356 | 0 |  |  |  |  | 0 | undef $request; | 
| 357 | 0 |  |  |  |  | 0 | undef $response; | 
| 358 |  |  |  |  |  |  | } | 
| 359 |  |  |  |  |  |  | else { | 
| 360 | 0 |  |  |  |  | 0 | $self->{error} = "Invalid payment data reference"; | 
| 361 |  |  |  |  |  |  | } | 
| 362 | 0 |  |  |  |  | 0 | return($answer); | 
| 363 |  |  |  |  |  |  | } | 
| 364 |  |  |  |  |  |  |  | 
| 365 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 366 |  |  |  |  |  |  | # Subroutine:  SetUserAccessRights | 
| 367 |  |  |  |  |  |  | # Author: Luis Moreno | 
| 368 |  |  |  |  |  |  | # Date: 20011002 | 
| 369 |  |  |  |  |  |  | # Modified: | 
| 370 |  |  |  |  |  |  | # Description: Set permissions to a user of the Realm. The user must have the same name | 
| 371 |  |  |  |  |  |  | # of the merchant | 
| 372 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 373 |  |  |  |  |  |  | sub setUserAccessRights() { | 
| 374 | 0 |  |  | 0 | 0 | 0 | my ($answer, $postcontent, $request, $inittime, $response, $deltatime) = (); | 
| 375 | 0 |  |  |  |  | 0 | my $self = shift; | 
| 376 | 0 |  |  |  |  | 0 | my $paydataref = shift; | 
| 377 |  |  |  |  |  |  |  | 
| 378 | 0 | 0 |  |  |  | 0 | if (ref($paydataref) eq "HASH") { | 
| 379 | 0 |  |  |  |  | 0 | $paydataref->{operation} = 'SetUserAccessRights'; | 
| 380 | 0 |  |  |  |  | 0 | $paydataref->{etapiversion} = 3; | 
| 381 | 0 |  |  |  |  | 0 | $paydataref->{user} = $paydataref->{merchanttitle}; | 
| 382 | 0 | 0 |  |  |  | 0 | $paydataref->{role} = $defaultmerole | 
| 383 |  |  |  |  |  |  | if (! $paydataref->{role}); | 
| 384 |  |  |  |  |  |  |  | 
| 385 | 0 |  |  |  |  | 0 | $postcontent = hash2content($paydataref); | 
| 386 | 0 |  |  |  |  | 0 | $h->content_length(length ($postcontent)); | 
| 387 | 0 |  |  |  |  | 0 | $request = HTTP::Request->new(POST => $self->{pmurl},$h); | 
| 388 | 0 |  |  |  |  | 0 | $request->content($postcontent); | 
| 389 | 0 |  |  |  |  | 0 | $inittime = time; | 
| 390 | 0 |  |  |  |  | 0 | $response = $ua->request($request); | 
| 391 | 0 |  |  |  |  | 0 | $deltatime = time - $inittime; | 
| 392 |  |  |  |  |  |  |  | 
| 393 |  |  |  |  |  |  |  | 
| 394 | 0 | 0 |  |  |  | 0 | if ($response->is_success) { | 
| 395 | 0 |  |  |  |  | 0 | $response->content =~ /$/; | 
| 396 | 0 |  |  |  |  | 0 | $self->{prirc} = $1; | 
| 397 | 0 |  |  |  |  | 0 | $self->{secrc} = $2; | 
| 398 | 0 |  |  |  |  | 0 | $self->{pmmessage} = $4; | 
| 399 | 0 |  |  |  |  | 0 | $answer = 1; | 
| 400 |  |  |  |  |  |  |  | 
| 401 |  |  |  |  |  |  | } | 
| 402 |  |  |  |  |  |  | else { | 
| 403 | 0 |  |  |  |  | 0 | $self->{error}  = $response->message; | 
| 404 |  |  |  |  |  |  | } | 
| 405 | 0 |  |  |  |  | 0 | undef $request; | 
| 406 | 0 |  |  |  |  | 0 | undef $response; | 
| 407 |  |  |  |  |  |  | } | 
| 408 |  |  |  |  |  |  | else { | 
| 409 | 0 |  |  |  |  | 0 | $self->{error} = "Invalid payment data reference"; | 
| 410 |  |  |  |  |  |  | } | 
| 411 | 0 |  |  |  |  | 0 | return($answer); | 
| 412 |  |  |  |  |  |  | } | 
| 413 |  |  |  |  |  |  |  | 
| 414 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 415 |  |  |  |  |  |  | # Subroutine:  close | 
| 416 |  |  |  |  |  |  | # Author: Luis Moreno | 
| 417 |  |  |  |  |  |  | # Date: 20010612 | 
| 418 |  |  |  |  |  |  | # Modified: | 
| 419 |  |  |  |  |  |  | # Description: | 
| 420 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 421 |  |  |  |  |  |  | sub close() { | 
| 422 | 1 |  |  | 1 | 0 | 17 | undef $ua; | 
| 423 | 1 |  |  |  |  |  | undef $h; | 
| 424 |  |  |  |  |  |  | } | 
| 425 |  |  |  |  |  |  |  | 
| 426 |  |  |  |  |  |  | # Non public subs | 
| 427 |  |  |  |  |  |  |  | 
| 428 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 429 |  |  |  |  |  |  | # Subroutine:  hash2content | 
| 430 |  |  |  |  |  |  | # Author: Luis Moreno | 
| 431 |  |  |  |  |  |  | # Date: 20010612 | 
| 432 |  |  |  |  |  |  | # Modified: | 
| 433 |  |  |  |  |  |  | # Description: | 
| 434 |  |  |  |  |  |  | #------------------------------------------------------- | 
| 435 |  |  |  |  |  |  | sub hash2content($hashref) { | 
| 436 | 0 |  |  | 0 | 0 |  | my ($hashref) = @_; | 
| 437 | 0 |  |  |  |  |  | my ($postcontent, $key) = (); | 
| 438 |  |  |  |  |  |  |  | 
| 439 | 0 |  |  |  |  |  | foreach $key (keys %{$hashref}) { | 
|  | 0 |  |  |  |  |  |  | 
| 440 | 0 |  |  |  |  |  | $postcontent .= uc($key) . '=' . $hashref->{$key} . '&'; | 
| 441 |  |  |  |  |  |  | } | 
| 442 | 0 |  |  |  |  |  | chop($postcontent); | 
| 443 | 0 |  |  |  |  |  | return($postcontent); | 
| 444 |  |  |  |  |  |  | } | 
| 445 |  |  |  |  |  |  |  | 
| 446 |  |  |  |  |  |  | 1; | 
| 447 |  |  |  |  |  |  |  | 
| 448 |  |  |  |  |  |  | __END__ |