Prev: Perl DBI module hanging (transaction isolation)
Next: FAQ 9.17 How do I check a valid mail address?
From: Graham on 6 Jan 2010 13:04 Below is a suggested 'Automatic Payment Confirmation' script copied and pasted from the Nochex Developer's forum (Nochex themselves do not offer support in Perl). This thread is now closed and I suspect the Nochex forum does not get much traffic, hence this post here. I have spotted one error (the line '$mail_method = "sendmail";' needs to be added if using sendmail). However, even with this correction, the script always goes down the first of the four 'if (res->' options (i.e. (res->is_error)), and thus none of my test transactions are being authorised, which makes me suspect that there is something wrong with the following lines:- use LWP::UserAgent; $ua = new LWP::UserAgent; $req = new HTTP::Request "POST","https://www.nochex.com/nochex.dll/apc/apc"; $req->content_type("application/x-www-form-urlencoded"); $req->content($query); $res = $ua->request($req); Anyone any ideas? #!/usr/bin/perl # REPLACE THIS WITH YOUR NOCHEX EMAIL ADDRESS. $admin_email = "sales(a)geodetech.com"; # THIS SHOULD BE EITHER smtp OR sendmail DEPENDING # ON THE MAIL METHOD YOU WANT TO USE. $mail_method = "smtp"; # IF YOU ARE USING SENDMAIL TO SEND EMAIL # SET THE PATH TO SENDMAIL ON YOUR SERVER. # IN ALL PROBABILITY THE DEFAULT WILL WORK $sendmail_path = "/usr/sbin/sendmail -t"; # IF YOU ARE USING SMTP TO SEND EMAIL # SPECIFY THE SMTP SERVER TO USE. # IN ALL PROBABILITY THE DEFAULT WILL WORK $smtp_server = "localhost"; read (STDIN, $query, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $query); $count = 0; foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $variable{$name} = $value; $count++; } $transaction_id = $variable{'transaction_id'}; $transaction_date = $variable{'transaction_date'}; $from_email = $variable{'from_email'}; $to_email = $variable{'to_email'}; $order_id = $variable{'order_id'}; $amount = $variable{'amount'}; $security_key = $variable{'security_key'}; use LWP::UserAgent; $ua = new LWP::UserAgent; $req = new HTTP::Request "POST","https://www.nochex.com/nochex.dll/apc/apc"; $req->content_type("application/x-www-form-urlencoded"); $req->content($query); $res = $ua->request($req); if ($res->is_error) { $subject = "Perl APC Script Error - Could not connect to Nochex servers"; $message = "Your Perl APC script was called but returned an error because it \ncould not connect with the NOCHEX servers.\n."; } elsif ($res->content eq "AUTHORISED") { $subject = "APC Result - AUTHORISED"; $message = "NOCHEX RESPONSE: AUTHORISED\n-----------------------------------------------\nOrder submitted with ID: ".$order_id."\n-----------------------------------------------\ntransaction id:\t".$transaction_id."\ntransaction date:\t".$transaction_date."\nfrom email:\t".$from_email."\nto email:\t".$to_email."\norder_id:\t".$order_id."\namount:\t".$amount."\nsecurity key:\t".$security_key."\n"; } elsif ($res->content eq "DECLINED") { $subject = "APC Result - DECLINED"; $message = "NOCHEX RESPONSE: DECLINED\n-----------------------------------------------\nOrder submitted with ID: ".$order_id."\n-----------------------------------------------\ntransaction id:\t".$transaction_id."\ntransaction date:\t".$transaction_date."\nfrom email:\t".$from_email."\nto email:\t".$to_email."\norder_id:\t".$order_id."\namount:\t".$amount."\nsecurity key:\t".$security_key."\n"; } else { $subject = "Invalid APC Result Returned"; $message = "The NOCHEX APC server returned an unrecognised or invalid response. In \nall probability due to en error in your code but could be the APC \nserver screwing up.\n-----------------------------------------------\nOrder submitted with ID: ".$order_id."\n-----------------------------------------------\ntransaction id:\t".$transaction_id."\ntransaction date:\t".$transaction_date."\nfrom email:\t".$from_email."\nto email:\t".$to_email."\norder_id:\t".$order_id."\namount:\t".$amount."\nsecurity key:\t".$security_key."\n"; } print "Content-Type: text/plain\n\n"; if ($mail_method eq "smtp") { use Net::SMTP; $smtp = Net::SMTP->new($smtp_server); $smtp->mail($ENV{USER}); $smtp->to($admin_email); $smtp->data(); $smtp->datasend("From: APC Script <apc_script(a)your.website>\n"); $smtp->datasend("To: ".$admin_email."\n"); $smtp->datasend("Subject: ".$admin_email."\n"); $smtp->datasend("Content-Type: text/plain\n"); $smtp->datasend("\n"); $smtp->datasend($message); $smtp->dataend(); $smtp->quit; } elsif ($mail_method eq "sendmail") { open(SENDMAIL, "|$sendmail_path") or die "Cannot open sendmail: $!"; print SENDMAIL "From: APC Script <apc_script(a)your.website>\n"; print SENDMAIL "To: ".$admin_email."\n"; print SENDMAIL "Subject: ".$subject."\n"; print SENDMAIL "Content-Type: text/plain\n\n"; print SENDMAIL $message; close(SENDMAIL); }
From: Sherm Pendley on 6 Jan 2010 14:33 On Jan 6, 12:04 pm, "Graham" <graham.s...(a)stowassocs.co.uk> wrote: > Below is a suggested 'Automatic Payment Confirmation' script copied and > pasted from the Nochex Developer's forum (Nochex themselves do not offer > support in Perl). This thread is now closed and I suspect the Nochex forum > does not get much traffic, hence this post here. I have spotted one error > (the line '$mail_method = "sendmail";' needs to be added if using sendmail). > However, even with this correction, the script always goes down the first of > the four 'if (res->' options (i.e. (res->is_error)), and thus none of my > test transactions are being authorised, which makes me suspect that there is > something wrong with the following lines:- > > use LWP::UserAgent; > $ua = new LWP::UserAgent; > $req = new HTTP::Request "POST","https://www.nochex.com/nochex.dll/apc/apc"; > $req->content_type("application/x-www-form-urlencoded"); > $req->content($query); > $res = $ua->request($req); > > Anyone any ideas? > > #!/usr/bin/perl > > # REPLACE THIS WITH YOUR NOCHEX EMAIL ADDRESS. > $admin_email = "sa...(a)geodetech.com"; > > # THIS SHOULD BE EITHER smtp OR sendmail DEPENDING > # ON THE MAIL METHOD YOU WANT TO USE. > $mail_method = "smtp"; > > # IF YOU ARE USING SENDMAIL TO SEND EMAIL > # SET THE PATH TO SENDMAIL ON YOUR SERVER. > # IN ALL PROBABILITY THE DEFAULT WILL WORK > $sendmail_path = "/usr/sbin/sendmail -t"; > > # IF YOU ARE USING SMTP TO SEND EMAIL > # SPECIFY THE SMTP SERVER TO USE. > # IN ALL PROBABILITY THE DEFAULT WILL WORK > $smtp_server = "localhost"; > > read (STDIN, $query, $ENV{'CONTENT_LENGTH'}); > > @pairs = split(/&/, $query); > $count = 0; > foreach $pair (@pairs) { > ($name, $value) = split(/=/, $pair); > $value =~ tr/+/ /; > $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; > $variable{$name} = $value; > $count++; > > } > > $transaction_id = $variable{'transaction_id'}; > $transaction_date = $variable{'transaction_date'}; > $from_email = $variable{'from_email'}; > $to_email = $variable{'to_email'}; > $order_id = $variable{'order_id'}; > $amount = $variable{'amount'}; > $security_key = $variable{'security_key'}; > > use LWP::UserAgent; > $ua = new LWP::UserAgent; > $req = new HTTP::Request "POST","https://www.nochex.com/nochex.dll/apc/apc"; > $req->content_type("application/x-www-form-urlencoded"); > $req->content($query); > $res = $ua->request($req); > > if ($res->is_error) { > $subject = "Perl APC Script Error - Could not connect to Nochex servers"; > $message = "Your Perl APC script was called but returned an error because > it \ncould not connect with the NOCHEX servers.\n.";} elsif ($res->content eq "AUTHORISED") { > > $subject = "APC Result - AUTHORISED"; > $message = "NOCHEX RESPONSE: > AUTHORISED\n-----------------------------------------------\nOrder submitted > with ID: > ".$order_id."\n-----------------------------------------------\ntransaction > id:\t".$transaction_id."\ntransaction date:\t".$transaction_date."\nfrom > email:\t".$from_email."\nto > email:\t".$to_email."\norder_id:\t".$order_id."\namount:\t".$amount."\nsecu rity > key:\t".$security_key."\n";} elsif ($res->content eq "DECLINED") { > > $subject = "APC Result - DECLINED"; > $message = "NOCHEX RESPONSE: > DECLINED\n-----------------------------------------------\nOrder submitted > with ID: > ".$order_id."\n-----------------------------------------------\ntransaction > id:\t".$transaction_id."\ntransaction date:\t".$transaction_date."\nfrom > email:\t".$from_email."\nto > email:\t".$to_email."\norder_id:\t".$order_id."\namount:\t".$amount."\nsecu rity > key:\t".$security_key."\n";} else { > > $subject = "Invalid APC Result Returned"; > $message = "The NOCHEX APC server returned an unrecognised or invalid > response. In \nall probability due to en error in your code but could be the > APC \nserver screwing > up.\n-----------------------------------------------\nOrder submitted with > ID: > ".$order_id."\n-----------------------------------------------\ntransaction > id:\t".$transaction_id."\ntransaction date:\t".$transaction_date."\nfrom > email:\t".$from_email."\nto > email:\t".$to_email."\norder_id:\t".$order_id."\namount:\t".$amount."\nsecu rity > key:\t".$security_key."\n"; > > } > > print "Content-Type: text/plain\n\n"; > > if ($mail_method eq "smtp") { > use Net::SMTP; > $smtp = Net::SMTP->new($smtp_server); > $smtp->mail($ENV{USER}); > $smtp->to($admin_email); > $smtp->data(); > $smtp->datasend("From: APC Script <apc_scr...(a)your.website>\n"); > $smtp->datasend("To: ".$admin_email."\n"); > $smtp->datasend("Subject: ".$admin_email."\n"); > $smtp->datasend("Content-Type: text/plain\n"); > $smtp->datasend("\n"); > $smtp->datasend($message); > $smtp->dataend(); > $smtp->quit;} elsif ($mail_method eq "sendmail") { > > open(SENDMAIL, "|$sendmail_path") or die "Cannot open sendmail: $!"; > print SENDMAIL "From: APC Script <apc_scr...(a)your.website>\n"; > print SENDMAIL "To: ".$admin_email."\n"; > print SENDMAIL "Subject: ".$subject."\n"; > print SENDMAIL "Content-Type: text/plain\n\n"; > print SENDMAIL $message; > close(SENDMAIL); > > > > } Why did you post this here? Seems to me *someone* forgot what groups are for what! ;) sherm--
From: C.DeRykus on 6 Jan 2010 21:13 On Jan 6, 10:04 am, "Graham" <graham.s...(a)stowassocs.co.uk> wrote: > Below is a suggested 'Automatic Payment Confirmation' script copied and > pasted from the Nochex Developer's forum (Nochex themselves do not offer > support in Perl). This thread is now closed and I suspect the Nochex forum > does not get much traffic, hence this post here. I have spotted one error > (the line '$mail_method = "sendmail";' needs to be added if using sendmail). > However, even with this correction, the script always goes down the first of > the four 'if (res->' options (i.e. (res->is_error)), and thus none of my > test transactions are being authorised, which makes me suspect that there is > something wrong with the following lines:- > ... I notice that you didn't get status to confirm that res->is_error is returning a 401 authorization error... > if ($res->is_error) { > $subject = "Perl APC Script Error - ... "; > $message = "Your Perl APC script was called . $status = $res->status_line; # confirm actual error } elsif { ... Also: use LWP::Debug qw/+/; # add debug trace as needed -- Charles DeRykus
From: Graham on 7 Jan 2010 04:46 "C.DeRykus" <derykus(a)gmail.com> wrote in message news:d0499caa-19a9-4394-9410-0931f735192c(a)26g2000yqo.googlegroups.com... On Jan 6, 10:04 am, "Graham" <graham.s...(a)stowassocs.co.uk> wrote: > Below is a suggested 'Automatic Payment Confirmation' script copied and > pasted from the Nochex Developer's forum (Nochex themselves do not offer > support in Perl). This thread is now closed and I suspect the Nochex forum > does not get much traffic, hence this post here. I have spotted one error > (the line '$mail_method = "sendmail";' needs to be added if using > sendmail). > However, even with this correction, the script always goes down the first > of > the four 'if (res->' options (i.e. (res->is_error)), and thus none of my > test transactions are being authorised, which makes me suspect that there > is > something wrong with the following lines:- > ... I notice that you didn't get status to confirm that res->is_error is returning a 401 authorization error... > if ($res->is_error) { > $subject = "Perl APC Script Error - ... "; > $message = "Your Perl APC script was called . $status = $res->status_line; # confirm actual error } elsif { ... Also: use LWP::Debug qw/+/; # add debug trace as needed -- Charles DeRykus I've added '$status = $res->status;' line where suggested, and have also added the lines '$response_as_string = $res->as_string;' and '$error_as_html = $res->error_as_HTML;'. When I print these, I get the following output:- ---------------------------------------------------------------------- response_as_string = HTTP/1.1 411 Length Required Connection: close Date: Thu, 07 Jan 2010 09:32:22 GMT Content-Length: 24 Content-Type: text/html Client-Date: Thu, 07 Jan 2010 09:32:19 GMT Client-Peer: [REMOVED FOR SECURITY] Client-Response-Num: 1 Client-SSL-Cert-Issuer: /C=US/O=Equifax/OU=Equifax Secure Certificate Authority Client-SSL-Cert-Subject: /C=GB/ST=West Yorkshire/L=Leeds/O=Nochex Ltd/OU=GB/CN=www.nochex.com Client-SSL-Cipher: RC4-MD5 Client-SSL-Warning: Peer certificate not verified <h1>Length Required</h1>error_as_html = <HTML> <HEAD><TITLE>An Error Occurred</TITLE></HEAD> <BODY> <H1>An Error Occurred</H1> 411 Length Required </BODY> </HTML> status = 411 Length Required-----------------------------------------------So it appears that a length is required. It may be a stupid question, but a length of what, and how should I provide it within the following code?use LWP::UserAgent;$ua = new LWP::UserAgent;$req = new HTTP::Request('POST', 'https://www.nochex.com/nochex.dll/apc/apc');$req->content_type("application/x-www-form-urlencoded");$req->content($query);$res = $ua->request($req);
From: Graham on 7 Jan 2010 07:27 This is awfully embarassing, but the reason for the 'length required' error appears to be that no data is being sent from the Nochex servers (obviously I should have checked that first before bothering folk). Why this is happening (or rather not happening) I can't imagine - I'm querying this with Nochex, but they just don't answer the support queries.
|
Next
|
Last
Pages: 1 2 3 4 Prev: Perl DBI module hanging (transaction isolation) Next: FAQ 9.17 How do I check a valid mail address? |