All pastes #79273 Raw Edit

Paypal IPN PHP Scrip

public php v1 · immutable
·published 2006-07-05 04:21 UTC
rendered paste body
<?php////////////////////////////////////////////////////////////////////////////////// example.php// PHP paypal_ipn class example////////////////////////////////////////////////////////////////////////////////require("paypal_ipn.php");// PayPal will send the information through a POST$paypal_info = $HTTP_POST_VARS;// To disable https posting to PayPal uncomment the following// $paypal_ipn = new paypal_ipn($paypal_info, "");// Then comment out this one$paypal_ipn = new paypal_ipn($paypal_info);// where to contact us if something goes wrong$paypal_ipn->error_email = "webmaster@example.com";// We send an identical response back to PayPal for verification$paypal_ipn->send_response();// PayPal will tell us whether or not this order is valid.// This will prevent people from simply running your order script// manuallyif( !$paypal_ipn->is_verified() ){	// bad order, someone must have tried to run this script manually	$paypal_ipn->error_out("Bad order (PayPal says it's invalid)");}// payment statusswitch( $paypal_ipn->get_payment_status() ){	case 'Completed':		// order is good	break;	case 'Pending':		// money isn't in yet, just quit.		// paypal will contact this script again when it's ready		$paypal_ipn->error_out("Pending Payment");	break;	case 'Failed':		// whoops, not enough money		$paypal_ipn->error_out("Failed Payment");	break;	case 'Denied':		// denied payment by us		// not sure what causes this one		$paypal_ipn->error_out("Denied Payment");	break;	default:		// order is no good		$paypal_ipn->error_out("Unknown Payment Status" . $paypal_ipn->get_payment_status());	break;} // end switch// If we made it down here, the order is verified and payment is complete.// You could log the order to a MySQL database or do anything else at this point.// Email the information to us$date = date("D M j G:i:s T Y", time());$message .= "\n\nThe following info was received from PayPal - $date:\n\n";@reset($paypal_info);while( @list($key,$value) = @each($paypal_info) ){	$message .= $key . ':' . " \t$value\n";}mail("root@example.com", "[$date] PayPal Payment Notification", $message);?>