|
Rank: Starting Member
Groups: Registered
Joined: 11/5/2010 Posts: 1
|
Hi i'm wondering if anyone can help me convert this ipn from alertpay to work with paypal. Thanks for any help Quote:<?
include("dbase.php"); include("settings.php");
//The value is the Security Code generated from the IPN section of your AlertPay account. Please change it to yours. define("IPN_SECURITY_CODE", "XXXXXXXXXXXXXXX"); define("MY_MERCHANT_EMAIL", "example@example.com"); //Setting information about the transaction $receivedSecurityCode = urldecode($_POST['ap_securitycode']); $receivedMerchantEmailAddress = urldecode($_POST['ap_merchant']); $customerEmailAddress = urldecode($_POST['ap_custemailaddress']); $transactionStatus = urldecode($_POST['ap_status']); $testModeStatus = urldecode($_POST['ap_test']); $netAmount = urldecode($_POST['ap_amount']);
if ($receivedMerchantEmailAddress != MY_MERCHANT_EMAIL) { // The data was not meant for the business profile under this email address. // Take appropriate action } else { //Check if the security code matches if ($receivedSecurityCode != IPN_SECURITY_CODE) { // The data is NOT sent by AlertPay. // Take appropriate action. } else { if ($transactionStatus == "Success") { if ($testModeStatus == "1") { // Since Test Mode is ON, no transaction reference number will be returned. // Your site is currently being integrated with AlertPay IPN for TESTING PURPOSES // ONLY. Don't store any information in your production database and // DO NOT process this transaction as a real order. } else { // This REAL transaction is complete and the amount was paid successfully. // Process the order here by cross referencing the received data with your database. // Check that the total amount paid was the expected amount. // Check that the amount paid was for the correct service. // Check that the currency is correct. // ie: if ($totalAmountReceived == 50) ... etc ... // After verification, update your database accordingly. include("dbase.php"); $result=mysql_query("SELECT user,money from chatusers WHERE email='$customerEmailAddress' LIMIT 1"); $row = mysql_fetch_assoc($result); $username=$row['user']; $money=$row['money']; $money += $netAmount; $money = number_format($money, 2, '.', ''); $sql="Update chatusers set money=$money where email='$customerEmailAddress'"; $res=mysql_query($sql); mysql_query("insert into payments (ammount, details) values ('".$netAmount."', '$username')"); } } else { // Transaction was cancelled or an incorrect status was returned. // Take appropriate action. } } } ?>
|
|
Rank: Administrator
Groups: Administrators, Registered
Joined: 1/30/2008 Posts: 70 Location: ,
|
The two are pretty similar. PayPal has the following template below: Code:// read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; }
// 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 ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
// assign posted variables to local variables $item_name = $_POST['item_name']; $item_number = $_POST['item_number']; $payment_status = $_POST['payment_status']; $payment_amount = $_POST['mc_gross']; $payment_currency = $_POST['mc_currency']; $txn_id = $_POST['txn_id']; $receiver_email = $_POST['receiver_email']; $payer_email = $_POST['payer_email'];
if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { // 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 } else if (strcmp ($res, "INVALID") == 0) { // log for manual investigation } } fclose ($fp); } ?> --- Shannon @ PayLoadz.comSell Downloads - eBooks, Videos, Music, Documents, and more...
|