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

Skip Navigation Links.

Multiple-Item Payment: Add to Cart Button

With shopping carts, buyers select multiple items and pay for them with a single payment. A shopper browses your entire catalog of products and adds the ones for purchase to a virtual shopping cart. Buyers review the items in their carts before checking out and making their payments. Shopping carts comes in two basic forms: 


- The PayPal Shopping Cart,  which is hosted by PayPal 

- Third party shopping carts that are compatible with PayPal and that integrate using Website Payments Standard.

If you use PayPal Shopping Cart, then "Add to Cart" Button will add a single item information to your PayPal hosted shopping cart. But if you use third party shopping cart, then you will find Upload Complete Cart Button  useful for your purpose. Upload Complete Cart Button  will upload a list of items directly to PayPal hosted shopping cart at once.

 

If you did not upgrade your account to a Premier or Business account, you cannot receive payment. So, you should upgrade your PayPal account before you do any experiment with Website Payments Standard features. You can do this easily through the account itself by logging in and visiting https://www.paypal.com/us/cgi-bin/webscr?cmd=_business-upgrade-info

 

You can place a separate Add to Cart button for each item in your website. In order to start, please follow the following steps:

  1. Drag and drop an instance of the Add To Cart Button control from your Visual Studio Toolbox as shown below:



  2. The first property of this control that you need to set is your Business Email Address or Merchant ID. 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 Inbox from SPAMs. You can get your Merchant ID from your PayPal account's Profile section. You can set either Business Email or Merchant ID from the Smart Tag or from the Property Editor.

  3. Now you may want to set few more properties like Amount, ItemName, ItemNumber 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 ScreenShot.



  4. Furthermore, you may choose to set the visual styles and PayPal page behaviors for the Add to Cart 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 screenshot.creenshot.



  5. Handling Instant Payment Notification (IPN) from PayPal:

    Instant Payment Notification is a mechanism by which you receive transaction data, and it allows you to integrate PayPal payments with your website’s back-end operations.

    By the way, the IPN handling concept is slightly different in Add to Cart button than other Payment Buttons like BuyNow Button, Donation Button etc. Because, other payment buttons work as a final checkout button and an IPN can be issued against a single checkout. But Add to Cart buttons are not a checkout button. Rather, it simply uploads an item to the PayPal hosted shopping cart. The checkout button is provided by PayPal in the very PayPal website when your customer is taken to PayPal website as a result of adding an item to the PayPal hosted shopping cart. So, PayPal needs to know a single ipn notify url for all of the add to cart buttons. So, unlike other Button Controls (i.e. Buy Now, Donation etc..), Add To Cart Button control does not have any IPN_Notified event. Rather, the expected practice is: Assign each Add to Cart Button a dedicated page for handling IPN. And each button's IPN handler url must be the same url otherwise, the last submited Add To Cart button's assigned notify_url will be considered to be the final ipn_notify url for all Add to Cart buttons that took part in the transaction.

    You can easily assign a dedicated page in design time as shown in the following screenshot:

    Please visit this page to learn more about IPN: handling Instant Payment Notification (IPN)

     

  6. Programming "Thank You for Payment" Page:

    Whenever your customer is transferred back to your website from PayPal website after completing or cancelling a payment (pursuant to submission of your BuyNow button), you can execute post payment business logic on your website by handling Payment Data Transfer (PDT) . You should set the same payment completed payment return url for all Add to Cart button you use in your application if you think that all of the Add to Cart button is meant for a single transaction.


    The following screenshot shows how to provide the payment complete return url and payment cacelled return url in the design mode. Unlike other Payment Buttons (i.e. Buy Now button, Donation button etc..) Add to Cart button does not have PayPal_Returned event as you must use a dedicated page PayPal_Return handler for all Add To Cart buttons in your web application. Please visit this page to learn more about handling PayPal return from a dedicated page.



     
  7. If you want to set this value programmatically in the run mode, you can use snippets (C#.Net) like this :



  8. If you already have provided the LicenseKey  from the design mode Smart Tag, then you are ready to allow your customer to add the item to his Shopping Cart. If you did not provide the License Key yet, your customer will be taken to PayPal SandBox.

  9. You may also want to place a View Cart Button  which will take your customers to the PayPal Shopping Cart showing the added items


Click Event:

You may want to set the properties of your Add to Cart Button after the customer has clicked the Button for purchasing an item. For example, in your web form, you may have a text box asking your customer how may copies of the item he/she wants to buy. So, if the button is clicked, you can calculate the final price and then send the information to PayPal. In order to do that, this control has an event named "Click". It is similar to any standard ASP.NET button control's Click Event as shown in the following figure:

 

If you attach an event handler to this event, then the event handler method will be executed before the data is transferred to PayPal.

 

If your textbox for quantity information has ID = txtQuantity and if you want to set price for a single item = US$ 34.78, then following snippet (C#.Net) shows how to perform calculation within Click Event Handler:

Not only PayPal related properties, you can also set Image Button related properties like Image URL, Border Color, Border Width etc from the property editor.

Event - ReturnedForShopping explained:

Add to Cart button supports an event named "ReturnedForShopping". This event is fired when your customer cliks the continue to shopping button in the PayPal hosted shopping cart and comes back to your website. You should use a single event handler method for all of your add to cart buttons. This event is not a background thread event, so you can use UI in this event handler method.

 

Please note: The continue shopping url is auto generated to support this ReturnedForShopping event. But if you do not want the control auto generate this continue shopping url, rather you want to use  a specific shopping url, then you wont be able to use this ReturnedForShopping event. You can override your preferred continue shopping url in the design mode as shown in the following screenshot:

 


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