Jump to content


Photo

IPN and the Sandbox


  • This topic is locked This topic is locked
1 reply to this topic

#1 PayPalStephen

PayPalStephen

    Advanced Member

  • Members
  • 2,138 posts

Posted 21 November 2003 - 11:32 AM

Please use this Topic for issues or questions about setting your IPN script to use with the Sandbox.

Stephen Ivaskevicius
PayPal/eBay, Inc.
www.paypal.com/pdn

#2 PayPal_Paulam

PayPal_Paulam

    Average Member

  • Members
  • 511 posts

Posted 21 November 2003 - 02:21 PM

Here is a modified version that we need to adjust in order to make it work for us. Our adjustments is quoted as "//Adjustments:".

<?php

#########################################################
# Copyright © EliteWeaver UK All rights reserved. #
#########################################################
# #
# Program : IPN Development Handler (SandBox) #
# Author : Marcus Cicero #
# File : notify.php #
# Function : Skeleton SandBox IPN Handler #
# Version : 1.0 #
# Last Modified : 11/01/2003 #
# Copyright © : EliteWeaver UK #
# #
#########################################################
# THIS SCRIPT IS FREEWARE AND IS NOT FOR RE-SALE! #
#########################################################
# END USER LICENCE AGREEMENT #
# Redistribution and use in source and/or binary forms #
# with or without modification, are permitted provided #
# that the above copyright notice is reproduced in the #
# script, documentation and/or any other materials that #
# may have been provided in the original distribution. #
#########################################################
# Copyright © EliteWeaver UK All rights reserved. #
#########################################################


//* Please set the following two variables

$certfile = 'cert/devusername.pem'; // Path to your pem certificate
$certpass = 'password'; // Password for the above, probably password


// Adjustment: This is the adjustment that we have to make in order to make it work for us

if (!isset($txn_type))
{

echo("No Post!!!!");
exit;
}

else
{

echo("Post");



// Add "cmd" to prepare for post back validation
// Read the ipn post from the test paypal sandbox
// Fix issue with php magic quotes enabled on gpc
// Apply variable antidote (replaces array filter)
// Destroy the original ipn post (security reason)
// Reconstruct the ipn string ready for the post


$ipnpost = 'cmd=_notify-validate'; // Notify validate

foreach ($_POST as $ipnkey => $ipnval)
{
if (get_magic_quotes_gpc())
$ipnval = stripslashes ($ipnval); // Fix issue with magic quotes
if (!eregi("^[_0-9a-z-]{1,30}$",$ipnkey)
|| !strcasecmp ($ipnkey, 'cmd'))
{ // ^ Antidote to potential variable injection and poisoning
unset ($ipnkey); unset ($ipnval); } // Eliminate the above
if (@$ipnkey != '') { // Remove empty keys (not values)
@$_PAYPAL[$ipnkey] = $ipnval; // Assign data to new global array
unset ($_POST); // Destroy the original ipn post array, sniff...

$ipnpost.='&'.@$ipnkey.'='.urlencode(@$ipnval); }} // Notify string


// Post back the reconstructed instant payment notification

$ipnexec = curl_init();

curl_setopt($ipnexec, CURLOPT_PROXY, 'sandbox.paypal.com:8080');
curl_setopt($ipnexec, CURLOPT_URL, 'https://www.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ipnexec, CURLOPT_HEADER, 0);
curl_setopt($ipnexec, CURLOPT_USERAGENT, 'Server Software: '.@$_SERVER['SERVER_SOFTWARE'].' PHP Version: '.phpversion());
curl_setopt($ipnexec, CURLOPT_REFERER, $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].@$_SERVER['QUERY_STRING']);
curl_setopt($ipnexec, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ipnexec, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ipnexec, CURLOPT_SSLCERT, $certfile);
curl_setopt($ipnexec, CURLOPT_SSLCERTPASSWD, $certpass);
curl_setopt($ipnexec, CURLOPT_POST, 1);
curl_setopt($ipnexec, CURLOPT_POSTFIELDS, $ipnpost);
curl_setopt($ipnexec, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ipnexec, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ipnexec, CURLOPT_TIMEOUT, 30);

$ipnresult = trim(curl_exec($ipnexec));

if (curl_error($ipnexec))
{
printf("Error %s: %s", curl_errno($ipnexec), curl_error($ipnexec)); }

else
{

// uncomment '#' to assign posted variables to local variables
#extract($_PAYPAL); // if globals is on they are already local

// and/or >>>

// refer to each ipn variable by reference (recommended)
// $_PAYPAL['receiver_id']; etc... (see: ipnvars.txt)



//Adjustment: We send out emails so we can track if the ipn script is going ok

mb_send_mail ( "youremail@yourdomain.com", "IPN Script", "My Script was hit".$txn_type.$ipn_test);

// IPN was confirmed as both genuine and VERIFIED

if (!strcmp ($ipnresult, "VERIFIED"))
{
mb_send_mail ( "youremail@yourdomain.com", "IPN Script", "Verified Transaction");

}

// IPN was not validated as genuine and is INVALID

elseif (!strcmp ($ipnresult, "INVALID"))
{
echo("INVALID response from IPN post");
mb_send_mail ( "youremail@yourdomain.com", "IPN Script", "Invalid Transaction");
}


else
{ // Just incase something serious should happen!
mb_send_mail ( "youremail@yourdomain.com", "IPN Script", "Post is not Verified or Invalid");
}}


// Terminate the socket connection (if open) and exit

@curl_close ($ipnexec); exit; }

#########################################################
# Copyright © EliteWeaver UK All rights reserved. #
#########################################################
# END USER LICENCE AGREEMENT #
# Redistribution and use in source and/or binary forms #
# with or without modification, are permitted provided #
# that the above copyright notice is reproduced in the #
# script, documentation and/or any other materials that #
# may have been provided in the original distribution. #
#########################################################
# THIS SCRIPT IS FREEWARE AND IS NOT FOR RE-SALE! #
#########################################################

?>

Paulam
Technical Support Agent





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users