PayPal Hacks. 100 Industrial-Strength Tips and Tools Free Open Book

PayPal Hacks. 100 Industrial-Strength Tips and Tools

Previous Section  < Day Day Up >  Next Section

Hack 98 Search eBay for Listings that Accept PayPal

figs/expert.gif figs/hack98.gif

Use the eBay API to search for PayPal-enabled listings.

eBay and PayPal are a natural fit. eBay buyers love to pay with PayPal because it's quick and easy, so the vast majority of items listed for sale on eBay accept PayPal. This hack uses the eBay API to search for listings at http://www.ebay.com that accept PayPal.

Like PayPal API applications, eBay API applications can be written using any programming language and operating system. This hack uses the eBay Software Development Kit (SDK) for Windows and the C# programming language. eBay SDKs abstract away some of the implementation details of programming the API to make it easier to create an application. In addition to the SDK for .NET, eBay also provides an SDK for Java, as well as XML over HTTPS POST and SOAP interfaces. See eBay Hacks by David A. Karp (O'Reilly) for further coverage of the eBay API.


To create a search application with the eBay SDK, you must first perform a few preliminary setup steps:

  1. Sign up for the eBay Developers Program at http://developer.ebay.com. When you complete the registration process (which is free), you'll receive a set of developer keys you need to begin developing eBay applications against the eBay test environment, known as the Sandbox (different than the PayPal Sandbox [Hack #87] ).

  2. Download the eBay SDK for Windows and install it on your computer. Remember, even if you're not using Windows and .NET, you can still write applications using the eBay API. For instance, much of the API code in eBay Hacks is written in Perl, which can, of course, be used on virtually any platform and without needing to be supported by an SDK.

  3. Create a test user account on the eBay Sandbox. Go to http://sandbox.ebay.com, click Register at the top of the page, and fill out the form. Although the form looks just like the sign-up form used by eBay, an eBay Sandbox account is similar to a PayPal Sandbox account, in that it is merely a pseudo-account used just for testing your software application.

  4. Create a security token using the token generator located at http://developer.ebay.com/tokentool. This page takes the developer keys from step 1, as well as your sandbox user ID and password, and converts them into a security token that you can use for testing purposes. You pass the token to the eBay API server each time your application makes an API call.

8.14.1 The Code

Now that you've done the preparatory work, it's time to write your application. Create a Windows forms application with a small text box called txtSearch, a button called btnSearch, and a listbox, lstItem, in which to store the search output.

To call the functions in the SDK, begin by making a reference to the assembly eBay.SDK.dll from your project in Visual Studio .NET. Then, insert the appropriate include files at the top of your form's code window:

using eBay.SDK;

using eBay.SDK.API;

using eBay.SDK.Model;

using eBay.SDK.Model.Item;

Finally, create a Click event handler for the button that performs the search and displays the results:

private void btnSearch_Click(object sender, System.EventArgs e)

{

    IItemFoundCollection items;

    GetSearchResultsCall search = new GetSearchResultsCall(CreateSession( ));

    search.Query = txtSearch.Text;

    search.PayPalItemsOnly = true;

    search.MaxResults = 20;    // can be up to 200; more if you use paging

    items = search.GetSearchResults( );



    foreach(IItem it in items) 

    {

        lstItem.Items.Add(it.Title);

    }

}

Because the majority of the communication and data-handling code is wrapped by the classes provided by the SDK, the code you have to write is fairly straightforward. To do the search, this procedure simply creates an instance of the GetSearchResultsCall object, assigns values to its properties, and then calls the object's GetSearchResults method.

Setting the PayPalItemsOnly method to true filters out non-PayPal items.


The return value of GetSearchResults is a typed IItemFoundCollection that is populated with IItem objects, each of which represents an item listed for sale on eBay. After the function returns the collection of eBay items, the foreach loop uses it to populate the listbox with their titles.

There's one part of this code that can be a little tricky: creating a session object. The eBay ApiSession object is required to be passed to the server along with every eBay API call. Our event handler gets an ApiSession object by calling a function called CreateSession, which looks like this:

private ApiSession CreateSession( ) 

{

    ApiSession sess = new eBay.SDK.API.ApiSession( );

    sess.Developer = ConfigurationSettings.AppSettings["DeveloperID"];

    sess.Certificate = ConfigurationSettings.AppSettings["Certificate"];

    sess.Application = ConfigurationSettings.AppSettings["ApplicationID"];

    IApiToken t = new ApiToken( );

    t.Token = ConfigurationSettings.AppSettings["Token"];

    sess.Token = t;

    sess.Url = ConfigurationSettings.AppSettings["ServerUrl"];

    return sess;

}

8.14.2 Running the Hack

