Reputation: 688
So I've added this untested code to my IPN
if (strcmp ($res, "VERIFIED") == 0) {
// check whether the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your PayPal email
// check that payment_amount/payment_currency are correct
// process payment and mark item as paid.
// 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'];
include 'connect.php';
if($payment_status == "completed")
{
mysql_query('UPDATE `users` SET `is_member`= 1 WHERE `username` == $username')
}
else
{
mysql_query('UPDATE `users` SET `is_member`= 0 WHERE `username` == $username')
}
essentially altering the data dependent on the payment_status. The problem I have though is that paypal have no idea what username is. How would I give paypal this information? do I do it through the subscribe button or change the html code?
Upvotes: 0
Views: 819
Reputation: 3402
Couple of options here to complete your user/membership reconciliation with IPN,
$payer_email
from IPN POST-back and make the data matching with your database entries (order details)Though this requires the least change on your code, it would fail to work when user uses a different email account (PayPal account) to pay
$invoice
value and map it with your order data entry.Some references here for further details:
Check here for how to add the "invoice" field:
For Standard Payment buttons, see HTML Variables for PayPal Payments Standard
For Express Checkout APIs, see SetExpressCheckout API Operation (NVP)
Upvotes: 1