PayPal Return Handler Component
Handling Payment Data Transfer (PDT) & Return from a dedicated Web Form.
The PayPalReturnHandler component is designed for the scenario where you want to use a dedicated page for handling the Return from PayPal instead of handling the PayPal_Returned event of the same button. If you handle the PayPal_Returned event directly from your Payment Button (BuyNow button, Donation button etc) then, you do not need this component at all.
In order to associate a PayPalReturnHandler component with a PayPal Return event caused by a Payment Button (i.e. BuyNow Button, Donation Button etc..) that is hosted in a different page, you need to follow the following steps:
(The example is shown for a BuyNow button, but the same procedure works for all other button controls)
- In the design mode of a BuyNow Button, open the smart tag wizard and go to the tab named "Step 4 (Payment Return/PDT) as shown in the following screen shot. Check the 2nd option and provide the relative path of the dedicated PayPal return handler files.


Once you have placed an instance of this component into your web form, attach an event handler method for the event "PayPal_Returned". This event handler method is the method which will contain your business logic.


Accessing Additional Data Items:
You can access the additional data items as shown in the following snippet :


But if you changed that path and if you want access the additional data items from a Dedicated 'PayPal Return Handler' component, then, you need to change the property 'TemporaryFolderUsedForAdditionalDataItems' as well as shown below:

Payment Data Transfer:
If you are not satisfied only with the transaction id, rather you want the all the transaction data, you can get that by activating Payment Data Transfer. Payment Data Transfer (PDT) is a secure method to retrieve the details about a PayPal transaction so that you can display them to your customer who are redirected back to your site upon payment completion.
PDT Authentication Token:
When you activate PDT, you will get an identification token named "PDT authentication token". It is a string value that identifies your account to PayPal. If you want to handle PDT using this component, you must provide this token to the component. The following screen shot shows how you can do that in Design Time.

Once you have set the PDT Authentication Token, you are ready to use snippet like this:


If the component does not find any PDT Token, e.PDT.Status will be set as "PayPalPDT.StatusCodes.NOT_Handling_PDT" and no transaction related data will be available except the Transaction ID.
A piece of advice : Never process
the post payment logic (i.e. logging the transaction data in your
database, verifying the payment and generating License Key, sending
email to the payer with shipping information etc) from PayPal_Returned
event even though you can collect all transaction data from PDT.
Because, if the payer closes his / her browser while living in PayPal
website before coming back to your website, then, PayPal_Returned event will never fire and so you will miss that transaction. Always use IPN for processing post payment logic. Use PayPal_Returned
event to convey 'Thank you' Message or doing some additional Read-Only
tasks. What is a Read Only task ? Read Only task means, "the task that
can be done by reading your database without writing / updating the
database". Get the Transaction-ID from the PayPal_Returned event, query your database using that Transaction-ID and find out if any information is already recorded by IPN event. If found, show the download link / shipping information etc from your database.
In order to use PDT, you must have Full Trust configuration in your ASP.NET website, otherwise you will always get e.PDT.Status = PayPalPDT.StatusCodes.Communication_Error from PayPal_Returned event. Because, prior to firing PayPal_Returned event, the control communicates with PayPal website in the background to verify the transaction using a method from WebClient class. Web Client class methods require Full Trust configuration. If you do not have full trust configuration, you cannot use the PDT feature even manually coding by yourself or using any other technique at all.
PDT Authentication Token property value will not be persisted in ViewState as it is a sensitive data. You can set PDT Token from Design Mode (persisted in ASPX markup). You can also set it programmatically from Page_Load event. But, if you set this value from a Post-back event (i.e. Click event) then, you will get unexpected result.
If you are testing in SandBox, you should change the property 'NotifySyncDestination = PayPal_Sandbox'. Otherwise, you will always get PDT Status = FAIL. But if you did not set the License Key (Trial Mode) then, no matter what value you set for this property, this component will always use NotifySyncDestination = PayPal_Sandbox.