Re: Re: POST without form
| From: | Daniel Dickey | Date: | Tue, 16 Oct 2001 02:54:13 +0000 |
| Subject: | Re: Re: POST without form | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-71166@lists.php.net to get a copy of this message | ||
I thought I would go ahead and provide the sample code for the PayPal
Instant Payment Notification (IPN). It is in PERL and ASP/VBScript and needs
to be converted to PHP. It may help to see it.
Instant Payment Notification - Sample Payment Notification Code
----------------------------------------------------------------------------
--------------------
Sample PERL Code
The code below is an example of a payment notification handler written in
PERL. While this code has been tested by PayPal, PayPal cannot be held
responsible for its use.
#!/usr/local/bin/perl
# read the post from PayPal system and add 'cmd'
read (STDIN, $query, $ENV{'CONTENT_LENGTH'});
$query .= '&cmd=_notify-validate';
# post back to PayPal system to validate
use LWP::UserAgent;
$ua = new LWP::UserAgent;
$req = new HTTP::Request 'POST','https://www.paypal.com/cgi-bin/webscr';
$req->content_type('application/x-www-form-urlencoded');
$req->content($query);
$res = $ua->request($req);
# split posted variables into pairs
@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++;
}
# assign posted variables to local variables
$receiver_email = $variable{'receiver_email'};
$item_name = $variable{'item_name'};
$item_number = $variable{'item_number'};
$custom = $variable{'custom'};
$payment_status = $variable{'payment_status'};
$payment_date = $variable{'payment_date'};
$payment_gross = $variable{'payment_gross'};
$payment_fee = $variable{'payment_fee'};
$txn_id = $variable{'txn_id'};
$first_name = $variable{'first_name'};
$last_name = $variable{'last_name'};
$address_street = $variable{'address_street'};
$address_city = $variable{'address_city'};
$address_state = $variable{'address_state'};
$address_zip = $variable{'address_zip'};
$address_country = $variable{'address_country'};
$payer_email = $variable{'payer_email'};
if ($res->content eq 'VERIFIED') {
# check transaction for uniqueness
# process payment
}
elsif ($res->content eq 'INVALID') {
# possible fraud
}
else {
# error
}
----------------------------------------------------------------------------
------------------
Sample ASP/VBScript Code
The code below is an example of a payment notification handler written in
ASP/VBScript. While this code has been tested by PayPal, PayPal cannot be
held responsible for its use.
Requires Microsoft XML SDK 3.0 available at msdn.microsoft.com.
<%@LANGUAGE="VBScript"%>
<%
Dim str, OrderID, Txn_id, Payment_status
Dim objHttp
str = Request.Form
OrderID = Request.Form("item_number")
Txn_id = Request.Form("txn_id")
Payment_status = Request.Form("payment_status")
' post back to PayPal system to validate
str = str & "&cmd=_notify-validate"
set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objHttp.open "POST", "https://www.paypal.com/cgi-bin/webscr",
false
objHttp.Send str
' Check notification validation
if (objHttp.status <> 200 ) then
' HTTP error handling
elseif (objHttp.responseText = "VERIFIED") then
' process payment
elseif (objHttp.responseText = "INVALID") then
' possible fraud
else
' error
end if
set objHttp = nothing
%>
---------------------------------------------------------------------------
--------------
"Reductor" <sjdtmv@tpg.com.au> wrote in message
news:00d801c152ee$7e1fec80$eb00a8c0@mum...
> you must put to newlines(\n\n) at the end of it all
> ----- Original Message -----
> From: "_lallous" <elias_bachaalany@yahoo.com>
> To: <php-general@lists.php.net>
> Sent: Friday, October 12, 2001 5:59 PM
> Subject: [PHP] Re: POST without form
>
>
> > // simple post method
> > // version 1.0 by Andrus (andrus@vnet.ee)
> >
> > // Disclaimer:
> > // everyone can change or use this code however and wherever they want
;)
> >
> >
> >
> > // send out "browser" headers
> > function send_headers ($fp) {
> > fputs ($fp, "Accept: */*\n");
> > fputs ($fp, "Accept-Language: en\n");
> > fputs ($fp, "Connection: Keep-Alive\n");
> > fputs ($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows
> > 98)\n");
> > }
> >
> > // post data and return reply
> > function post_data ($host, $url, $data) {
> > $fp = @fsockopen ($host, 80, $errno, $errstr, 120);
> > $ret = "";
> > if (strncasecmp ($url, "http://",Í�èÁɰ6Ék\{íÁ
> > Ž 7) == 0) $url = substr
> > ($url, 7);
> > $p = strpos ($url, '/');
> > if (empty ($p)) {
> > $req = "/";
> > } else {
> > $req = substr ($url, $p);
> > }
> > if ($fp) {
> > fputs ($fp, "POST $req HTTP/1.0\n");
> > send_headers ($fp);
> > fputs ($fp, "Content-type: application/x-www-form-urlencoded\n");
> > $out = "";
> > while (list ($k, $v) = each ($data)) {
> > if(strlen($out) != 0) $out .= "&";
> > $out .= rawurlencode($k). "=" .rawurlencode($v);
> > }
> > $out = trim ($out);
> > fputs ($fp, "Content-length: ".strlen($out)."\n\n");
> > fputs ($fp, "$out");
> > fputs ($fp, "\n");
> > while(!feof($fp)){
> > $ret .= fgets($fp,128);
> > }
> > fclose ($fp);
> > }
> > return $ret;
> > }
> > // example how to use:
> >
> > // following code will post variables "login" and "pass" to server
> > "www.something.com" script "/submit.php"
> > $reply = post_data ("www.something.com", "/submit.php", array
> > ("login"
=>
> > $username, "pass" => $password));
> >
> >
> > "Daniel Dickey" <daniel_dickey@hotmail.com> wrote in message
> > news:20011011160148.24821.qmail@pb1.pair.com...
> > > How do I send a POST without using a form?
> > >
> > >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail: php-list-admin@lists.php.net
> >
>