Posts: 427
Name: Stuart
Location: Glasgow, Scotland
|
Hi Guys
Looking for some help with a PayPal IPN...
Im pretty sure i had this script working before then i had to leave it and noiw that ive come back to it it isnt working!
After going through the paypal cart and payment the IPN file can never get to the VERIFIED block. It always is 'unverified'. Im not sure if this is a setting of the sandbox paypal account that needs to be set to allow these users (i dont know what verified users are (or if it is infact something to do with the transaction itself) but why wouldnt i want their money?! )
Anyways, the cut-down code is below at the moment im just trying to get the basic thing working before i put in the stuff to process the cart items and stuff.
PHP Code:
<?php
include('config.php');
//------------------------------------------------ // Read post from PayPal system and create reply // starting with: 'cmd=_notify-validate'... // then repeating all values sent - VALIDATION. //------------------------------------------------ $postvars = array(); while (list ($key, $value) = each ($HTTP_POST_VARS)) { $postvars[] = $key; }
$req = 'cmd=_notify-validate';
for ($var = 0; $var < count ($postvars); $var++) { $postvar_key = $postvars[$var]; $postvar_value = $$postvars[$var]; $req .= "&" . $postvar_key . "=" . urlencode ($postvar_value); }
//-------------------------------------------- // Create message to post back to PayPal... // Open a socket to the PayPal server... //-------------------------------------------- $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen ($req) . "\r\n\r\n"; $fp = fsockopen ("www.sandbox.paypal.com", 80, $errno, $errstr, 30);
//---------------------------------------------
//---------------------------------------------------------------------- // Check HTTP connection made to PayPal OK, If not, print an error msg //---------------------------------------------------------------------- if (!$fp) { //echo "$errstr ($errno)"; //fwrite($log, "Failed to open HTTP connection!"); $res = "FAILED"; } //-------------------------------------------------------- // If connected OK, write the posted values back, then... //-------------------------------------------------------- else {
fputs ($fp, $header . $req); //------------------------------------------- // ...read the results of the verification... // If VERIFIED = continue to process the TX... //------------------------------------------- while (!feof($fp)) { $res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) { //---------------------------------------------------------------------- // If the payment_status=Completed... Get the password for the product // from the DB and email it to the customer. //---------------------------------------------------------------------- if (strcmp ($payment_status, "Completed") == 0) { //do whatever } //---------------------------------------------------------------------- // If the payment_status is NOT Completed... You'll have to send the // password later, by hand, when the funds clear... //---------------------------------------------------------------------- else { //do whatever } } //---------------------------------------------------------------- // ..If UNVerified - It's 'Suspicious' and needs investigating! // Send an email to yourself so you investigate it. //---------------------------------------------------------------- else { //do whatever } } }
//------------------------------------------- // Close PayPal Connection, Log File and DB. //------------------------------------------- fclose ($fp); ?>
Btw, this script is based on one i got online somewhere so apparently should work!
Last edited by stoot98; 12-18-2008 at 04:28 AM..
|