I had implemented IPN handler (copt paste it from code project) in one of the project for the first time.
The problem in the user can registered to my website with some email address and then while paying he can use some different email address
And the IPN handler request variable give the email address with which it pays. How should i find out which user had paid.
if (strResponse == "VERIFIED")
{
//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
string payerEmail = Request.Form["payer_email"];
string paymentStatus = Request.Form["payment_status"];
string receiverEmail = Request.Form["receiver_email"];
string amount = Request.Form["mc_gross"];
}
Solutions:
Pass some addiditonal may be user id in the payment processing page and assume it will be returned in IPN handler.
Or ask the user to enter the paypal email address before paying. (not feels good)
Any help in this regard is appreciated
I usually POST, within the cart info, a custom field that identifies my local transaction, or my local cart. IPN will send that custom field back to you, so that you can match the transaction with your user. Or you can just pass the USER_ID, and get it back regardless of the transaction.
Send paypal your custom data in your form using this field:
<input type="hidden" name="custom" value="YOUR_CUSTOM_INFO_HERE">
Handle IPN in your callback:
if (strcmp ($res, "VERIFIED") == 0) {
// This is the custom field i posted within the cart form.
$cid = $_POST['custom'];
$txn_id = $_POST['txn_id'];
$cart = load_cart_by_cid($cid);
if (!empty($cart)) {
// Fetch your user from cart and do things with it,
// along with your security checks.
$user = $cart->getUser();
// For example, store the transaction.
TransactionManager::saveTransaction($user, $txn_id);
}
}
Source is php, but i think is verbose enough to be easily translated in java, or c#, or whatever.