Gossamer Forum
Home : General : Perl Programming :

SSL and Parsing Forms... Need Help, Alex? :)

Quote Reply
SSL and Parsing Forms... Need Help, Alex? :)
Hi all

I'm trying to do script to connect to a online credit card processing company, but I don't want to send the users directly to then since my webserver it's in portuguese and there system it's in english.

This script scripts receive the POST request from a form and it should connect to the credit card processing company but it's not parsing the data correctly:

Code:
#!/usr/local/bin/perl
require Net::SSL;
read(STDIN, $data, $ENV{'CONTENT_LENGTH'});
$ENV{SSL_CIPHER}="EXP-RC4-MD5";

$sock = Net::SSL->new(PeerAddr => "secure.creditcardcompany.com", PeerPort => 443) | | die "Can't connect";

$mlength=length($data);

$sock->print("POST /cgi-bin/script.cgi HTTP/1.0\n\n");
$sock->print("Accept: www/source\n");
$sock->print("Accept: text/html\n");
$sock->print("Accept: text/plain\n");
$sock->print("User-Agent: Mozilla/4.0\n");
$sock->print("Content-type: application/x-www-form-urlencoded\n");
$sock->print("Content-length: $mlength\n\n");
$sock->print("$data\n");

while ($sock->read($buf, 1024)) {
$resp.=$buf;
}


The answer I receive it's "Sorry -- this order form cannot be processed. The merchant identification is missing or invalid. Please inform the merchant of the problem."
And I know that the information in the form it's correct because if I send it directly to the credit card company it works fine, so the problem is in the way the script it's sending the information.
Can anyone help? Smile

Rogerio Morais
www.rogerle.com

Quote Reply
Re: SSL and Parsing Forms... Need Help, Alex? :) In reply to
Hi,

I noticed in your:
$ENV{SSL_CIPHER}
There were no quotes?
Do you hope it could be that easy to replace it with:
$ENV{'SSL_CIPHER'}

Other than that...I don't know! But I would be interested in taking a look at your code when you get it to work. I have been trying to figure out how to do what you are doing for Authorize.NET and iTransact. I mean I got them integrated and all but I'd like to cut out the step of having the store visitors seeing the CC Processors ugly pages. If you could let me take a look when it is completed I'd really owe you one!

Rod
Quote Reply
Re: SSL and Parsing Forms... Need Help, Alex? :) In reply to
Hi Phoule

The problem wasn't that. Frown
But you can use the code freely. No problem with that. To iTransact just change the:
Code:
PeerAddr => "secure.redi-check.com"

and

$sock->print("POST /cgi-bin/rc3/ord.cgi HTTP/1.0\n\n");

For Authorizenet it's:
Code:
PeerAddr => "www.authorize.net"

and

$sock->print("POST /scripts/authnet25/AuthRequest.asp HTTP/1.0\n");

Now what we need is "just" a way to parse the form information and sending it to the credit card server in the correct way. Smile

------------------
Rogerio Morais
http://www.rogerle.com
Quote Reply
Re: SSL and Parsing Forms... Need Help, Alex? :) In reply to
It looks good to me. What I would do is test it out on your own server. Create a script like:

Code:
#!/usr/local/bin/perl
use CGI;
my $in = new CGI;
print $in->header('text/plain');
foreach ($in->param) {
print "$_ => ", $in->param($_), "\n";
}
# ----------------------------

and then try posting to that using the SSL script and see what comes out.

Hope that helps,

Alex
Quote Reply
Re: SSL and Parsing Forms... Need Help, Alex? :) In reply to
Hi Alex, thank you for your reply.

I try another approch to the problem. And it seens like it works.
I just want to confirm if it sends the information throught SSL:

Code:
use LWP::UserAgent;
use CGI;

read(STDIN, $data, $ENV{'CONTENT_LENGTH'});

$ua = new LWP::UserAgent;
$ua->agent("Mozilla/4.0" . $ua->agent);

$ENV{'SSL_CIPHER'}="EXP-RC4-MD5";
my $req = new HTTP::Request POST => 'https://secure.redi-check.com/cgi-bin/rc3/ord.cgi';
$req->content_type('application/x-www-form-urlencoded');
$req->content($data);
my $results = $ua->request($req);




------------------
Rogerio Morais
http://www.rogerle.com