Handling canceled Paypal payments - php

I am currently using Paypal as a payment system on a website I'm working and so far everything works great...except one thing. Once the payment is complete, Paypal calls the IPN page I provided and everything's good. But if the person cancels the payment, I'm not sure how I'm supposed to know that since Paypal doesn't call the IPN in that case (at least, from what I understand).
Sure, if the person clicks on "Cancel and return to the website", he will come back to the Cancel page I provided. But what if he just closes the paypal page? He would never return to my website's cancel page.
In some cases, I guess it wouldn't be much of a problem. I'm sure there is a way to know if the payment is canceled but I just can't find it, which is why I'm here.
Thanks for your help.

you should be able to implement some sort of confirmation field in your transaction table, eg: ipn_confirmed.
You set it to default as unconfirmed and set it as confirmed when paypal's IPN return the value. Then, you will only process request that is confirmed. If there is a glitch in the matrix, you will need your customer to contact you and send his/her paypal's transaction info and match is with your data. If it match, process it.

Related

paypal Subscription button : payment notification

I have two payment methods one is through subscription and another one is single payment.
for single payment: I receive the message payment_status 'completed' to return url then I do the database update.
for subscription : I receive the message txn_type subscr_signup.to return url not subscr_payment.
But I need to immediately tell give the product to the user.
How to know in the success page itself the payment is collected by paypal... for subscription
In short I want to know the payment status.
please help me
for single payment: I receive the message payment_status 'completed' to return url then I do the database update.
That's where I feel you are doing it wrong. You are relying on the buyer to go back to your webpage (in order to do the database update) by clicking on the link at the end of the checkout or by Paypal automatically redirecting to your webpage. What's the problem with that? If the buyer doesn't click the link or wait for the redirect, then they do not go back to the webpage and therefore no database update gets made.
So how can I get the payment information? There is a better (but not 100% reliable) way to do this and that is by using IPN. With both payment methods, you can add a notify_url variable. This is the URL of a listener script to which Paypal will post information about the transaction that is made. So when a buyer makes a payment, your script will be called to make the necessary database update. Just be aware the script has to do certain things in order for Paypal to send you the information. I have used this implementation in the past and it has worked for the most part.
How to know in the success page itself the payment is collected by paypal... for subscription
Above might not answer your original question. From looking at their documentation, you might be able to use return and cancel_return variables in both methods to determine whether the payment was complete or not, respectively.

PHP - Paypal payment transaction

I've a problem with Paypal IPN. The callback works very well.
I've a site and anyone can signup for free in my site. Later, the user can upgrade the account and here intervenes paypal.
How can I be sure that the user (A) paid to the transaction_id (0123) ?
Ex.
User (A) -> Click to button (item_number = (0009)) -> redirect to paypal page;
User (?) paid -> Paypal IPN sended and server received data -> [Which user has paid?]
!! This, without the user return to the site !!
Thank You
I'm sorry #Vincenzo Raco, but that is bad advice.
PDT and IPN are essentially the same exact thing except that PDT sends data to your return URL and IPN sends it to a silent listener.
There is no guarantee that users will make it back to your return URL, even if you have Auto Return enabled, so it's never a good idea to handle post-payment processing tasks on the return URL. If your IPN is getting hacked that means you have a problem with your configuration.
All IPN's are verified with PayPal's servers, and if you're using API calls, hosted buttons, encrypted buttons, etc. people can't see the original code, copy it, and make adjustments to pricing, which would be the only potential "hack" that anybody could do. Just make sure not to use basic, standard HTML buttons and that potential problem goes away.
IPN is definitely what you want to use to handle your post-payment processing. You can save your user record or whatever data you're working with in your database prior to sending the user over to PayPal. You can include the record ID of your database in the PayPal payment request (I typically use the invoice parameter for this) and then that will be returned in IPN so that you can pull that data back out of your database or add new related accordingly.

PayPal Pro : is it necessary to gather details oneself or can PayPal do that for me?

