Using the PayPal APIIf you are familiar with

PayPal 101PayPal offers secure online payment options. Buyers can set up a PayPal account and fund the accountwith a credit card, a bank account, or by sending in money to PayPal. Merchants can use PayPal toaccept various types of payments and pays PayPal a commission for handling the transaction. To set upa PayPal buyer or merchant account for use online, visit www.paypal.com, as shown in Figure 6-1. Figure 6-1These materials have been reproduced with the permission of PayPal, Inc.Copyright 2003 PayPal, Inc. All rights reserved. PayPal was made famous because of eBay, but numerous other companies use PayPal to facilitate pay- ment transactions on their own Web sites. Introduction to the PayPal APINow that you know the basics of the services that PayPal offers, let s turn to the PayPal API. The PayPalAPI is an XMLWeb service that can be called using the SOAPprotocol. This concept was introduced inChapter 1. 148Chapter

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services

Using the PayPal APIIf you are familiar with

Using the PayPal APIIf you are familiar with eBay, you are probably also familiar with PayPal. PayPal became famousfor allowing individuals and businesses alike to easily accept credit cards and other electronic pay- ments for their eBay auction sales. PayPal is also accepted as a payment service by companiesother than just eBay. Companies all over the world have established PayPal merchant accountstoallow payment for their goods and services online by customers who have a PayPal account. Given that eBay currently owns PayPal, it is not surprising that an API has also been releasedtoallow developers to more easily integrate PayPal payment transactions into their custom applications. This chapter gets you up and running with the PayPal API, and more specifically, covers the following: .An introduction to PayPal as an online payment service .How to set up a developer account and a security certificate required to use thePayPalAPI .How to convert the security certificate to the required format .The syntax of PayPal API queries .How to call the PayPal API using SOAPfrom Visual Studio .NET .Additional ideas for how you might use the PayPal APIAlthough the setup process to use the PayPal API is a bit tedious, the PayPal API itself is lessdetailed than the others you have looked at so far because you have only a few different ways toprocess payments. Additional information, including code examples and API documentation, isavailable on the PayPal developer site. This chapter spends the majority of time helping you getset up to use the PayPal API and also providing a simple example to illustrate how to call the APIto process payments from your programs.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services

Here are examples of other ways to use

Another example is a company called MarketWorks (www.marketworks.com) that has used the eBayAPI to streamline the listing of over 2 million listings per month. Other companies have used the API tointegrate eBay features into existing applications or have created listing tools to make management oflistings easier. SummaryYou learned about eBay as a leading online auction house, and how eBay is helping assure its future suc- cess by making it easy for you to include eBay functionality in your own programs. You learned aboutthe two different ways you can call an eBay API, and you looked at some examples of how you can usethe API in your own programs. If you want more information about the eBay API, additional examplesare included in some of the later chapters or in the comprehensive online documentation. Now, turn to Chapter 6 where you learn about the eBay s sister API: PayPal. 146Chapter

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services

Here are examples of other ways to use

Here are examples of other ways to use the eBay Web API: .Send an automatic e-mail to the winning bidder after you determine the auction has closed winner has been established. .Sign up for platform notifications (commercial-tier members only) where an HTTPpost is a URLyou specify when certain events occur, such as a buyer leaving feedback or an auctionending. .Retrieve a daily or other periodic status report of your listings on eBay. .Create a third-party listing tool that enables your customers to more easily manage their listingsfrom within their existing inventory management applications. Third-Party eBay ExtensionsAs with the other APIs discussed so far, dozens of third parties have used the eBay Web API in creativeways. On the eBay Web site, you can find an extensive list of what some of these third parties have The list is currently located at http://developer.ebay.com/DevProgram/business/stories.For example, Bonfire Media (www.bonfiremedia.com) currently offers a product called Pocket Auctions, which is an application that uses the eBay API to allow users to shop, compare prices, bid, and so on mobile phones. An example of a screen from the Bonfire Media Web site discussing Pocket Auctionsis illustrated in Figure 5-13. Figure 5-13145Using

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services

SOAP Example1.Add the following Example5procedure to the code

