How to Use the PayPal BuyNow Component

The BuyNow JSF component that was created by Jayashri Visvanathan, wraps the PayPal BuyNow button functionality so it can be easily reused. This button enables you to sell individual items on a website that can serve JavaServer Faces pages.  The main advantage of wrapping the BuyNow button with a JSF component is that you can populate various component attributes dynamically by binding them to properties in a managed bean. Specifically, this can save a lot of time when you have hundreds of items to sell through your website.  The tag library for the BuyNow component can be accessed using the declaration:
    <%@taglib prefix="ui" uri="http://java.sun.com/blueprints/ui/14"%>
The BuyNow component renders a form HTML element that submits information to PayPal about the item that the buyer wants to order through hidden form fields.  For this reason, when you are using this component in a JSP page, it must not be placed in a form element.  All the basic information that you would post to PayPal when you want to complete a transaction is supported as properties on the BuyNow component.  If you have additional information you want to post to PayPal other than what is supported on BuyNow component's attributes, you can use of postData attribute on the BuyNow Component. The postData attribute accepts a ValueBinding expression that evaluates to a JavaBean of type "com.sun.j2ee.blueprints.ui.shopping.BuyNowPostData". This bean supports all the attributes that you would optionally want to post to PayPal to complete a transaction.

By default the BuyNow component posts to the PayPal Sandbox.  The Sandbox is a mirror of the real PayPal site where real financial transactions aren't made. It is a safe testing environment used to test PayPal features such as Website Payments. You may want to run in this mode until your website is operational and ready to be hosted on a public domain.

By default, button images are loaded from the PayPal site.  You can configure the "image" attribute to load an alternate image if you want to override the default behavior.  You must have Internet access when you are testing your application, whether in the test mode or in the production mode because both modes initiate a connection to the PayPal Payment service.

An example of the JSF BuyNow component's use is as follows:
  <ui:buyNow business="donate@animalfoundation.com" id="buyNow1" itemName="Buy Item One"
amount="100.00" quantity="1" type="BuyNow" postData="#{PayPalBean.postData}" target="paypal"/>

JSP Tag Attributes

The BuyNowComponent supports the following attributes in addition to the standard JSF CommandButton's specific attributes. The corresponding PayPal attribute names are specified in parenthesis.

BuyNowPostData Bean Properties

The BuyNowPostData bean supports the following properties. The corresponding PayPal attribute names are specified in parenthesis.

Known Limitations

References


© Sun Microsystems 2006. All of the material in The Java BluePrints Solutions Catalog is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.