Difference between revisions of "PayPal"
From Organic Design wiki
(RAC job) |
(PDT code sample) |
||
Line 15: | Line 15: | ||
*[http://www.paypal-tech.com/SG2/scriptparse.php IPN PHP Script Generator] | *[http://www.paypal-tech.com/SG2/scriptparse.php IPN PHP Script Generator] | ||
− | === | + | === IPN code sample === |
{{code|<php> | {{code|<php> | ||
<?php | <?php | ||
Line 64: | Line 64: | ||
fclose ($fp); | fclose ($fp); | ||
} | } | ||
+ | ?> | ||
+ | </php>}} | ||
+ | |||
+ | == PDT code sample == | ||
+ | {{code|<php> | ||
+ | <?php | ||
+ | // read the post from PayPal system and add 'cmd' | ||
+ | $req = 'cmd=_notify-synch'; | ||
+ | |||
+ | $tx_token = $_GET['tx']; | ||
+ | $auth_token = "GX_sTf5bW3wxRfFEbgofs88nQxvMQ7nsI8m21rzNESnl_79ccFTWj2aPgQ0"; | ||
+ | $req .= "&tx=$tx_token&at=$auth_token"; | ||
+ | |||
+ | // post back to PayPal system to validate | ||
+ | $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.paypal.com', 80, $errno, $errstr, 30); | ||
+ | // If possible, securely post back to paypal using HTTPS | ||
+ | // Your PHP server will need to be SSL enabled | ||
+ | // $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); | ||
+ | |||
+ | if (!$fp) { | ||
+ | // HTTP ERROR | ||
+ | } else { | ||
+ | fputs ($fp, $header . $req); | ||
+ | // read the body data | ||
+ | $res = ''; | ||
+ | $headerdone = false; | ||
+ | while (!feof($fp)) { | ||
+ | $line = fgets ($fp, 1024); | ||
+ | if (strcmp($line, "\r\n") == 0) { | ||
+ | // read the header | ||
+ | $headerdone = true; | ||
+ | } | ||
+ | else if ($headerdone) | ||
+ | { | ||
+ | // header has been read. now read the contents | ||
+ | $res .= $line; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // parse the data | ||
+ | $lines = explode("\n", $res); | ||
+ | $keyarray = array(); | ||
+ | if (strcmp ($lines[0], "SUCCESS") == 0) { | ||
+ | for ($i=1; $i<count($lines);$i++){ | ||
+ | list($key,$val) = explode("=", $lines[$i]); | ||
+ | $keyarray[urldecode($key)] = urldecode($val); | ||
+ | } | ||
+ | // check the payment_status is Completed | ||
+ | // check that txn_id has not been previously processed | ||
+ | // check that receiver_email is your Primary PayPal email | ||
+ | // check that payment_amount/payment_currency are correct | ||
+ | // process payment | ||
+ | $firstname = $keyarray['first_name']; | ||
+ | $lastname = $keyarray['last_name']; | ||
+ | $itemname = $keyarray['item_name']; | ||
+ | $amount = $keyarray['payment_gross']; | ||
+ | |||
+ | echo ("<p><h3>Thank you for your purchase!</h3></p>"); | ||
+ | |||
+ | echo ("<b>Payment Details</b><br>\n"); | ||
+ | echo ("<li>Name: $firstname $lastname</li>\n"); | ||
+ | echo ("<li>Item: $itemname</li>\n"); | ||
+ | echo ("<li>Amount: $amount</li>\n"); | ||
+ | echo (""); | ||
+ | } | ||
+ | else if (strcmp ($lines[0], "FAIL") == 0) { | ||
+ | // log for manual investigation | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | fclose ($fp); | ||
+ | |||
?> | ?> | ||
</php>}} | </php>}} |
Revision as of 04:30, 4 December 2007
MediaWiki Extension
MW:Extension:PayPal is an extension for creating PayPal donation forms using a <paypal> tag. PokerCoder requested adding IPN support to the extension through this RentACoder job and has accepted User:Nad's bid to complete the work.
IPN
Instant Payment Notification, included with Website Payment products, Express Checkout, and Standard Checkout, is available to PayPal Premier and Business members. Instant Payment Notification allows you to integrate your PayPal payments with your website's back-end operations, so that you get immediate notification and authentication of any PayPal payments and disputes you may receive.
- IPN at PayPal Integration Center
- IPN Introduction for Developers
- DesignerTuts Tutorial
- IPN Manual
- IPN Technical Overview
- Instant Code Samples
- IPN Techniques
- Basic Inventory Management Using IPN
- IPN Test Environment
- IPN PHP Script Generator