-
May 4th, 2011, 06:33 PM
#1
Thread Starter
New Member
Need help Converting Paypal IPN To AlertPay
Hello, I have seen a few posts of you all helping convert Paypal's IPN script over to Alertpay.
My problem is, if Im not mistaken, Is Alertpay brings in information.
My IPN does both.
Here is my IPN -
PHP Code:
<?php
// 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 ('www.paypal.com', 80, $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'];
$quantity = $_POST['quantity'];
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
if($payment_status != "Completed") { fclose ($fp);die(""); }
if($db->num_rows($db->query("SELECT * FROM dps_accepted WHERE dpTXN='{$txn_id}'")) > 0) { fclose ($fp);die(""); }
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
if($receiver_email != $set['paypal']) { fclose ($fp);die(""); }
// check that payment_amount/payment_currency are correct
if($payment_currency != "USD") { fclose ($fp);die(""); }
// parse for pack
$packr=explode('|',$item_name);
if(str_replace("www.","",$packr[0]) != str_replace("www.","",$_SERVER['HTTP_HOST'])) { fclose($fp); die(""); }
if($packr[1] != "DP") { fclose($fp);die(""); }
$pack=$packr[2];
if( $pack != 1 and $pack != 2 and $pack != 3 and $pack != 4 and $pack != 5 and $pack != 6 and $pack != 7 and $pack != 8 and $pack != 9) { fclose($fp);die(""); }
if($pack == 1 && $payment_amount != 3*$quantity) { fclose ($fp);die(""); }
if($pack == 2 && $payment_amount != 5*$quantity) { fclose ($fp);die(""); }
if($pack == 3 && $payment_amount != 10*$quantity) { fclose ($fp);die(""); }
if($pack == 4 && $payment_amount != 20*$quantity) { fclose ($fp);die(""); }
if($pack == 5 && $payment_amount != 30*$quantity) {fclose ($fp);die(""); }
if($pack == 6 && $payment_amount != 10*$quantity) { fclose ($fp);die(""); }
if($pack == 7 && $payment_amount != 25*$quantity) { fclose ($fp);die(""); }
if($pack == 8 && $payment_amount != 30*$quantity) { fclose ($fp);die(""); }
if($pack == 9 && $payment_amount != 0.75*$quantity) { fclose ($fp);die(""); }
// grab IDs
$buyer=$packr[3];
$for=$buyer;
// all seems to be in order, credit it.
// $q=$db->query("SELECT bogo FROM users WHERE bogo>=1");
// $bg=$db->fetch_single($q);
$bg = 1;
while ($amnt != $quantity) // Repeat until Quantity is reached.
{
$amount=$amnt+1;
if($pack==1)
{
$db->query("UPDATE users u LEFT JOIN userstats us ON u.userid=us.userid SET u.donator_points=u.donator_points+10 WHERE u.userid={$for}");
$db->query("INSERT INTO inventory VALUES ('','221',{$for},'$bg')",$c);
$db->query("INSERT INTO stafflog VALUES(NULL, '1', unix_timestamp(), 'Game autocredit ID {$buyer} a Pack 1 x {$bg}, $amount of $quantity', '$IP')");
$d=30;
$t="standard";
}
else if($pack==2)
{
$db->query("UPDATE users u LEFT JOIN userstats us ON u.userid=us.userid SET u.donator_points=u.donator_points+20 WHERE u.userid={$for}");
$db->query("INSERT INTO inventory VALUES ('','222',{$for},'$bg')",$c);
$db->query("INSERT INTO stafflog VALUES(NULL, '1', unix_timestamp(), 'Game autocredit ID {$buyer} a Pack 2 x {$bg}, $amount of $quantity', '$IP')");
$d=30;
$t="packtwo";
}
$d=0;
$t="packsix";
}
$amnt++; // Add one pass to the amnt variable.
}
// process payment
event_add($for, "Your \${$payment_amount} Pack {$pack} Donator Pack x {$bg} ($quantity packs) has been successfully credited to you.", $c);
$db->query("INSERT INTO dps_accepted VALUES('', {$buyer}, {$for}, '$t', unix_timestamp(), '$txn_id')");
}
else if (strcmp ($res, "INVALID") == 0) {
event_add('14124', "Marker Fail", $c);
}
}
fclose ($fp);
}
?>
The Alertpay IPN is:
PHP Code:
<?php
/**
* @author AlertPay
* @copyright 2010
*/
//The value is the Security Code generated from the IPN section of your AlertPay account. Please change it to yours.
define("IPN_SECURITY_CODE", "xxxxxxxxxxxxxxxx");
define("MY_MERCHANT_EMAIL", "name@example.com");
//Setting information about the transaction
$receivedSecurityCode = urldecode($_POST['ap_securitycode']);
$receivedMerchantEmailAddress = urldecode($_POST['ap_merchant']);
$transactionStatus = urldecode($_POST['ap_status']);
$testModeStatus = urldecode($_POST['ap_test']);
$purchaseType = urldecode($_POST['ap_purchasetype']);
$totalAmountReceived = urldecode($_POST['ap_totalamount']);
$feeAmount = urldecode($_POST['ap_feeamount']);
$netAmount = urldecode($_POST['ap_netamount']);
$transactionReferenceNumber = urldecode($_POST['ap_referencenumber']);
$currency = urldecode($_POST['ap_currency']);
$transactionDate= urldecode($_POST['ap_transactiondate']);
$transactionType= urldecode($_POST['ap_transactiontype']);
//Setting the customer's information from the IPN post variables
$customerFirstName = urldecode($_POST['ap_custfirstname']);
$customerLastName = urldecode($_POST['ap_custlastname']);
$customerAddress = urldecode($_POST['ap_custaddress']);
$customerCity = urldecode($_POST['ap_custcity']);
$customerState = urldecode($_POST['ap_custstate']);
$customerCountry = urldecode($_POST['ap_custcountry']);
$customerZipCode = urldecode($_POST['ap_custzip']);
$customerEmailAddress = urldecode($_POST['ap_custemailaddress']);
//Setting information about the purchased item from the IPN post variables
$myItemName = urldecode($_POST['ap_itemname']);
$myItemCode = urldecode($_POST['ap_itemcode']);
$myItemDescription = urldecode($_POST['ap_description']);
$myItemQuantity = urldecode($_POST['ap_quantity']);
$myItemAmount = urldecode($_POST['ap_amount']);
//Setting extra information about the purchased item from the IPN post variables
$additionalCharges = urldecode($_POST['ap_additionalcharges']);
$shippingCharges = urldecode($_POST['ap_shippingcharges']);
$taxAmount = urldecode($_POST['ap_taxamount']);
$discountAmount = urldecode($_POST['ap_discountamount']);
//Setting your customs fields received from the IPN post variables
$myCustomField_1 = urldecode($_POST['apc_1']);
$myCustomField_2 = urldecode($_POST['apc_2']);
$myCustomField_3 = urldecode($_POST['apc_3']);
$myCustomField_4 = urldecode($_POST['apc_4']);
$myCustomField_5 = urldecode($_POST['apc_5']);
$myCustomField_6 = urldecode($_POST['apc_6']);
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.
}
}
else {
// Transaction was cancelled or an incorrect status was returned.
// Take appropriate action.
}
}
}
?>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|