This page explains the usage and facts about the Subscription button Web Form Server Control. If you intend to use Subscription button within your ASP.NET MVC project, please visit this page.
PayPal Subscriptions and Recurring Payments let you accept recurring payments for your service. Our Subscription Button Control is designed to facilitate you to use that PayPal offered service within your ASP.NET Web site in the most organized Object Oriented way.
When you set up Subscriptions, you can offer subscribers a trial period, special introductory rates, and a regular rate. Subscribers are billed automatically according to the terms you specify, removing the hassle of keeping track of which payments you have and have not received. PayPal Subscription buttons can also help you improve your buyer experience with customizable buttons, secure payments, and the ability to pre populate your subscribers’ PayPal sign up pages. PayPal provides Instant Payment Notifications to give you instant notification of all subscriptions activities and to facilitate Subscription Password Management.
If you are evaluating a Trial Version of this control OR if you want to test with Demo Money, please prepare your Sand Box account before proceeding to this chapter .
In order to keep this page short and simple, the examples are given only in C# language. If you are a VB.NET programmer, please accept our apology. The example snippets are so short and comprehensive that as a programmer you wont have any problem to comprehend. Although the class library reference has examples and snippets in both C# and VB.NET.
|- The Checkout Experience
- Getting Started
|- Set Properties Programmatically
- Click Event and Post Back
|- Handling Instant Payment Notification (IPN)
- Handling PayPal Return / PDT
- Drag and drop an instance of the Subscription Button control from your Visual Studio Toolbox as shown below:
The first property of this control that you need to set is your Business Email Address or Merchant ID of your Merchant Account. If you are testing in Sand Box, then, this is the account which you created as 'Test Merchant Account' as explained in the Sand Box preparation chapter. Please do not get confused with the Developer Central Login account with the Test Merchant Account. Merchant ID is an alternative to using your Email address. It is better not to expose your business email address in order to protect your Email In-box from Spams. You can set either Business Email or Merchant ID from the Smart Tag or from the Property Editor. In order to get your Merchant ID, log in to your PayPal account. If you are testing in Sand-box, then, log in to your Developer Central Account, then log in to your Merchant Test Account from https://www.sandbox.paypal.com/. Click 'Profile' Menu, then, your Merchant ID will be shown up as shown in the following screen shot.
Set the merchant ID as shown here:
Now you may want to set few more properties like Subscription Name, Billing Cycle, Regular Rate etc and you can do all of these using the Wizard for the button which can be called by clicking the link found in the Smart Tag as shown in the following Screen-shot.
- Furthermore, you may choose to set the visual styles and PayPal page behaviors for the subscription button. Just click the button "Next" shown in the wizard and you will be taken to configure the display page as shown in the following screen-shot.
Please note: If your account is not upgraded to a Premier or Business account, then, you will not see any affect of these styling properties for PayPal page. For example, if you set a header image URL, you will not see that image when you click the Subscription button and taken to PayPal website. You will see your email address as the header of the page.
- Please note: If your account is not upgraded to a Premier or Business account, then, you will not see any affect of these styling properties for PayPal page. For example, if you set a header image URL, you will not see that image when you are taken to PayPal website due to a click on the Subscription button. In that case, you will see your email address as the header of the page.
- If you want to pass unlimited custom data that you want to track in a Post Payment event like IPN_Subscription / IPN_Payment event, PayPal_Returned, then, please check the feature chapter about Additional Data Items.
Click Here to view the complete Class Diagram that you may use as a reference when you set properties from your code.
If you attach an event handler to this event, then the event handler method will be executed before the data is transferred to PayPal.
You can use Validation logic inside the Click Event handler of a Subscription button and based on a condition (user input) you can cancel the submission to PayPal. Please check the method CancelSubmission().
- The Subscription Button will POST BACK only IF the Click event is handled. If you do not handle Click event, your customer will be taken to PayPal website directly from the Client Side without any Server Round Trip.
Handling Instant Payment Notification (IPN) from PayPal:
Not only when the Agree button is clicked, PayPal submits IPN when:
- Payments are first made, with a status of completed or pending.
- Payments clear, fail, or are denied, if the initial status was pending.
- Subscriptions begin, end, or are canceled, if you use Subscriptions Password Management.
This control can capture that notification and fire a server side event named IPN_Subscription. This control not only just fires the event, but also collects all the transaction data from IPN and offers you a rich set of strongly typed relational object model as event argument object which is not only loved by all Object Oriented Programmers, but also revealing all the headaches from the developer about verification and other complex tasks in IPN Session.
Click Here to view the complete Class Diagram of SubscriptionIPNEventArgs object.
- Unless a payment is made, Transaction ID will not be available. For tracking Subscription, you should use the property e.SubscriptionInfo.SubscriberID.
Handle the IPN_Payment event so that you can get notified whenever Payment is made for a Subscription.
- Click Here to view the complete Class Diagram of SubscriptionIPNPaymentEventArgs object.
By the way, the above example snippet does not show the detailed way of handling FRAUD attempts in order to simplify the overview of IPN_Subscription / IPN_Payment events. So, you should check the pattern for payment verification, fraud detection and automated Product delivery.
If you do not want to handle IPN_Subscription / IPN_Payment events from the same page, rather if you want to handle IPN_Subscription / IPN_Payment events from a dedicated page, you can do that too. Simply do not handle IPN_Subscription / IPN_Payment events and set the Custom Notification URL from the Design Time Smart Tag Wizard -> Step 3 as shown here:
- If you use a Custom IPN URL to capture the IPN from a dedicated page, you can still get the benefit of firing IPN_Subscription / IPN_Payment events and capture all IPN data from event argument object from that dedicated page. How ? Please check the chapter for IPNHandler Component.
If you handle any of the IPN_Subscription / IPN_Payment events, setting Custom Notification URL will have NO EFFECT. The control will always generate notify URL automatically to use the same page where the Subscription button is hosted so that the same Subscription button can fire IPN_Subscription / IPN_Payment events.
If you do not handle any of the IPN_Subscription / IPN_Payment events and if you do not set any Custom Notification URL then, this control will not capture IPN at all. If you have specified any default IPN URL in your PayPal profile, then, PayPal will use that URL to send IPN for any transaction happens in your PayPal account in that case.
You should handle IPN_Exception event if you want to capture any Exception thrown in your IPN_Subscription / IPN_Payment events handler method. By handling IPN_Exception event, you not only catch any exception that was fired beyond your IPN_Subscription / IPN_Payment events handler layer, but also you get rid of using TRY - CATCH block in your IPN_Subscription / IPN_Payment events handler which will enhances the readability of your code.
You do not need to turn IPN option ON from your PayPal account at all. This control will take care of everything for you.
Whenever your customer is transferred back to your website from PayPal website after completing or canceling the subscription, you can do additional tasks on your website by handling an event named PayPal_Returned. This control not only just fires the event, but also collects all the transaction data from PayPal if you have turned 'Payment Data Transfer' option ON from your PayPal profile. The event argument object of PayPal_Returned event offers you a rich set of strongly typed relational object model same like the event argument object of IPN_Subscription / IPN_Payment events. This event will take care of notification validation so you just do not need to worry about any dirty code work, rather use the clean data returned by this event argument object.
Once you handled PayPal_Returned event of your Subscription button, your buyer will be taken back to your website after the subscription is started or canceled to sign up. You can check from your Event handler if the subscription was proceeded or canceled as shown below:
If you do not handle PayPal_Returned event, then, your subscriber will not be returned to your website by PayPal. So, you should handle this event if you want to bring your subscriber back to your site.
If you want to redirect your subscriber to a different page after returning from PayPal, you can do so by setting the Custom Completed Return URL and Custom Canceled Return URL from the Step 4 tab of the Subscription button Design Time Wizard as shown here:
Notice the check box in the above screen shot. If you check this box, then, the Canceled Return URL will be auto generated so that you can handle both of the Completed and Canceled Return event from the same page. It is HIGHLY RECOMMENDED that you check this option.
If you prefer to use Custom Return URL as mentioned above, you can still fire PayPal_Returned event and collect the information about completed/canceled from your dedicated return page. How ? please check the chapter for PayPalReturnHandler Component.
- If you handle PayPal_Returned event, then, setting Custom Complete Return URL and Custom Canceled Return URL will have NO EFFECT. So, if you want to redirect the subscriber to a dedicated page after PayPal return, then, make sure that you do not handle PayPal_Returned event and then, set the Custom Complete Return URL / Custom Canceled Return URL.
If you want to receive all the transaction data in PayPal_Returned event as you could in IPN_Subscription / IPN_Payment events from SubscriptionReturnedEventArgs, then, you need to turn 'Payment Data Transfer (PDT)' option On from your PayPal account. Once you turn PDT ON for your PayPal account, you will receive an Authentication Token which is called 'PDT Authentication Token'.
Once you get the PDT Authentication Token, from the design time smart tag, click Button Wizard and select the last tab "Step 4 (Payment Return / PDT)". In that tab, at the bottom of the Form, you will find the box for PDT Authentication Token. Set the PDT Authentication Token in that box as shown here:
After PDT Authentication Token is set, you can collect transaction data from the PayPal_Returned event argument object SubscriptionReturnedEventArgs.
Click Here to view the complete Class Diagram of SubscriptionReturnedEventArgs object.
- You do not need to enable PDT if you just need to collect Transaction ID from PayPal_Returned event. e.TransactionID is available even though if you do not set PDT Authentication token. But, Transaction ID is available ONLY IF a payment is made. If you offer FREE Trial period, then, there will be no payment made at the subscription sign up and so, Transaction ID will not be available. For tracking Subscription, you should use the property e.SubscriptionInfo.SubscriberID.