ASP.NET PayPal Control for Website Payments Standard
Online Documentation.

Skip Navigation Links.

Automating Shipment of your product after payment

 

Ok, you have learned how to use one of the Payment Buttons (i.e. BuyNow Button  , Add to Cart Button , Donation Button , Upload Complete Cart ButtonSubscription Button  etc.). When you place one of the Payment Button in your website, your customer will be able to pay you by clicking that button and the money will beposited to your PayPal account. Now it is up to you if you want to manually check your PayPal account everyday or every hour, and if you find a payment, search the email address of your customer, send him email and product shipping information by email, OR if you want to implement a feature in your website so that, as soon as the payment is made to your PayPal account, the email will be sent to your customer with the shipping information or if the product is a digital product like Software, eBook etc, then, a download link or email attachment will be sent to your customer for that digital product.

If you choose the later, then, you would be excited to know that, this control comes with 2 Post Payment Events. They are 'IPN_Notified' and 'PayPal_Returned'.

There are some basic differences between these 2 events. 'IPN_Notified' event is asynchronous and 'PayPal_Returned' event is synchronous. You can use any of these events to automate your shipping process OR you may use both of them to make your automation logic more robust.

Let me explain you about the scenario. 

1. When your customer clicks any of the Payment button, he is taken to PayPal website. In PayPal Website, he may choose to complete the payment or cancel and return to your website. If he completes the payment, PayPal will send a notification to your website which is called IPN or Instant Payment Notification, and as you hosted our PayPal control in your website, this PayPal control will catch that notification and fire 'IPN_Notified' event asynchronously (in a background process) while your customer may be still at PayPal Website. So, imagine that situation, you have handled the IPN_Notified event of this control in your webpage and the attached event handler method for IPN_Notified event is being executed asynchronously where your customer is not even returned back to your website. So, you can understand that, IPN_Notified event is a NON VISUAL Event, and this event is being fired by PayPal, not your Customer. So, of course this event will not be useful for showing any User Interface to your customer, right ? Then, you may be wondering, what you can do in that IPN_Notified event handler method! Ok, you can treat that event as a Service Event. That means, you can perform non visual post payment activities in that event. You can send an email to your customer, saying "Thank you for the payment", or you can generate the receipt, software download link etc and send email. You can also log the transaction to your database. So you can do anything that does not require your customer to be present. Also note that, when IPN_Notified event is being fired, a different SESSION is created and the SESSION user is PAYPAL, not your CUSTOMER. So, if you expect that, you can add your customer's user name from Cookie to your Membership role, that will be a mistake. There is a way to do that, we will discuss about that in IPN Details  page. The Event Argument Object of IPN_Notified event contains all transaction data in a type safe manner which will give you the pleasure of object oriented programming. So, you can use that transaction data to implement your business rules.

2. When your customer visited PayPal website, we assumed that, he completed the Payment. So, as soon as he finished the payment, he will be either sent back to your website by PayPal or a back link will be shown by PayPal to your customer to come back to your site. As soon as your customer landed back to your site, a new SESSION starts and 'PayPal_Returned' event is fired. This event is not that tricky like IPN_Notified event. Heres, NOT PayPal, rather your CUSTOMER is the user of this SESSION. When any of your attached event handler method is being executed for the event 'PayPal_Returned' your customer is present in front of your website and so, you can use User Interface programming in that event handler method. A typical usage of this event handler method is, setting the Text property of any Label control on your page with the sentence "Thank  you for your Payment". Same like IPN_Notified event, all transaction data can be retrieved by this event's event argument object. So, what you can do in IPN_Notified event can be done in this PayPal_Returned event too. Moreover, you can use User Interface in PayPal_Returned event which you could not do in IPN_Notified event. By the way, if your customer does not complete the payment, cancel and returned back to your website, PayPal_Returned event fires in that situation too. The event argument object of the PayPal_Returned event will let you know if the customer completed the payment or cancelled and came back without paying. How you can use the PayPal_Returned event can be learned in details in the PayPal Return Details  page.

 

What is the sequence of firing these events ? Is IPN_Notified event fires all the time before PayPal_Returned event ?

The answer is YES and NOT ALL THE TIME. That means, it is very usual that the IPN_Notified event is fired as soon as the customer completes his/her payment in PayPal website. And when he/she comes back to your website, PayPal_Returned event is fired. So, you may assume that, IPN_Notified event is fired before 'PayPal_Returned' event. But there is a catch. IPN_Notified event is Asynchronous, that means, sometimes it may happen that, while IPN_Notified event is being fired, the customer clicked the return link very quickly and landed to your website so fast that PayPal_Returned event fired while IPN_Notified event handler method did not finish its task. Also it may happen that, when PayPal sent the first notification to your website about IPN, it failed due to some HTTP error, so PayPal retried sending the same IPN after a while. In that case, you will see that PayPal_Returned event fired when IPN_Notified event did not fired. So, you may keep all of these situation in mind just to keep your software design robust, but those are the worst cases. The best case and Average case is : IPN_Notifed event is fired before PayPal_Returned event.

 

So ! Which event should I use to implement my post payment business logic ?

You might be thinking that, if all transaction data can be retrieved by PayPal_Returned event, then, IPN_Notified event is redundant. Actually NO. As I mentioned, IPN_Notified event is fired asynchronously when your customer may still in PayPal website and your customer has no Control over stopping firing this event. So, you are sure that, No matter what, your customer closes his browser or come back to your site, IPN_Notified event will be fired by this control. So, you should use this event to log the transaction to your database, generate receipt and download link for your digital product, send email with attachment etc. Then, you can use 'PayPal_Returned' event to give your customer a feel that he is being appreciated for the payment and also you may let him/her see the shipping information or download link for the product if you wish. In case, if you customer closes his browser before he comes back to your website, or if he gets his internet connection disconnected or any other worst cases, you will miss to generate receipt and other post payment processing logic execution if you depended only on PayPal_Returned event. So, it is better to use both of these events in more efficient manner.

 As I mentioned in the earlier paragraph, IPN_Notified event is fired as soon as the payment is completed while your customer is in the PayPal website. Once your customer comes back to your website, the PayPal_Returned event is fired. So, we can assume that, any stored information (in your database) which was stored in the IPN session is ready to be retrieved (from your database) in the PayPal_Returned event. So, in PayPal_Returned event, you can show your customer a summary of tasks done in IPN_Notified event.

 You can use a combination of these two events efficiently to perform your Post Payment Business logics. For instance, use IPN_Notified event for storing the transaction information in your database, deliver the access keys for software downloads etc and use PayPal_Returned event for retrieving the generated access keys (generated in IPN_Notified event) and showing that to your customer.

 

The following diagram will give you an idea about the sequence of the events fired by this control.n in mind just to keep your software design robust, but those are the worst cases. The best case and Average case is : IPN_Notifed event is fired before PayPal_Returned event.

 

Please note the diagram. The IPN_Notified event is marked with a Server icon, that means, the user wont see this event being fired. The Click Event and PayPal_Returned events are marked with Computer Monitor icon, that means, the customer can see these events being fired. Now, you got the basic idea about these post payment events. Now, you should read the detail documentation about

 

1. Handling Instant Payment Notification aka IPN

2. Handling PayPal Returned (Payment Data Transfer aka PDT)

 

Still Confused ?

If you are still confused, please check the sample application that comes with the setup.exe file you have downloaded from our website. Also please do not hesitate to ask us as many questions as you want from our Help Desk