Revert "Embed Safe 2.07 into Vend::Safe to avoid various problems with recent version...
[interchange.git] / lib / Vend / Payment / Cardsave.pm
1 # Vend::Payment::Cardsave - Interchange Cardsave Payment module
2 #
3 # Copyright (C) 2012 Zolotek Resources Ltd
4 # All Rights Reserved.
5 #
6 # Author: Lyn St George <lyn@zolotek.net>
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public
19 # License along with this program; if not, write to the Free
20 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 # MA  02111-1307  USA.
22 #
23 package Vend::Payment::Cardsave;
24
25 =head1 NAME
26
27 Vend::Payment::Cardsave - Interchange Cardsave Payments Module
28
29 =head1 PREREQUISITES
30
31     XML::Simple
32     URI
33     libwww-perl
34     Net::SSLeay
35         HTTP::Request
36         
37 Test for current installations, eg: perl -MXML::Simple -e 'print "It works\n"'
38 To install perl modules do: "emerge dev-perl/XML-Simple" on Gentoo, or on other systems do
39 "perl -MCPAN -e  'install XML::Simple'"
40
41 =head1 DESCRIPTION
42
43 The Vend::Payment::Cardsave module implements the Cardsave payment routine for use with Interchange.
44
45 #=========================
46
47 =head1 SYNOPSIS
48
49 Quick start:
50
51 Place this module in <ic_root>/lib/Vend/Payment, and call it in <ic_root>/interchange.cfg with
52 Require module Vend::Payment::Cardsave. Ensure that your perl installation contains the modules
53 listed above and their pre-requisites.
54
55 Add a new payment route into catalog.cfg as follows:
56 Route cardsave id xxx
57 Route cardsave password xxx
58 Route cardsave returnurl 'https://domain.tld/cgi/ord/tdscardsavereturn'
59
60 The above are required, while those below are only required if you want to change from the 
61 default values as noted. These may be overriden at run-time with: [value avs_override_policy].
62 [value cv2_override_policy] and [value tds_override_policy] respectively.
63
64 Route cardsave avsoverridepolicy NPPP
65 Route cardsave cv2overridepolicy PP
66 Route cardsave threedsecureoverridepolicy TRUE
67
68 These next are also optional and allow you to override the default error messages as given in parentheses
69 with your own error messages to display to errant customers:
70 Route cardsave main3DSerror (Payment error: )
71 Route cardsave address_error (Address match failed)
72 Route cardsave postcode_error (PostalCode match failed)
73 Route cardsave cv2_error  (Card Security Code match failed)
74 The displayed message will start with the main3DSerror and append others as appropriate. 
75 Route cardsave mail_txn_to (email address, defaults to ORDERS_TO)
76 Route cardsave mail_txn_approved (1 to email approved orders)
77 Route cardsave mail_txn_declined (1 to email possibly fraudulent attempts)
78
79 Alter etc/log_transaction to wrap the following code around the "[charge route...]" call 
80 found in ln 172 (or nearby):
81         [if scratchd mstatus eq success]
82         [tmp name="charge_succeed"][scratch order_id][/tmp]
83         [else]
84         [tmp name="charge_succeed"][charge route="[var MV_PAYMENT_MODE]" amount="[scratch tmp_remaining]" order_id="[value mv_transaction_id]"][/tmp]
85         [/else]
86         [/if]
87 and change [var MV_PAYMENT_MODE] above to [value mv_payment_route] if you want to use Paypal or similar in conjunction with this
88
89 Also add these lines just after '&final = yes' near the end of the credit_card section of etc/profiles.order:
90 &set=mv_payment Cardsave
91 &set=psp Cardsave
92 &set=mv_payment_route cardsave
93 &set=mv_order_route default
94 &setcheck = end_profile 1
95 &setcheck = payment_method cardsave
96
97 New fields to put into the transactions table:
98 psp: [value psp] (type varchar(64))
99 payment_route: [value mv_payment_route] (type varchar(128))
100 txtype:  [calc]$Session->{payment_result}{TxType} || $Scratch->{txtype};[/calc] (type varchar(64))
101 pares: [calc]$Session->{payment_result}{PaRes};[/calc] (type text)
102 md: [calc]$Session->{payment_result}{MD};[/calc]  (type varchar(128))
103 currency_locale: [scratch mv_locale] (type varchar(64))
104 currency_code: [calc]$Session->{payment_result}{Currency};[/calc] (type varchar(32))
105         
106 NB/ the country code and currency code are both numeric, not alphabetic, and are both '826';
107 The amount passed to Cardsave is in pennies, so £8.24 is passed as 824.
108
109 The card type and card issuer are both available from a special call, and this call is made prior
110 to the main transaction call. Both values are logged and may be of use in anti-fraud measures.
111
112 There are 2 gateway entry points listed, and each gateway entry point
113 is tried in turn until one responds, with a 30 second time-out on each. The one that responds on the first
114 'cardpost' call is put in session to become the default for the second call after returning from the ACS.
115 These "gateway entry points" are actually separate data centres, with hot replication between them, though 
116 the replication may take a minute or so - hence the preference to stay with the same gateway entrypoint 
117 throughout the entire transaction if possible. 
118
119 Create a page in pages/ord called tdscardsavereturn.html like so:
120 <html>
121 <head>
122 <link rel="stylesheet" href="/images/theme_css.css">
123 </head>
124 <body>
125 [charge route="cardsave" cardsaverequest="tdspost"]
126 (some blurb for those who failed at the ACS and thus don't get past the [charge ..] line above)
127 </body>
128 </html>
129
130 Create a page in pages/ord called tdsfinal.html, which includes this snippet
131           <tr>
132                 <td align=center height=600 valign=middle colspan=2 width=800>
133                   <iframe src="[area ord/tdsauth]"  frameborder=0 width=800 height=600></iframe>
134                 </td>
135           </tr>
136 amongst the standard page elements, so the iframe is populated by the bank's ACS page.
137
138 Create another page in pages/ord called tdsauth.html like so:
139 <table align="center" width="100%">
140  <tr>
141   <td>
142 <body onload="document.form.submit();">
143 <FORM name="form" action="[scratchd acsurl]" method="POST" />
144 <input type="hidden" name="PaReq" value="[scratch pareq]" />
145 <input type="hidden" name="TermUrl" value="[scratch termurl]" />
146 <input type="hidden" name="MD" value="[scratch md]" />
147 </form>
148 <div style="background:white;border:1px solid blue;">
149 <br>
150 <noscript>
151 (equivalent form and a blurb for the customer to manually click 'submit')
152 </noscript>
153   </td>
154  </tr>
155 </table>
156 This page will be replaced by the bank's ACS page automagically. If the transaction is
157 successful at the bank, the customer will see the bank page replaced with the receipt page. 
158
159 In the etc/receipt.html page, change the calls to the header and footer like so:
160 [if type=explicit compare=`$Session->{payment_result}{SecureStatus} eq 'OK'`]
161 [else]
162 @_NOLEFT_TOP_@
163 [/else]
164 [/if]
165 [if type=explicit compare=`$Session->{payment_result}{SecureStatus} eq 'OK'`]
166 [else]
167 @_NOLEFT_BOTTOM_@
168 [/else]
169 [/if]
170 so that the receipt page will display properly within the tdsfinal page.
171
172 Test card numbers:
173 without 3DS: 4976000000003436/452 : street no 32 , postcode TR148PA, exp 12/12 gives 'success'
174 with 3DS: 4976350000006891/341, street no 113, postcode B421SX, exp 12/12 gives 'success'
175 other cv2s or postcodes should result in failure.
176
177 Virtual terminal operations:
178 Possible ops are: REFUND, COLLECTION, VOID, SALE, PREAUTH.
179 These are all keyed to the value of the MD returned from the original 3DSecure transaction
180 and saved into the transactions table as 'md'. This is read into the module as [value crossreference].
181 The various ops are read in as [value txtype]. The currency code is taken from the db and
182 read in as [value iso_currency_code_numeric], defaulting to '826' for GBP. 
183 SALE is used for repeat or recurring billing.
184
185 A possible block of code in a virtual terminal would be this:
186 <input type="hidden" name="mv_payment_route" value="cardsave">
187 <input type="hidden" name="cardsaverequest" value="crossreferencepost">
188 <input type="hidden" name="crossreference" value="[sql-param md]">
189 <select name="txtype">
190   <option value="PREAUTH" "[selected txtype PREAUTH]">PreAuth
191   <option value="REFUND" "[selected txtype REFUND]">Refund
192   <option value="SALE" "[selected txtype SALE]">Sale
193   <option value="COLLECTION" "[selected txtype COLLECTION]">Collection
194   <option value="VOID" "[selected txtype VOID]">Void
195 </select>
196
197
198
199 =head1 Changelog
200 090: release candidate
201
202 098: following the split of LloydsTSB into two separate banks and the issue of new cards,
203 apparently using Royal Bank of Scotland BIN ranges, Cardsave are returning the issuer for
204 these cards only as a string whereas all other issuers are returned as a hash, contrary
205 to their API. This update handles that situation. 
206
207
208 =head1 AUTHORS
209
210 Lyn St George <lyn@zolotek.net>
211
212 =cut
213
214 BEGIN {
215         eval {
216                 package Vend::Payment;
217                 require Net::SSLeay;
218                         require XML::Simple;
219                         require LWP;
220                         require HTTP::Request::Common;
221                         import HTTP::Request::Common qw(POST);
222                         use HTTP::Request  ();
223
224         };
225
226        $Vend::Payment::Have_LWP = 1 unless $@;
227
228         if ($@) {
229                 $msg = __PACKAGE__ . ' requires XML::Simple, HTTP::Request, Net::SSLeay and LWP. ' . $@;
230                 ::logGlobal ($msg);
231                 die $msg;
232         }
233
234         ::logGlobal("%s v0.9.8 20130730 payment module loaded",__PACKAGE__)
235                 unless $Vend::Quiet or ! $Global::VendRoot;
236 }
237
238 package Vend::Payment;
239
240 use strict;
241
242   my ($host, $host1, $host2, $host3, $host4);
243
244 sub cardsave {
245     my ($response, $in, $opt, $actual, %result, $passoutdata, $orderdescription, $db, $dbh, $sth);
246     my $subtotal = Vend::Interpolate::subtotal();
247 #::logDebug("TDSbounced=$::Scratch->{tdsbounced}; subtotal=$subtotal");
248     return if ($::Scratch->{'tdsbounced'} > '1');
249
250         my (%actual) = map_actual();
251                 $actual  = \%actual;
252
253         my $cardsaverequest = charge_param('cardsaverequest') || $::Values->{'cardsaverequest'} || 'cardpost'; 
254            $::Values->{'tdsrequest'} = $cardsaverequest;
255         if ($cardsaverequest eq 'cardpost') {
256            $result{'MErrMsg'} = "No credit card entered " unless $actual->{'mv_credit_card_number'};
257            $result{'MErrMsg'} .= "<br>No items in your basket " unless $subtotal > '0';
258          }
259     
260     return(%result) if length $result{'MErrMsg'};
261
262 #::logDebug("Cardsave".__LINE__.": txtype=$::Values->{txtype}; req=$::Values->{cardsaverequest};$cardsaverequest");
263         my $username     = charge_param('id') or die "No username id\n";
264         my $password     = charge_param('password') or die "No password\n";
265         my $txtype       = charge_param('txtype') || $::Values->{'txtype'} || 'SALE';
266            $::Values->{'txtype'} ||= $txtype;
267         my $tdsfinalpage = charge_param('tdsfinalpage') || 'ord/tdsfinal'; 
268         my $termurl      = charge_param('returnurl') || "$::Variable->{SECURE_SERVER}$::Variable->{CGI_URL}/ord/tdscardsavereturn";
269         # ISO currency code, from the page for a multi-currency site or fall back to config files.
270         my $currency = $::Scratch->{'iso_currency_code'} || $::Values->{'currency_code'} || charge_param('currency') || 'GBP';
271         my $currency2 = $currency;
272            $currency2 =~ /(\w\w)/i;
273            $currency2 = $1;
274 #::logDebug("Cardsave".__LINE__.": 1=" . $::Scratch->{'iso_currency_code'} . "2=" . $::Values->{'currency_code'} . "3=" . charge_param('currency'));
275         my $amount =  charge_param('amount') || Vend::Interpolate::total_cost() || $::Values->{'amount'}; 
276            $amount =~ s/^\D*//g;
277            $amount =~ s/\s*//g;
278            $amount =~ s/,//g;
279            $amount =  sprintf '%.2f', $amount;
280            $amount =~ s/\.//g; # £10.00 becomes 1000 for Cardsave
281
282            $host1   = charge_param('host1') || 'https://gw1.cardsaveonlinepayments.com:4430';   
283            $host2   = charge_param('host2') || 'https://gw2.cardsaveonlinepayments.com:4430';   
284            $host3   = charge_param('host3') || 'https://gw3.cardsaveonlinepayments.com:4430';   
285            $host4   = charge_param('host4') || 'https://gw4.cardsaveonlinepayments.com:4430'; ### NB testing only  
286            
287         my $address1 = $::Values->{'b_address1'} || $::Values->{'address1'};
288         my $address2 = $::Values->{'b_address2'} || $::Values->{'address2'};
289         my $address3 = $::Values->{'b_address3'} || $::Values->{'address3'};
290         my $address4 = $::Values->{'b_address4'} || $::Values->{'address4'};
291         my $address  = "$address1, $address2, $address3 $address4";
292            $address  =~ s/,\s+$//g;
293            $address  =~ s/[^a-zA-Z0-9,.\- ]//gi;
294         my $city     = $::Values->{'b_city'} || $::Values->{'city'};
295            $city     =~ s/[^a-zA-Z0-9,.\- ]//gi;
296         my $state    = $::Values->{'b_state'} || $::Values->{'state'};
297            $state    =~ s/[^a-zA-Z0-9,.\- ]//gi;
298         my $zip      = $::Values->{'b_zip'} || $::Values->{'zip'};
299            $zip      =~ s/[^a-zA-Z0-9,.\- ]//gi;
300         my $country  = $::Values->{'b_country'} || $::Values->{'country'};
301         my $email      = $actual->{'email'};
302            $email      =~ s/[^a-zA-Z0-9.\@\-_]//gi;
303         my $phone      = $actual->{'phone_day'} || $actual->{'phone_night'};
304            $phone      =~ s/[\(\)]/ /g;
305            $phone      =~ s/[^0-9-+ ]//g;
306         my $ipaddress  = $CGI::remote_addr if $CGI::remote_addr;
307            $ipaddress  =~ /(\d*)\.(\d*)\.(\d*)\.(\d*)/;
308         my $t1 = sprintf '%03d', $1;
309         my $t2 = sprintf '%03d', $2;
310         my $t3 = sprintf '%03d', $3;
311         my $t4 = sprintf '%03d', $4;
312            $ipaddress = "$t1.$t2.$t3.$t4" if $CGI::remote_addr;                 
313
314         my $pan = $actual->{'mv_credit_card_number'};
315            $pan =~ s/\D//g;
316            $actual->{'mv_credit_card_exp_month'}    =~ s/\D//g;
317            $actual->{'mv_credit_card_exp_year'}     =~ s/\D//g;
318            $actual->{'mv_credit_card_exp_year'}     =~ s/\d\d(\d\d)/$1/;
319         my $cardref  = $pan;
320            $cardref  =~ s/^(\d\d\d\d).*(\d\d\d\d)$/$1****$2/;
321            $::Session->{'CardRef'} = $cardref;
322            
323         my $cardholder         = "$actual->{b_fname} $actual->{b_lname}" || "$actual->{fname} $actual->{lname}";
324            $cardholder         =~ s/[^a-zA-Z0-9,.\- ]//gi;
325
326         my $mvccexpmonth  = sprintf '%02d', $actual->{'mv_credit_card_exp_month'};
327         my $mvccexpyear   = sprintf '%02d', $actual->{'mv_credit_card_exp_year'};
328
329         my $expshow = "$mvccexpmonth" . "$mvccexpyear";
330            $expshow =~ s/(\d\d)(\d\d)/$1\/$2/;
331
332         my $mvccstartmonth = $actual->{'mv_credit_card_start_month'} || $::Values->{'mv_credit_card_start_month'} || $::Values->{'start_date_month'};
333            $mvccstartmonth =~ s/\D//g;
334         
335         my $mvccstartyear = $actual->{'mv_credit_card_start_year'} || $::Values->{'mv_credit_card_start_year'} || $::Values->{'start_date_year'};
336            $mvccstartyear =~ s/\D//;
337            $mvccstartyear =~ s/\d\d(\d\d)/$1/;
338
339         my $issuenumber = $actual->{'mv_credit_card_issue_number'} || $::Values->{'mv_credit_card_issue_number'} ||  $::Values->{'card_issue_number'};
340            $issuenumber =~ s/\D//g;
341         
342         my $cv2  =  $actual->{'mv_credit_card_cvv2'} || $::Values->{'mv_credit_card_cvv2'} || $::Values->{'cvv2'};
343            $cv2  =~ s/\D//g;
344            
345            $::Session->{'mv_order_number'} = $::Values->{'mv_order_number'};
346
347 #::logDebug("Cardsave".__LINE__.": on=$::Values->{mv_order_number}; valtxtype=$::Values->{txtype};  pan=$pan; cardholder=$cardholder; expm=$mvccexpmonth; expy=$mvccexpyear; issue=$issuenumber; cv2=$cv2; address=$address");
348
349 my $echocardtype = charge_param('echocardtype') || 'TRUE';
350         my $echoavscheckresult = charge_param('echoavscheckresult') || 'TRUE';
351         my $echocv2checkresult = charge_param('echocv2checkresult') || 'TRUE';
352         my $echoamountreceived = charge_param('echoamountreceived') || 'TRUE';
353         my $duplicatedelay = charge_param('duplicatedelay') || '1';
354         my $avsoverridepolicy = delete $::Values->{'avs_override_policy'} || charge_param('avsoverridepolicy') || 'NPPP';
355         my $cv2overridepolicy = delete $::Values->{'cv2_override_policy'} || charge_param('cv2overridepolicy') || 'PP';
356         my $threedsecureoverridepolicy = delete $::Values->{'tds_override_policy'} || charge_param('threedsecureoverridepolicy') || 'TRUE'; # TRUE forces 3DS on, FALSE sets 3DS off
357         my $mailto = charge_param('mail_txn_to') || $::Variable->{'ORDERS_TO'};
358
359 # Lookup iso code from country.txt - major country and currency codes identical
360         my ($iso_country_code_numeric, $iso_currency_code_numeric); 
361             $db  = dbref('country') or die ::errmsg("cannot open country table");
362             $dbh = $db->dbh() or die ::errmsg("cannot get handle for tbl 'country'");
363             $sth = $dbh->prepare("SELECT isonum FROM country WHERE code = '$currency2'");
364
365         if ($currency =~ /GBP/i) {
366                 $iso_currency_code_numeric = '826';
367                 }
368         elsif ($currency =~ /EUR/i) {
369                 $iso_currency_code_numeric = '978';
370                 }
371         elsif ($currency =~ /USD/i) {
372                 $iso_currency_code_numeric = '840';
373                 }
374         else {
375                 $sth->execute();
376                 $iso_currency_code_numeric = $sth->fetchrow();          
377         };
378
379         if ($country =~ /GB|UK/i) {
380                 $iso_country_code_numeric = '826';
381                 }
382         elsif ($country =~ /US/i) {
383                 $iso_country_code_numeric = '840';
384                 }
385         else {
386             $sth = $dbh->prepare("SELECT isonum FROM country WHERE code = '$country'");
387                 $sth->execute();
388                 $iso_country_code_numeric = $sth->fetchrow();           
389         };
390
391 #::logDebug("Cardsave".__LINE__.": country=$country,code=$iso_country_code_numeric; currency=$currency,cur2=$currency2; currencycode=$iso_currency_code_numeric");
392                 $iso_currency_code_numeric = '826' unless defined $iso_currency_code_numeric;
393                 $iso_country_code_numeric  = '826' unless defined $iso_country_code_numeric;
394 #::logDebug("Cardsave".__LINE__.": country=$country; currency=$currency; currencycode=$iso_currency_code_numeric");
395
396 #-------------------------------------------------------------------------------------------------
397 # Create the Header and the Transaction Control block for re-use
398 #
399         my $header = <<EOF;
400 <?xml version="1.0" encoding="UTF-8"?>
401 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
402                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
403                xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
404 <soap:Body>
405 EOF
406
407         my $transcontrol = <<EOF;
408         <TransactionControl>
409           <EchoCardType>$echocardtype</EchoCardType>
410           <EchoAVSCheckResult>$echoavscheckresult</EchoAVSCheckResult>
411           <EchoCV2CheckResult>$echocv2checkresult</EchoCV2CheckResult>
412           <EchoAmountReceived>$echoamountreceived</EchoAmountReceived>
413           <DuplicateDelay>$duplicatedelay</DuplicateDelay>
414           <AVSOverridePolicy>$avsoverridepolicy</AVSOverridePolicy>
415           <CV2OverridePolicy>$cv2overridepolicy</CV2OverridePolicy>
416           <ThreeDSecureOverridePolicy>$threedsecureoverridepolicy</ThreeDSecureOverridePolicy>
417         </TransactionControl>
418 EOF
419
420 #--------------------------------------------------------------------------------------------------
421 # Create a CardDetailsTransaction request and read response
422 #
423         if ($cardsaverequest eq 'cardpost') {
424 #::logDebug("Cardsave".__LINE__." started $cardsaverequest; on=$::Values->{mv_order_number};");
425 #::logDebug("Cardsave".__LINE__.": result=".::uneval(\%result));
426
427          my $order_id  = $Tag->time({ body => "%Y%m%d%H%M%S" }); 
428         $order_id .= $::Session->{id};
429             $::Session->{'order_id'} = $order_id;
430                 $::Session->{'CardsaveHost'} = '$host1';
431                 $::Scratch->{'tdspause'} = '';
432                 $::Scratch->{'mstatus'} = '';
433 #        $::Scratch->{'tdsmsg'} = '';
434
435 #::logDebug("Cardsave".__LINE__.": txtype=$txtype; order-id=$order_id; soid=$::Scratch->{order_id}");
436
437         my $xmlOut = $header;
438            $xmlOut .= <<EOX;
439 <CardDetailsTransaction xmlns="https://www.thepaymentgateway.net/">
440     <PaymentMessage>
441      <MerchantAuthentication Password="$password" MerchantID="$username" /> 
442       <TransactionDetails Amount="$amount" CurrencyCode="$iso_currency_code_numeric">
443         <MessageDetails TransactionType="$txtype" />
444         <OrderID>$order_id</OrderID>
445 EOX
446
447         $xmlOut .= $transcontrol;
448
449         $xmlOut .= <<EOX;
450          </TransactionDetails>
451           <CardDetails>
452         <CardName>$cardholder</CardName>
453         <CardNumber>$pan</CardNumber>
454         <ExpiryDate Month="$mvccexpmonth" Year="$mvccexpyear" />
455         <StartDate Month="$mvccstartmonth" Year="$mvccstartyear" />
456         <CV2>$cv2</CV2>
457         <IssueNumber>$issuenumber</IssueNumber>
458       </CardDetails>
459       <CustomerDetails>
460         <BillingAddress>
461           <Address1>$address</Address1>
462          <City>$city</City>
463           <State>$state</State>
464           <PostCode>$zip</PostCode>
465           <CountryCode>$iso_country_code_numeric</CountryCode>
466         </BillingAddress>
467         <EmailAddress>$email</EmailAddress>
468         <PhoneNumber>$phone</PhoneNumber>
469         <CustomerIPAddress>$ipaddress</CustomerIPAddress>
470       </CustomerDetails>
471     </PaymentMessage>
472   </CardDetailsTransaction>
473 </soap:Body>
474 </soap:Envelope>
475 EOX
476
477         my $card = getcardtypeCardsave($pan, $username, $password);
478           
479            $::Session->{'CardType'} = $result{'CardType'} = $card->{'CardType'} if $card->{'CardType'};
480            $::Session->{'CardIssuer'} = $result{'CardIssuer'} = $card->{'Issuer'}->{'content'} if $card->{'Issuer'} =~ /HASH/;
481            $::Session->{'CardIssuer'} = $result{'CardIssuer'} = $card->{'Issuer'} if $card->{'Issuer'} !~ /HASH/;
482            $::Session->{'CardIssuerCode'} = $result{'CardIssuerCode'} = $card->{'Issuer'}->{'ISOCode'} if $card->{'Issuer'} =~ /HASH/;
483            $::Session->{'CardInfo'} = "$result{'CardType'}, $::Session->{'CardRef'}, $expshow" if $card->{'CardType'};
484 ###::logDebug("Cardsave".__LINE__.": xmlOut=$xmlOut\ncardinfo=$::Session->{CardInfo}; issuer=$::Session->{CardIssuer}");         
485 #::logDebug("Cardsave".__LINE__.": card-xmlback=".::uneval($card));
486
487         my $msg = postCardsave($xmlOut);
488         my $xml = new XML::Simple(Keyattr => 'CardDetailsTransactionResponse');
489         my $data = $xml->XMLin("$msg");
490 #::logDebug("Cardsave".__LINE__.": xmlOut=$msg\n xmlback=".::uneval($data));
491            $data = $data->{'soap:Body'}->{'CardDetailsTransactionResponse'};
492
493            $result{'TxAuthNo'} = $data->{'TransactionOutputData'}->{'AuthCode'};
494            $result{'TDScheck'} = $data->{'TransactionOutputData'}->{'ThreeDSecureAuthenticationCheckResult'};
495            $result{'MD'}       = $data->{'TransactionOutputData'}->{'CrossReference'};
496            $result{'CardType'} = $data->{'TransactionOutputData'}->{'CardTypeData'}->{'CardType'};
497 ###        $result{'Issuer'}   = $data->{'TransactionOutputData'}->{'CardTypeData'}->{'Issuer'}->{'content'};
498            $result{'StatusCode'}  = $data->{'CardDetailsTransactionResult'}->{'StatusCode'};
499            $result{'AuthAttempt'} = $data->{'CardDetailsTransactionResult'}->{'AuthorisationAttempted'};
500            $result{'TDSmessage'}  = $data->{'CardDetailsTransactionResult'}->{'Message'};
501
502            $result{'CardRef'}  = $::Session->{'CardRef'} = $cardref;
503            $result{'CardInfo'} = $::Session->{'CardInfo'};
504
505           if ($data->{'CardDetailsTransactionResult'}->{'ErrorMessages'}->{'MessageDetail'} =~ /ARRAY/) {
506                 for my $i (0 .. 4) {
507                         #$::Session->{'errors'}{'Payment error'} =~ s/Passed variable: CardDetails\.//g;
508                         #$::Session->{'errors'}{'Payment error'} =~ s/Required variable: //g;
509                         #$::Session->{'errors'}{'Payment error'} =~ s/type //g;
510                         $::Session->{'errors'} .= "<p>$data->{'CardDetailsTransactionResult'}->{'ErrorMessages'}->{'MessageDetail'}[$i]{'Detail'}"; 
511                         $result{'MErrMsg'} .= $::Session->{'errors'};
512                                 }
513                         }
514           else {
515                     $::Session->{'errors'}{'Payment error'} = $data->{'CardDetailsTransactionResult'}->{'ErrorMessages'}->{'MessageDetail'}->{'Detail'};
516                     if ($::Session->{'errors'}{'Payment error'} =~ /PaymentMessage\.CardDetails\.CardNumber/i) {
517                                 $::Session->{'errors'}{'Payment error'} = 'Credit Card is missing';
518                         }
519           }
520
521 #::logDebug("Cardsave".__LINE__.": type=$result{CardType}; errors = $::Session->{'errors'}{'Payment error'}");
522
523 #::logDebug("Cardsave".__LINE__.": authcode=$result{TxAuthNo}, cardref=$result{CardRef}; cardinfo=$result{CardInfo}; xref-md=$result{MD}; stcode=$result{statuscode}; TDSattmp=$result{AuthAttempt}; TDSmsg=$result{TDSmessage}");
524
525          my $PaReq = $data->{'TransactionOutputData'}->{'ThreeDSecureOutputData'}->{'PaREQ'};
526          my $acsurl = $data->{'TransactionOutputData'}->{'ThreeDSecureOutputData'}->{'ACSURL'};
527 #::logDebug("Cardsave".__LINE__.": tds: PaReq=$PaReq\nacsurl=$acsurl");   
528
529 #................................................................................................
530 # Now go off to the ACS
531 #
532           if (defined $acsurl) {
533 #::logDebug("Cardsave".__LINE__." started TDSpost to ACS $acsurl; on=$::Values->{mv_order_number};");
534
535                 $::Scratch->{'acsurl'}  = $acsurl;
536                 $::Scratch->{'pareq'}   = $PaReq;
537                 $::Scratch->{'termurl'} = $termurl;
538                 $::Scratch->{'md'}      = $result{'MD'};
539                 $::Session->{'payment_id'} = $order_id;
540                 $::Scratch->{'tdspause'} = '1';
541                 $::Scratch->{'mstatus'}  = 'pause';
542                 $::Scratch->{'tdspostdone'} = '';
543                 $result{'PaReq'} = $PaReq;
544             $result{'MStatus'} = 'pause';
545 #           undef $::Session->{'errors'}; # remove 'die' msg from log_transaction
546                 undef $acsurl;
547
548         $::Scratch->{'tdsreturned'} = $::Scratch->{'tdsbounced'} = '';
549         
550 #::logDebug("Cardsave".__LINE__." termurl=$termurl; $::Session->{'order_id'}");
551         my $tdsfinal = $Tag->area({ href => "$tdsfinalpage" });
552         $Tag->tag({ op => 'header', body => <<EOB });
553 Status: 302 moved
554 Location: $tdsfinal
555 EOB
556
557            }
558    }
559
560 #------------------------------------------------------------------------------------------------
561 # Returned from the ACS, now to post the 3DS results to Cardsave for authentication
562 #
563         if ($cardsaverequest eq 'tdspost' and length $CGI->{'MD'}) {
564 #::logDebug("Cardsave".__LINE__." started $cardsaverequest; on=$::Values->{mv_order_number};");
565
566                 $result{'PaRes'} = $CGI->{'PaRes'} if $CGI->{'PaRes'};
567         $result{'MD'}    = $CGI->{'MD'} if $CGI->{'MD'};
568                 $::Scratch->{'cardsaverequestdone'} = 'tdspost';
569                 $::Values->{'cardsaverequest'} = '';
570                 $::Scratch->{'mstatus'} = '';
571                 undef $cardsaverequest;
572                 my $acspage = ::http()->{'entity'};
573
574 #::logDebug("Cardsave".__LINE__.": PaRes=$result{PaRes}\nMD=$result{MD}\n###acspage=$$acspage");
575
576         my $xmlOut = $header;
577            $xmlOut .= <<EOX;
578   <ThreeDSecureAuthentication xmlns="https://www.thepaymentgateway.net/">
579     <ThreeDSecureMessage>
580     <MerchantAuthentication MerchantID="$username" Password="$password" />
581      <ThreeDSecureInputData CrossReference="$result{'MD'}">
582         <PaRES>$result{'PaRes'}</PaRES>
583       </ThreeDSecureInputData>
584       <PassOutData>$passoutdata</PassOutData>
585     </ThreeDSecureMessage>
586   </ThreeDSecureAuthentication>
587 </soap:Body>
588 </soap:Envelope>
589 EOX
590
591         my $msg  = postCardsave($xmlOut);
592         my $xml  = new XML::Simple();
593         my $data = $xml->XMLin("$msg");
594 #::logDebug("Cardsave".__LINE__.": xmlback=".::uneval($data));
595        $data = $data->{'soap:Body'}->{'ThreeDSecureAuthenticationResponse'};
596
597        if ($data->{'ThreeDSecureAuthenticationResult'}->{'ErrorMessages'}->{'MessageDetail'} =~ /ARRAY/) {
598                 for my $i (0 .. 4) {
599                         $::Session->{'errors'}{'Payment error'} .= "<p>$data->{'ThreeDSecureAuthenticationResult'}->{'ErrorMessages'}->{'MessageDetail'}[$i]{'Detail'}"; 
600                                 }
601                          }
602            else {
603                     $::Session->{'errors'}{'Payment error'} = $data->{'ThreeDSecureAuthenticationResult'}->{'ErrorMessages'}->{'MessageDetail'}->{'Detail'};
604            }
605
606            if (length $::Session->{'errors'}{'Payment error'}) {
607                  $result{'StatusCode'} = '5';
608            }
609  
610            $result{'TxAuthNo'}    = $data->{'TransactionOutputData'}->{'AuthCode'};
611            $result{'CV2Result'}   = $data->{'TransactionOutputData'}->{'CV2CheckResult'};
612            $result{'AddressResult'} = $data->{'TransactionOutputData'}->{'AddressNumericCheckResult'};
613            $result{'PostCodeResult'} = $data->{'TransactionOutputData'}->{'PostCodeCheckResult'};
614            $result{'TDScheck'}   = $data->{'TransactionOutputData'}->{'ThreeDSecureAuthenticationCheckResult'};
615            $result{'MD'}    = $data->{'TransactionOutputData'}->{'CrossReference'};
616
617            $result{'StatusCode'}  = $data->{'ThreeDSecureAuthenticationResult'}->{'StatusCode'};
618            $result{'AuthAttempt'} = $data->{'ThreeDSecureAuthenticationResult'}->{'AuthorisationAttempted'};
619            $result{'TDSmessage'}  = $data->{'ThreeDSecureAuthenticationResult'}->{'Message'};
620
621 #::logDebug("Cardsave".__LINE__.": on=$::Values->{mv_order_number}; 3ds status=$result{StatusCode}; 3dsres=$result{TDScheck}; authattempt=$result{AuthAttempt}; resmsg=$result{TDSmessage}; authcode=$result{TxAuthNo}");               
622
623 # Now returned from Cardsave, so either complete or fail the 3DS transaction
624        if ($result{'StatusCode'} == '0') {
625                    $result{'SecureStatus'}  = 'OK';
626                    $result{'MStatus'} = $result{'pop.status'} = 'success';
627                    $result{'order-id'} ||= $::Session->{'order_id'};
628                    $result{'TxType'} = uc($txtype);
629                    $result{'Status'} = 'OK';
630                $result{'CardType'} = $::Session->{'CardType'};
631                    $result{'CardInfo'} = $::Session->{'CardInfo'};
632                    $result{'CardRef'}  = $::Session->{'CardRef'};
633 ###                $result{'CardIssuer'} = $::Session->{'CardIssuer'};
634                    $result{'CardIssuerCode'} = $::Session->{'CardIssuerCode'};
635                    $::Scratch->{'mstatus'} = 'success';
636                    $::Scratch->{'order_id'} = $result{'order-id'};
637                    $::Values->{'psp'} = charge_param('psp') || 'Cardsave';
638                    $::Session->{'payment_id'} = $result{'order-id'};
639                    $::CGI::values{'mv_todo'} = 'submit';
640                    $::Scratch->{'tdspause'} = '';
641            $::Scratch->{'tds'} = 'yes' ;
642                    $::Values->{'mv_payment'} = "Real-time card $::Session->{'CardInfo'}";
643                    $::Values->{'mv_order_route'} ||= 'log copy_user main';
644            $::Scratch->{'tdspostdone'} = 'yes' ;
645            
646                                         $Vend::Session->{'payment_result'} = \%result;
647
648 #::logDebug("Cardsave".__LINE__.": tdspostdone=$::Scratch->{'tdspostdone'}; SecureStatus=$result{'SecureStatus'} so now to run routes;");
649
650                                         Vend::Dispatch::do_process();
651
652                                         }
653
654                 else {
655
656                            $result{'MStatus'} = $result{'pop.status'} = $::Scratch->{'mstatus'} = 'fail';
657                            $result{'TDSerror'} = $result{'TDSmessage'};
658                            $::Scratch->{'tds'} = '';
659 #::logDebug("Cardsave".__LINE__.": 3ds status=$result{StatusCode}; 3ds res=$result{TDScheck};  resmsg=$result{TDSmessage}");            
660                  
661                  }
662     }
663
664 #------------------------------------------------------------------------------------------------
665 # Get the type and issuer of the card, for anti-fraud use
666 #
667         if ($cardsaverequest eq 'getcardtype') {
668 #::logDebug("Cardsave".__LINE__." started $cardsaverequest for card $pan");
669                 getcardtypeCardsave($pan);
670     }
671
672 #------------------------------------------------------------------------------------------------
673 # Is this useful? Rather try each listed gateway in turn if any fail
674 #
675         if ($cardsaverequest eq 'getgatewayentrypoints') {
676 #::logDebug("Cardsave".__LINE__." started $cardsaverequest");
677
678         my $xmlOut = $header;
679            $xmlOut .= <<EOX;
680   <GetGatewayEntryPoints xmlns="https://www.thepaymentgateway.net/">
681     <GetGatewayEntryPointsMessage>
682       <MerchantAuthentication MerchantID="$username" Password="$password" />
683     </GetGatewayEntryPointsMessage>
684   </GetGatewayEntryPoints>
685 </soap:Body>
686 </soap:Envelope>
687 EOX
688
689         my $msg = postCardsave($xmlOut);
690         my $xml = new XML::Simple();
691         my $data = $xml->XMLin("$msg");
692 #::logDebug("Cardsave".__LINE__.": xmlback=".::uneval($data));
693     }
694
695 #------------------------------------------------------------------------------------------------
696 # Use the crossreference (MD) for repeat billing and refunds, without needing the card number
697 #
698         if ($cardsaverequest eq 'crossreferencepost') {
699 #::logDebug("Cardsave".__LINE__." started $cardsaverequest");
700
701         my $crossreference = $::Values->{'crossreference'};
702         my $order_id  = charge_param('order_id') || $Tag->time({ body => "%Y%m%d%H%M%S" }); 
703            $order_id .=   "-" . $Tag->time({ body => "%H%M%S" }) if charge_param('order_id');
704            $order_id .=  $::Session->{id};
705            $::Session->{'order_id'} = $::Values->{'mv_transaction_id'} = $order_id;
706         my $new_transaction = $::Values->{'new_transaction'} || 'FALSE';
707 #::logDebug("Cardsave".__LINE__.": sessoid=$::Session->{'order_id'}; void=$::Values->{'order_id'}");
708         my $xmlOut = $header;
709            $xmlOut .= <<EOX;
710  <CrossReferenceTransaction xmlns="https://www.thepaymentgateway.net/">
711     <PaymentMessage>
712      <MerchantAuthentication MerchantID="$username" Password="$password" />
713       <TransactionDetails Amount="$amount" CurrencyCode="$iso_currency_code_numeric">
714         <MessageDetails TransactionType="$txtype" NewTransaction="$new_transaction" CrossReference="$crossreference" />
715         <OrderID>$order_id</OrderID>
716         <OrderDescription>$orderdescription</OrderDescription>
717              <TransactionControl>
718                   <EchoCardType>TRUE</EchoCardType>
719                   <EchoAVSCheckResult>TRUE</EchoAVSCheckResult>
720                   <EchoCV2CheckResult>TRUE</EchoCV2CheckResult>
721                   <EchoAmountReceived>TRUE</EchoAmountReceived>
722                   <DuplicateDelay>60</DuplicateDelay>
723                   <AVSOverridePolicy>$avsoverridepolicy</AVSOverridePolicy>
724                   <ThreeDSecureOverridePolicy>FALSE</ThreeDSecureOverridePolicy>
725              </TransactionControl>
726       </TransactionDetails>
727       <PassOutData>$passoutdata</PassOutData>
728     </PaymentMessage>
729   </CrossReferenceTransaction>
730 </soap:Body>
731 </soap:Envelope>
732 EOX
733 #::logDebug("Cardsave".__LINE__.": xmlout=$xmlOut");
734         my $msg = postCardsave($xmlOut);
735         my $xml = new XML::Simple();
736         my $data = $xml->XMLin("$msg");
737 #::logDebug("Cardsave".__LINE__.": xmlback=".::uneval($data));
738            $data = $data->{'soap:Body'}->{'CrossReferenceTransactionResponse'};
739            $result{'StatusCode'}  = $data->{'CrossReferenceTransactionResult'}->{'StatusCode'};
740            $result{'AuthAttempt'} = $data->{'CrossReferenceTransactionResult'}->{'AuthorisationAttempted'};
741            $result{'TDSmessage'}  = $data->{'CrossReferenceTransactionResult'}->{'Message'};
742            $result{'MD'}          = $data->{'TransactionOutputData'}->{'CrossReference'};
743 #::logDebug("Cardsave".__LINE__.": xmlback=".::uneval($data));
744
745     }
746 #-------------------------------------------------------------------------------------------------
747 # Now to complete things
748
749 #::logDebug("Cardsave".__LINE__.": on=$::Values->{mv_order_number}; MStatus=$result{MStatus}; SecureStatus=$result{'SecureStatus'}; TDSmsg=$result{'TDSmessage'}");
750 #::logDebug("Cardsave".__LINE__.": result=".::uneval(\%result));
751         my $cardsavedate = $Tag->time({ body => "%A %d %B %Y, %k:%M:%S, %Z" });
752         my $amountshow =  $amount/'100';
753 #::logDebug("Cardsave".__LINE__.": statuscode=$result{StatusCode}; req=$cardsaverequest");
754 # unless ($result{'SecureStatus'}) {
755   if ($result{'StatusCode'} == '0') {
756          $result{'MStatus'} = $result{'pop.status'} = $::Scratch->{'mstatus'} = 'success';
757          $result{'order-id'} ||= $::Session->{'order_id'};
758                  $::Values->{'mv_payment'} = "Real-time card $::Session->{'CardInfo'}";
759 #::logDebug("Cardsave".__LINE__.": mstatus=$result{'MStatus'}; orderid=$result{'order-id'}; $::Session->{'order_id'}"); 
760                 if (charge_param('mail_txn_approved') == '1') {
761                 $::Tag->email({ to => $mailto, from => $mailto, reply => $mailto,
762                                                 subject => "Cardsave txn approved",
763                                                 body => "At $cardsavedate you received payment from $cardholder of $currency$amountshow\n\n" });
764                                           }
765                           }
766    elsif ($result{'StatusCode'} != '0') {
767          $result{'MStatus'} = $result{'pop.status'} = $::Scratch->{'mstatus'} = 'fail';
768          $result{'order-id'} = $result{'pop.order-id'} = '';
769          $result{'MErrMsg'} = charge_param('main3DSerror') || "Payment error: <br>"; # if $result{'TDSmessage'} eq 'FAILED';
770          $result{'MErrMsg'} .= $result{'TDSmessage'} if $result{'TDSmessage'};
771                  $result{'MErrMsg'} .= "$::Session->{'errors'}{'Payment error'}<br>";
772                  $result{'MErrMsg'} .= " Authentication failed<br>" if $result{'TDScheck'}  eq 'FAILED';
773                  $result{'MErrMsg'} .= " Billing Address \"$::Values->{address1}\" failed to match at your bank<br>" if ($result{'AddressResult'} eq 'FAILED' && charge_param('avsoverridepolicy') !~ /^P/i);
774                  $result{'MErrMsg'} .= " Billing PostalCode \"$::Values->{zip}\" failed to match at your bank<br>" if ($result{'PostCodeResult'} eq 'FAILED' && charge_param('avsoverridepolicy') !~ /^A/i);
775                  $result{'MErrMsg'} .= " Card Security Code match failed<br>" if ($result{'CV2Result'} eq 'FAILED' && charge_param('cv2ovreridepolicy') !~ /^P/i);
776                  $::Session->{'errors'}{'Payment error'} = $result{'MErrMsg'};
777 #::logDebug("Cardsave".__LINE__.": on=$::Values->{mv_order_number}; mstatus=$result{'MStatus'}; MErrMsg=$result{'MErrMsg'}"); 
778            }
779   #    }
780
781            $::Session->{'errors'}{'Payment error'} .= "$result{'TDSmessage'}" if ($result{'StatusCode'} == '30');
782 # Now optionally email a message on certain failures, eg those that might indicate attempted fraud
783           my $ierror = lc($result{'TDSmessage'});
784
785           if (($ierror =~ /avs|declined|variable/i) and (charge_param('mail_txn_declined') == '1')) {
786                    $::Tag->email({ to => "$mailto", from => "$mailto",
787                                         subject => "Cardsave payment error",
788                                         body => "\nCardholder: $cardholder
789 Card info: $::Session->{'CardInfo'}
790 Card issuer: $::Session->{'CardIssuer'}
791 Address: $::Values->{address1}, $::Values->{address2}
792 City, Postcode:  $::Values->{city}, $::Values->{zip}
793 Country: $::Values->{country}
794 OrderID: $::Session->{'order_id'}
795 AddressResult: $result{AddressResult}
796 PostCodeResult: $result{PostCodeResult}
797 CV2Result: $result{CV2Result}
798 SecureStatus: $result{SecureStatus}
799 AuthAttempt: $result{'AuthAttempt'}
800 TDSmessage: $result{'TDSmessage'}
801 MD (crossreference): $result{MD}
802 IP address: $ipaddress
803 Date of failure: $cardsavedate
804 Displayed errors: $::Session->{'errors'}{'Payment error'}
805 Logged Error: $result{'TDSmessage'}\n"
806                                  });
807 #::logDebug("Cardsave".__LINE__.": txn error of \"$result{TDSmessage}\" emailed to $mailto"); 
808         }
809         
810 #::logDebug("Cardsave".__LINE__." result:" .::uneval(\%result));
811
812                 return (%result);
813
814 }
815
816 #
817 #--------------------------------------------------------------------------------------------------
818 # End of main routine
819 #--------------------------------------------------------------------------------------------------
820 #
821
822 sub postCardsave {
823          my $self = shift;
824          my $ua = LWP::UserAgent->new;
825             $ua->timeout(30);
826          my $gw = $::Session->{'CardsaveHost'} || $host3;
827 #        my $gw = $host4; # TESTING - this does not exist
828          my $req = HTTP::Request->new('POST' => $gw);
829                 $req->content_type('text/xml');
830                 $req->content_length( length($self) );
831                 $req->content($self);
832          my $res = $ua->request($req);
833          my $respcode = $res->status_line;
834 #::logDebug("Cardsave".__LINE__.": default gw=$gw; session gw=$::Session->{'CardsaveHost'}");
835
836         if ($res->is_success && $res->content){
837                 $::Session->{'CardsaveHost'} = $gw;
838 #::logDebug("Cardsave".__LINE__.": session gw=$gw");
839                 return ($res->content());
840                           }
841          else  { 
842         $req->uri( $host3 );
843         $res = $ua->request($req);
844 #::logDebug("Cardsave".__LINE__.": gw test 1 $host3");
845           if ( $res->is_success && $res->content ) {
846                           $::Session->{'CardsaveHost'} = $host3;
847 #::logDebug("Cardsave".__LINE__.": success gw=$host3");
848                           return $res->content();
849                                 }
850           else { 
851                           $req->uri( $host2 );
852                           $res = $ua->request($req);
853 #::logDebug("Cardsave".__LINE__.":  gw test 2 $host2");
854                                 if ( $res->is_success && $res->content ) {
855 #::logDebug("Cardsave".__LINE__.": success gw=$host2");
856                                    $::Session->{'CardsaveHost'} = $host2;
857                                    return $res->content();
858                                            }
859                                 else { 
860                           $req->uri( $host1 );
861                           $res = $ua->request($req);
862 #::logDebug("Cardsave".__LINE__.": gw test 3 $host1");
863                                 if ( $res->is_success && $res->content ) {
864 #::logDebug("Cardsave".__LINE__.": success gw=$host1");
865                                    $::Session->{'CardsaveHost'} = $host1;
866                                    return $res->content();
867                                           }
868                                 else {
869 #::logDebug("Cardsave".__LINE__.": CARDSAVE RESPONSE IS FAILURE $respcode");
870                                         die ::errmsg("No response from the Cardsave payment gateway, please consider using Paypal instead or try again a little later. Our apologies. ");
871                                         }
872                                 } 
873           } 
874      }
875 }
876
877 sub getcardtypeCardsave {
878
879         my ($pan, $username, $password) = @_;
880         my $xmlOut = <<EOX;
881 <?xml version="1.0" encoding="UTF-8"?>
882 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
883                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
884                xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
885 <soap:Body>
886 <GetCardType xmlns="https://www.thepaymentgateway.net/">
887     <GetCardTypeMessage>
888       <MerchantAuthentication MerchantID="$username" Password="$password" />
889       <CardNumber>$pan</CardNumber>
890     </GetCardTypeMessage>
891   </GetCardType>
892 </soap:Body>
893 </soap:Envelope>
894 EOX
895 #::logDebug("\n===============================Cardsave".__LINE__.": cardtype xmlout=$xmlOut");
896 my $msg = postCardsave($xmlOut);
897         my $xml = new XML::Simple();
898         my $data = $xml->XMLin("$msg");
899 #::logDebug("Cardsave".__LINE__.": cardref=$::Session->{CardRef}");
900 #::logDebug("Cardsave".__LINE__.": cardref=$::Session->{CardRef} : uneval cardtype=".::uneval($data));
901            $data = $data->{'soap:Body'}->{'GetCardTypeResponse'}->{'GetCardTypeOutputData'}->{'CardTypeData'};
902 #::logDebug("Cardsave".__LINE__.": card type data=$data\n===================================================\n");
903                 return($data);
904
905 }
906
907 package Vend::Payment::Cardsave;
908
909 1;