I know that with PayPal Pro, the user enters his information on my site and PayPal processes that in the background.
Still, is it possible to have it like with PayPal standard : the user gets redirected to PayPal site, enters his information there, pays there, and come back ?
I'm asking cause my client has PayPal Pro, however I don't feel comfortable with gathering payment data myself. I would prefer PayPal to do that for me.
Short answer: Yes, you can use IPN.
Longer answer:
Either way you want to have an SSL certificate, and to handle various payment information.
If you're using IPN, the user gets redirected to the PayPal site, pays, and gets redirected back, and you receive a notification to one of your scripts. That script will have to check if the data you receive is similar to what you sent, and other checks. You may not receive the notification instantly, sometimes it takes a few days to get it (very rarely though).
With PayPal Pro, the user enters his credit card details and submits them. You will have to make some checks here, but after that you send the info to PayPal, and you receive the response (either success or response) - instantly.
These are the major differences, it's nothing mind boggling one way or the other, you just need to use the API documentation.

How can get transaction details from paypal after successful payment

My sent data to paypal is
"https://www.paypal.com/cgi-bin/webscr/cmd=_cart&upload=1&business=seller.email#something.com&currency_code=USD&bn=BusinessName&return=http://www.sellersite.com&item_number_1=55&item_name_1=battery&amount_1=55&quantity_1=2&item_number_2=52&item_name_2=bat&amount_2=5&quantity_2=3"
And I want to show those sent data(item number, item name,amount,quantity) and the paypal transaction id to the buyer on "http://www.sellersite.com" after successful payment. (Suppose, the seller has the merchant account with paypal and he would enter that paypal id into database from admin section of the website. So,I would not think about his paypal account settings, my job is just to create the environment for paypal payment for the seller.)
If I write a script like
$T_ID=$_REQUEST['tx']; // or $T_ID=$_GET['tx']; **ref(tx):- "https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_html_paymentdatatransfer"
$item=$_REQUEST['item_number_1']; // or $item=$_GET['item_number_1'];
Then would I get those data from paypal ?
Please tell me.
-Thanks.
It's not going to be quite that simple. You'll need to setup Payment Data Transfer (PDT) in order to get details sent back to your return URL after the buyer completes the payment.
This is useful if you're simply going to display details back to the user, but it's not recommended for updating your own database, sending out email notifications, etc. because there is no guarantee this page will ever be reached so the code won't always run.
For that sort of thing you'll want to use Instant Payment Notification (IPN). This works very similar to PDT except that it will always POST data to your IPN listener on your server regardless of whether or not the user makes it back to your return URL, and it happens outside of your checkout system all together.

Paypal IPN needed?

I'm doing a project involving Paypal, more specifically with the NVP API in PHP. But I just can't seem to figure what to use the IPN feature for.
I mean, when the user has been redirected to Paypal to confirm the purchase, he is redirected back to my website's "Paypal-succes-page", when the transaction is complete. And just to be sure that he actually payed i could use the "PaymentDetails" operation.
Now where does IPN fit in this process? and what is the benefit of it?
Thanks
The integrate with PayPal's services you will notice there are three main channels (and IMO it's important to know this so you can decide the benefits for your application):
IPN: Instant Payment Notification
PDT: Payment Data Transfer
PayPal's API
To use PayPal's IPN you need to add a 'listener' script (example) and add the address to your PayPal account. Whenever an event occurs PayPal will send a message directly to your server via your listener and you then update your accounts appropriately. This is especially useful for running subscription services as events will occur in the background without user intervention and you can capture successful/failed recurring payments etc.
PayPal's PDT is a system for accepting data when a user is redirected back to your site from PayPal. For example, a user clicks 'Buy', they are directed to PayPal, enter information etc. Then, once the payment has been taken, they are redirected back to your site. PayPal can pass details about the transaction including whether it was successful or not so you can display the appropriate success/failed page from your site.
PayPal's API allows you to integrate more deeply with PayPal's services, and you would use this if you were managing payments directly from your site.
These services aren't mutually exclusive, so you can use any combination with your application.
I hope this helps
The IPN feature is a very useful feature which you should use to update your database in my opinion. Sure the user is redirected to your success-page after the purchase where you can validate the payment details.
But what if he closes (by accident or not) the browser before reaching your success page? You will never know the result of the transaction and you will never update your database or process his order accordingly.
When using the IPN you can be sure that the transaction result will always reach you because PayPal will keep on making an offline request to your IPN page until it has reached your servers.
Instant Payment Notification
The typical usage of the IPN is to validate the purchase and to let your script or management system know that the transaction is complete so your system can update any records you may have for your service.
But the most important part is that the transaction is validated.
IPN send all data about transaction to your server - price, items, contacts ... so you can check, if someone don't pay you only 1$ instead of 100$ and confirm your order. It prevets thiefs, cheaters, ... USE IT! ;)

Categories