This code expects to find the configuration information it needs in a .NET XML configuration file, called Web.config if you're writing a web application or ExeName.config (where ExeName is the name of the executable) if you're creating a compiled binary application. A typical configuration file of an eBay application written in any .NET language looks like this:

 <?xml version="1.0" encoding="utf-8" ?>

 <configuration>

   <appSettings>

     <add key="DeveloperID" value="mydevid" />

     <add key="ApplicationID" value="myappid" />

     <add key="Certificate" value="mycert" />

     <add key="ServerUrl" value="https://api.sandbox.ebay.com/ws/api.dll" />

     <add key="Token" value="AgAAAA**AQAAAA**aAAAAA**n8yAQA" />

   </appSettings>

 </configuration>

For this to work, you need to replace the italicized values in the appSettings section (mydevid, myappid, and mycert) with your developer keys (sent to you from eBay after registering in step 1, earlier in this hack) and your security token (generated in step 4). Finally, the ServerUrl value provided here is the correct URL for the eBay development Sandbox. (You'll use a different URL to take the application live.)

Compile your application, and give it a whirl!

8.14.3 Hacking the Hack

There are many more things you can do with the eBay API besides search. One of the most common operations involves automatically listing items for sale, typically to save time in the selling process or provide integration between your inventory database and eBay. You can also use the eBay API to obtain details about listings in progress, download high-bidder information for completed items, and even create notifications when a bidder with negative feedback bids on one of your auctions! There are more than 70 calls in the eBay API, and the SDK provides quite a few code examples in a number of different programming languages.

Jeffrey McManus

    Previous Section  < Day Day Up >  Next Section
    Index: [SYMBOL][A][B][C][D][E][F][G][H][I][J][L][M][N][O][P][Q][R][S][T][U][V][W][X][Y]


         Main Menu
    PayPal Hacks
    Table of Contents
    Copyright
    Credits
    Preface
    Chapter 1. Account Management
    Chapter 2. Making Payments
    Chapter 3. Selling with PayPal
    Chapter 4. Payment Buttons
    Chapter 5. Storefronts and Shopping Carts
    Chapter 6. Managing Subscriptions
    Chapter 7. IPN and PDT
    Chapter 8. The PayPal Web Services API
    Introduction: Hacks #87-100
    8.2 Create a Developer Account
    Hack 87 Set up the Sandbox
    Hack 88 Make Your First API Call
    Hack 89 Create a Wrapper Class for Your API Calls
    Hack 90 Use the PayPal API Wrapper Class
    Hack 91 Refund Payments with the API
    Hack 92 Handle Transaction Errors within the API Wrapper
    Hack 93 Retrieve Transaction Details with the API
    Hack 94 Search for PayPal Transactions
    Hack 95 Hack the API Wrapper
    Hack 96 Issue Payments en Masse with the Mass Pay API
    Hack 97 Pay Affiliates and Suppliers on a Schedule
    Hack 98 Search eBay for Listings that Accept PayPal
    Hack 99 Test IPN and PDT in the Sandbox
    Hack 100 Go Live
    Colophon
    Index


    More Books
    PHP Hacks
    Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
    The Koran (Holy Qur'an)
    Macromedia Flash 8 Bible
    Search Engine Optimization for Dummies
    YouTube Traffic
    PHP 5 for Dummies
    Harry Potter and The Chamber of Secrets
    Harry Potter and the Sorcerer's Stone
    The Pilgrim's Progress
    Wireless Hacks
    Flash Hacks. 100 Industrial-Strength Tips & Tools
    PayPal Hacks. 100 Industrial-Strength Tips and Tools
    Amazon Hacks
    Pdf Hacks
    The Da Vinci Code
    Google Hacks
    The Holy Bible
    Windows XP For Dummies
    Harry Potter and the Half-Blood Prince
    Seo Book
    Upgrading and Repairing Networks
    Macromedia Dreamweaver 8 UNLEASHED
    Windows XP Annoyances
    Windows XP Hacks
    Microsoft Windows XP Power Toolkit
    Teach Yourself MS Office In 24Hours
    iPod & iTunes Missing Manual
    PC Hacks 100 Industrial-Strength Tips and Tools
    PC Overclocking, Optimization, and Tuning - 2th Edition
    PC Hardware In A Nutshell 3rd Edition
    PC Hardware in a Nutshell, 2nd Edition
    Upgrading and Repairing PCs
    Google for Dummies
    MySQL Cookbook
    Teach Yourself Macromedia Flash 8 In 24 Hours
    PHP CookBook
    Sams Teach Yourself JavaScript in 24 Hours
    PHP5 Manual
    Free Games Paper Airplanes
    500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele