Paypal IPN: how get the POSTs from this class?
Posted
by
sineverba
on Stack Overflow
See other posts from Stack Overflow
or by sineverba
Published on 2013-11-07T21:23:17Z
Indexed on
2013/11/08
3:54 UTC
Read the original article
Hit count: 231
I'm using this Class
<?php
class paypalIPN {
//sandbox:
private $paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
//live site:
//private $paypal_url = 'https://www.paypal.com/cgi-bin/webscr';
private $data = null;
public function __construct()
{
$this->data = new stdClass;
}
public function isa_dispute()
{
//is it some sort of dispute.
return $this->data->txn_type == "new_case";
}
public function validate()
{
// parse the paypal URL
$response = "";
$url_parsed = parse_url($this->paypal_url);
// generate the post string from the _POST vars aswell as load the
// _POST vars into an arry so we can play with them from the calling
// script.
$post_string = '';
foreach ($_POST as $field=>$value) {
$this->data->$field = $value;
$post_string .= $field.'='.urlencode(stripslashes($value)).'&';
}
$post_string.="cmd=_notify-validate"; // append ipn command
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->paypal_url);
//curl_setopt($ch, CURLOPT_VERBOSE, 1);
//keep the peer and server verification on, recommended
//(can switch off if getting errors, turn to false)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
$response = curl_exec($ch);
if (curl_errno($ch))
{
die("Curl Error: " . curl_errno($ch) . ": " . curl_error($ch));
}
curl_close($ch);
return $response;
if (preg_match("/VERIFIED/", $response))
{
// Valid IPN transaction.
return $this->data;
}
else
{
return false;
}
}
}
ANd i recall in this mode:
public function get_ipn()
{
$ipn = new paypalIPN();
$result = $ipn->validate();
$logger = new Log('/error.log');
$logger->write(print_r($result));
}
But I obtain only "VERIFIED" or "1" (whitout or with the print_r function).
I just tried also to return directly the raw curl response with
return $response;
or
return $this->response;
or also
return $this->parse_string;
but everytime I receive only "1" or "VERIFIED".......
Thank you very much
© Stack Overflow or respective owner