loop through and display the feedbackFor Each items In Response.FeedbackDetailArrayTextBox1.Text = TextBox1.Text & vbCrLf & Commenting User: & _ items.CommentingUser & vbCrLfTextBox1.Text = TextBox1.Text & Comment: & items.CommentText & _ vbCrLfNextElse display any errors that occurredTextBox1.Text = For intCount = 0 To Response.Errors.Length – 1TextBox1.Text = TextBox1.Text & Error: & _ Response.Errors(intCount).ErrorCodeTextBox1.Text = TextBox1.Text & vbCrLf & Message: & _ Response.Errors(intCount).LongMessageNext intCountEnd IfExit Subhandleerror: MsgBox( An error occurred: & Err.Number & – & Err.Description) Exit SubEnd Sub2.Run the project, and specify 5when prompted to run this example. XML ExampleThe following XMLcode retrieves feedback about a particular seller using the GetFeedbackmethod. See the earlier instructions for running this example from the existing project. Replace the UserIdvaluewith the User ID of the person for whom you want to retrieve feedback. < ?xml version= 1.0 encoding= utf-8 ?> Your Token Here 1 1 GetFeedback Specify User Id Here Other Ways to Use the eBay APIIn the previous sections, you looked at five examples to give you an idea of how you can use the eBayAPI in your applications. Following are some additional examples of ways you might want to use theeBay API. Additional examples of the eBay API are also included in the later chapters and case studies atthe end of this book. 144Chapter

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services

SOAP Example1.Add the following Example5procedure to the code

SOAP Example1.Add the following Example5procedure to the code section of the existing project. Replace where specified with your own eBay credentials. Sub Example5() On Error GoTo handleerrorDim strToken As StringDim strDevId As StringDim strAppId As StringDim strCertId As String specify credentials required to access APIstrToken = Your Token Here strDevId = Your Dev Id Here strAppId = Your App Id Here strCertId = Your Cert Id Here Dim SOAPService As New ebay.eBayAPIInterfaceServiceSOAPService.Url = _ https://api.sandbox.ebay.com/wsapi?callname=GetFeedback&siteid=0&appid= & _ strAppId & version=383 SOAPService.RequesterCredentials = New ebay.CustomSecurityHeaderTypeSOAPService.RequesterCredentials.eBayAuthToken = strTokenSOAPService.RequesterCredentials.Credentials = New ebay.UserIdPasswordTypeSOAPService.RequesterCredentials.Credentials.AppId = strAppIdSOAPService.RequesterCredentials.Credentials.DevId = strDevIdSOAPService.RequesterCredentials.Credentials.AuthCert = strCertIdDim Request As New ebay.GetFeedbackRequestTypeDim Response As New ebay.GetFeedbackResponseType specify the API versionRequest.Version = 383 specify the seller s user id to retrieve feedback forRequest.UserID = Specify a Valid Seller User Id call the GetFeedback method to retrieve the feedbackResponse = SOAPService.GetFeedback(Request) Dim intCount As Integer display the feedback about the sellerIf IsNothing(Response.Errors) ThenDim items As New ebay.FeedbackDetailType if no feedback, then exitIf IsNothing(Response.FeedbackDetailArray) ThenTextBox1.Text = No feedback for this seller Exit SubEnd If143Using

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services

#4 Retrieve Winning Bidders of Dutch AuctionThis example calls

Dim items As ebay.OfferType if no users, then exitIf IsNothing(Response.BidArray) ThenTextBox1.Text = No users were returned. Exit SubEnd IfFor Each items In Response.BidArrayTextBox1.Text = TextBox1.Text & vbCrLf & User Id: & _ items.User.UserID & vbCrLfTextBox1.Text = TextBox1.Text & Quantity: & items.Quantity & _ vbCrLfNextElse display any errors that occurredTextBox1.Text = For intCount = 0 To Response.Errors.Length – 1TextBox1.Text = TextBox1.Text & Error: & _ Response.Errors(intCount).ErrorCodeTextBox1.Text = TextBox1.Text & vbCrLf & Message: & _ Response.Errors(intCount).LongMessageNext intCountEnd IfExit Subhandleerror: MsgBox( An error occurred: & Err.Number & – & Err.Description) Exit SubEnd Sub2.Run the project and specify 4when prompted to run this example. XML ExampleThis example shows the XMLcode for retrieving the winning bidders of a Dutch auction using theGetHighBiddersmethod. See the earlier instructions for using this in the existing project. Replace theItemIdvalue with the Item ID of a listing for which you wish to retrieve winning bidders. < ?xml version= 1.0 encoding= utf-8 ?> Your Token Here 1 4501701557 GetHighBidders #5 Retrieve Feedback about a SellerThis final example calls the GetFeedbackmethod to retrieve feedback about a particular seller. 142Chapter

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services

#4 Retrieve Winning Bidders of Dutch AuctionThis example calls

