tim: PayPal

Hallo

sitz zum glück in der ersten etage, sonst hätt ich mein rechner schon zum fenster raus geschmissen - lohnt sich aber noch nicht.

und zwar::: bin grad dabei folgendes zu realisieren:

schritt 1: klick auf "Jetzt kaufen" Schaltfläche von PayPal schritt 2: bezahldaten senden.

bis hier noch alles ok.

schritt 3: es soll ein kostenpflichtiges formular aufgerufen werden, dass jeweils nur einmal pro bezahlung geöffnet werden kann.

paypal liefert ja einen tollen token zurück, womit man das überprüfen kann - aber scheiße is!

in der theorie lässt sich das script testen. es liefert nach der bezahlung auch werte zurück. in der paypal umgebung bleibt die seite jedoch leer und ich kann das token nicht überprüfen!!! schöne scheiße!

hier die links:

paychecker.de/test/test.php (PHP Check) paychecker.de/test/paypal.php (kann unter http://www.belahost.com/pp/  getestet werden)

paypal.php

<?php #1 = Live on PayPal Network 2 = Testing with BelaHost.com $verifymode = "2"; # be sure to change value for testing/live!

Send notifications to here

$send_mail_to = "sandbox5@paychecker.de";

subject of messages

$sysname = "Paypal IPN Transaction";

Your primary PayPal e-mail address

$paypal_email = "sandbox5@paychecker.de";

Your sendmail path

$mailpath = "/usr/sbin/sendmail -t";

#the name you wish to see the messages from $from_name = "PAYCHECKER";

#the emails will be coming from $from_email = "info@paychecker.de";

Convert Super globals For backward compatibility

if(phpversion() <= "4.0.6")  { $_POST= ($HTTP_POST_VARS);  }

Check for IPN post if non then return 404 error.

if (!$_POST['txn_type']) {header("Status: 404 Not Found");exit; } else { header("Status: 200 OK");    }

Now we Read the Posted IPN

$postvars = array();

foreach ($_POST as $ipnvars => $ipnvalue) $postvars[] = $ipnvars;

$postipn = 'cmd=_notify-validate'; # Now we ADD "cmd=_notify-validate" for Post back Validation                    $orgipn = '<b>Posted IPN variables in order received:</b><br><br>';     # Prepare for validation             for ($x=0; $x < count($postvars); $x++) { $y=$x+1; $postkey = $postvars[$x]; $postval = $$postvars[$x]; $postipn.= "&" . $postkey . "=" . urlencode($postval);  $orgipn.= "<b>#" . $y . "</b> Key: " . $postkey . " <b>=</b> " . $postval . "<br>";  }

Verify Mode 1: This will post the IPN variables to the Paypal Network for Validation

if     ($verifymode == 1)             { $port = fsockopen ("sandbox.paypal.com", 80, $errno, $errstr, 30); $header = "POST /cgi-bin/webscr HTTP/1.0\r\n"."Host: www.sandbox.paypal.com\r\n"."Content-Type: application/x-www-form-urlencoded\r\n"."Content-Length: " . strlen($postipn) . "\r\n\r\n";             }

Verify Mode 2: This will post the IPN variables to Belahost Test Script for validation

Located at www.belahost.com/pp/index.php

elseif ($verifymode == 2)             { $port = fsockopen ("www.belahost.com", 80, $errno, $errstr, 30); $header = "POST /pp/ HTTP/1.0\r\n"."Host: www.belahost.com\r\n"."Content-Type: application/x-www-form-urlencoded\r\n"."Content-Length: " . strlen($postipn) . "\r\n\r\n";             } else { $error=1; echo "CheckMode: " . $verifymode . " is invalid!";  exit; }

Error at this point: If at this point you need to check your Firewall or your Port restrictions?

Setup email Notification here to trouble shoot. . .

if (!$port && !$error)             {    echo "Problem: Error Number: " . $errno . " Error String: " . $errstr;    send_mail("$send_mail_to", "$sysname", "\nYour Paypal System failed due to $errno and string $errstr \n");    exit;             }

If No Errors to this point then we proceed with the processing.

Open port to paypal or test site and post Varibles.

else          {    fputs ($port, $header . $postipn);             while (!feof($port))         {                    $reply = fgets ($port, 1024);                    $reply = trim ($reply);                     }

Prepare a Debug Report

$ipnreport = $orgipn . "<br><b>" . "IPN Reply: " . $reply . "</b>";

Below Instant Payment Notifiction Variables

$business = $_POST['business'];                    $receiver_email = $_POST['receiver_email'];                    $item_name = $_POST['item_name'];                    $item_number = $_POST['item_number'];                    $quantity = $_POST['quantity']; #Advanced and Custom information                    $invoice = $_POST['invoice'];                    $custom = $_POST['custom'];                    $memo = $_POST['memo'];                    $tax = $_POST['tax'];                    $option_name1 = $_POST['option_name1'];                    $option_selection1 = $_POST['option_selection1'];                    $option_name2 = $_POST['option_name2'];                    $option_selection2 = $_POST['option_selection2'];

Shopping Cart Information

$num_cart_items = $_POST['num_cart_items'];

Transaction Information

$payment_status = $_POST['payment_status'];                    $pending_reason = $_POST['pending_reason'];                    $reason_code = $_POST['reason_code'];                    $payment_date = $_POST['payment_date'];                    $txn_id = $_POST['txn_id'];                    $txn_type = $_POST['txn_type'];                    $payment_type = $_POST['payment_type'];

Currency and Exchange Information

$mc_gross = $_POST['mc_gross'];                    $mc_fee = $_POST['mc_fee'];                    $mc_currency = $_POST['mc_currency'];        $settle_amount = $_POST['settle_amount'];                    $settle_currency = $_POST['settle_currency'];                    $exchange_rate = $_POST['exchange_rate'];                    $payment_gross = $_POST['payment_gross'];                    $payment_fee = $_POST['payment_fee'];

Auction Information

$for_auction = $_POST['for_auction'];                    $auction_buyer_id = $_POST['auction_buyer_id'];                    $auction_closing_date = $_POST['auction_closing_date'];                    $auction_multi_item = $_POST['auction_multi_item'];

Buyer Information

$first_name = $_POST['first_name'];                    $last_name = $_POST['last_name'];                    $address_name = $_POST ['address_name'];                    $address_street = $_POST['address_street'];                    $address_city = $_POST['address_city'];                    $address_state = $_POST['address_state'];                    $address_zip = $_POST['address_zip'];                    $address_country = $_POST['address_country'];                    $address_status = $_POST['address_status'];                    $payer_email = $_POST['payer_email'];                    $payer_id = $_POST['payer_id'];                    $payer_status = $_POST['payer_status'];

Below are Subscription - Instant Payment Notifiction Variables

$notify_version = $_POST['notify_version'];                    $verify_sign = $_POST['verify_sign'];                    $subscr_date = $_POST['subscr_date'];                    $subscr_effective = $_POST['subscr_effective'];                    $period1 = $_POST['period1'];                    $period2 = $_POST['period2'];                    $period3 = $_POST['period3'];                    $amount1 = $_POST['amount1'];                    $amount2 = $_POST['amount2'];                    $amount3 = $_POST['amount3'];                    $mc_amount1 = $_POST['mc_amount1'];                    $mc_amount2 = $_POST['mc_amount2'];                    $mc_amount3 = $_POST['mc_amount3'];                    $recurring = $_POST['recurring'];                    $reattempt = $_POST['reattempt'];                    $retry_at = $_POST['retry_at'];                    $recur_times = $_POST['recur_times'];                    $username = $_POST['username'];                    $password = $_POST['password'];                    $subscr_id = $_POST['subscr_id'];

IPN was Confirmed as both Genuine and VERIFIED

if (!strcmp ($reply, "VERIFIED"))             {

/* Now that IPN was VERIFIED below are a few things which you may want to do at this point.

  1. Check that the "payment_status" variable is: "Completed"
  2. If it is Pending you may want to wait or inform your customer?
  3. You should Check your datebase to ensure this "txn_id" or "subscr_id" is not a duplicate. txn_id is not sent with subscriptions!
  4. Check "payment_gross" or "mc_gross" matches match your prices!
  5. You definately want to check the "receiver_email" or "business" is yours. */

Remove Echo below when live

echo $ipnreport; send_mail("$send_mail_to", "$sysname", "\n Verified IPN Transaction\n \n$ipnreport\n");                                   }

IPN was Not Validated as Genuine and is INVALID

elseif (!strcmp ($reply, "INVALID"))             {

/* Now that IPN was INVALID below are a few things which you may want to do at this point.

  1. Check your code for any post back Validation problems!
  2. Investigate the Fact that this Could be an attack on your script IPN!
  3. If updating your DB, Ensure this "txn_id" is Not a Duplicate! */

Remove Echo line below when live

echo $ipnreport; send_mail("$send_mail_to", "$sysname", "\n IN Valid IPN Transaction\n \n$ipnreport\n");                                   }

else             {

If your script reaches this point there is a problem. Communication from your script to test/paypal pages could be 1 reason.

echo $ipnreport; send_mail("$send_mail_to", "$sysname", "\n FATAL ERROR No Reply at all\n \n$ipnreport\n");             }

Terminate the Socket connection and Exit

fclose ($port); exit;       }

/* =================================          Below are functions    ================================= */

Email function

function send_mail($to, $subj, $body) {     global $from_name, $from_email, $mailpath;

E-mail Configuration

$announce_subject = "$subj"; $announce_from_email = "$from_email"; $announce_from_name = "$from_name"; $announce_to_email = "$to"; $MP = "$mailpath"; $spec_envelope = 1;

End email config

Access Sendmail

Conditionally match envelope address

if(isset($spec_envelope)) { $MP .= " -f $announce_from_email"; } $fd = popen($MP,"w"); fputs($fd, "To: $announce_to_email\n"); fputs($fd, "From: $announce_from_name <$announce_from_email>\n"); fputs($fd, "Subject: $announce_subject\n"); fputs($fd, "X-Mailer: MyPayPal_Mailer\n"); fputs($fd, "Content-Type: text/html\n"); fputs($fd, $body); # $body will be sent when the function is used pclose($fd); } /******************************************************** *    THIS SCRIPT IS FREEWARE AND IS NOT FOR RE-SALE     * *   If you would like to have a custom script written   * *   for you contact http://www.belahost.com/contact.php * ********************************************************/

?>