#4 Retrieve Winning Bidders of Dutch AuctionThis example calls the GetHighBiddersmethod to retrieve the winning bidders for a Dutch auction. SOAP Example1.Add the following Example4procedure to the code section of the existing project. Replace where specified with your own eBay credentials. Also specify a valid Dutch auction on the Sandbox test eBay site where indicated. Sub Example4() On Error GoTo handleerrorDim strToken As StringDim strDevId As StringDim strAppId As StringDim strCertId As String specify credentials required to access APIstrToken = Your Token Here strDevId = Your Dev Id Here strAppId = Your App Id Here strCertId = Your Cert Id Here Dim SOAPService As New ebay.eBayAPIInterfaceServiceSOAPService.Url = _ https://api.sandbox.ebay.com/wsapi?callname=GetHighBidders&siteid=0&appid= & strAppId & version=383 SOAPService.RequesterCredentials = New ebay.CustomSecurityHeaderTypeSOAPService.RequesterCredentials.eBayAuthToken = strTokenSOAPService.RequesterCredentials.Credentials = New ebay.UserIdPasswordTypeSOAPService.RequesterCredentials.Credentials.AppId = strAppIdSOAPService.RequesterCredentials.Credentials.DevId = strDevIdSOAPService.RequesterCredentials.Credentials.AuthCert = strCertIdDim Request As New ebay.GetHighBiddersRequestTypeDim Response As New ebay.GetHighBiddersResponseType specify the API versionRequest.Version = 383 specify the item id for the dutch auctionRequest.ItemID = Put Item Id Here call the AddItem method to list the itemResponse = SOAPService.GetHighBidders(Request) Dim intCount As Integer display the successful list of users who purchased this item under the dutch auctionIf IsNothing(Response.Errors) Then141Using

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services

SOAP Example1.Add the following Example3procedure to the code

TextBox1.Text = No items for this seller Exit SubEnd If display the itemsFor Each items In Response.ItemArrayTextBox1.Text = TextBox1.Text & vbCrLf & Title: & _ items.Title & vbCrLfTextBox1.Text = TextBox1.Text & Description: & _ items.Description & vbCrLfNextElse display any errors that occurredTextBox1.Text = For intCount = 0 To Response.Errors.Length – 1TextBox1.Text = TextBox1.Text & Error: & _ Response.Errors(intCount).ErrorCodeTextBox1.Text = TextBox1.Text & vbCrLf & Message: & _ Response.Errors(intCount).LongMessageNext intCountEnd IfExit Subhandleerror: MsgBox( An error occurred: & Err.Number & – & Err.Description) Exit SubEnd Sub2.Run this program and specify 3when prompted to run this example. XML ExampleThe following code is an example of XMLcode that retrieves all pending auctions for a specified sellerusing the GetSellerListmethod. Follow the instructions described in the beginning of this section ifyou want to run this example from the existing project. Also, replace the User ID with the ID of someonefor whom you want to retrieve pending auctions. < ?xml version= 1.0 encoding= utf-8 ?> Your Token Here 1 Valid User Id Goes Here GetSellerList 32 10

1 2004-10-20 00:00:01 2004-10-20 23:59:59 140Chapter

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Inexpensive Web Hosting services

SOAP Example1.Add the following Example3procedure to the code

SOAP Example1.Add the following Example3procedure to the code section of the existing project. Replace where specified with your own eBay credentials. Also replace the User ID value with User ID of a seller for whom you wish to retrieve a list of items. Sub Example3() On Error GoTo handleerrorDim strToken As StringDim strDevId As StringDim strAppId As StringDim strCertId As String specify credentials required to access APIstrToken = Your Token Here strDevId = Your Dev Id Here strAppId = Your App Id Here strCertId = Your Cert Id Here Dim SOAPService As New ebay.eBayAPIInterfaceServiceSOAPService.Url = _ https://api.sandbox.ebay.com/wsapi?callname=GetSellerList&siteid=0&appid= & strAppId & version=383 SOAPService.RequesterCredentials = New ebay.CustomSecurityHeaderTypeSOAPService.RequesterCredentials.eBayAuthToken = strTokenSOAPService.RequesterCredentials.Credentials = New ebay.UserIdPasswordTypeSOAPService.RequesterCredentials.Credentials.AppId = strAppIdSOAPService.RequesterCredentials.Credentials.DevId = strDevIdSOAPService.RequesterCredentials.Credentials.AuthCert = strCertIdDim Request As New ebay.GetSellerListRequestTypeDim Response As New ebay.GetSellerListResponseType specify the API versionRequest.Version = 383 specify user id for seller you wish to retrieve list forRequest.UserID = Specify User Id Here call the GetSellerList method to get the listResponse = SOAPService.GetSellerList(Request) Dim intCount As Integer display the list of items for this sellerIf IsNothing(Response.Errors) ThenDim items As New ebay.ItemTypeTextBox1.Text = Number of items for seller: & _ Response.ReturnedItemCountActual & vbCrLf if no items, then exitIf IsNothing(Response.ItemArray) Then139Using

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Inexpensive Web Hosting services