Open the text file in a text editor

At this point, you must convert the .p12 certificate into the type of certificate required by your program- ming language. For example, to use the PayPal API from Visual Studio .NET, you convert the .p12 certifi- cate to a .CER certificate. To do so, you first should double-click the previously created my_paypal_cert.p12file. The Certificate Import Wizard appears. Follow the prompts to import the certificate, specifying yourcertificate password when prompted. Accept the defaults, and a message should appear indicating that theimport was successful. Next, after the wizard completes, you export the .p12 certificate from Internet Explorer to a .CER file. Todo so, open Internet Explorer, and then select Tools.Internet Options and select the Content tab. Clickthe Certificates button and select the .p12 certificate that you use to access the Sandbox. It should appearon the Personal tab. Click the Export button, and a Certificate Export Wizard appears. Follow the wizardto accept the defaults, and on the File to Export screen, select Browse and specify the path and filenamefor the new certificate. Click Save to save the file and follow the prompts to finish the wizard. It isimportant that you keep track of the name and location where you saved the .CER file because you willneed it in calls to the API later on. Anatomy of a PayPal API QueryNow that you have all the messy setup out of the way, let s take a look at how a PayPal API query isstructured. You then see a simple example of how to execute queries using the API. Query SyntaxCurrently, you can call one of four methods of the PayPal API: RefundTransaction, TransactionSearch, GetTransactionDetails, and MassPay. Each of these is covered detail. RefundTransactionThe RefundTransactionmethod is used to request a payment refund. ARefundTransactionRequestis an object that is passed to the RefundTransactionmethod and supports the following properties: .TransactionId Required. Unique identifier for a transaction. .RefundType Type of refund. Currently Fullor Partial. .Amount Amount of refund. Required if partial refund. .Memo Custom comment about the refund. The RefundTransactionmethod responds by returning a RefundTransactionResponseobject. TransactionSearchThe TransactionSearchmethod requests a historical transaction search. Up to 100 exact matches canbe retrieved. Various criteria can be specified to limit the search results. The following properties aresupported by the TransactionSearchRequestobject that is passed to the TransactionSearchmethod: .StartDate Required. Starting date range to use for search. .End Date Ending date range to use for search. 158Chapter

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

Open the text file in a text editor

Open the text file in a text editor such as Notepad and separate the private key and the certificate intotwo separate files. The private key is indicated with the Begin and End RSAPrivate Key comment, certificate portion is indicated with the Begin and End Certificate comment. Save the private key called privatekey.pemand save the certificate in a file called certificate.pem. Other names be used. It is important that each file contains the comment in the correct syntax, with five dashes surroundingeach comment. Otherwise, you will receive an error later when trying to create the P12 certificate. Forexample, the privatekey.pem file should contain the following: —–BEGIN RSAPRIVATE KEY—–Your key is here—–END RSAPRIVATE KEY—– At this point, you have to use a cryptographic tool to convert the certificates to a PKCS12 (.p12) certifi- cate file. One example of such a tool is described in the PayPal documentation is OpenSSL, which isoffered in an easy installation version for Windows at www.slproweb.com. More information aboutOpenSSLcan also be found at www.openssl.org. Follow the instructions to download and installOpenSSL. Open a command window and navigate to the path where OpenSSL.exe is located (based on where the program). Copy your two .pem files to that same path to make this process easier. Typeopenssl.exe to run the program, and at the OpenSSLprompt, type the following command to convert files created previously: pkcs12 export inkey privatekey.pem in certificate.pem out my_paypal_cert.p12You are prompted to enter a password associated with the certificate. Make sure to write down this password for future use. Upon successful creation of the p12 certificate, a screen like the one shown 6-12 is displayed. Figure 6-12Type Exitto exit the OpenSSLtool. Verify that your .p12 certificate, called my_paypal_cert.p12, was created in that same directory. You need this file later, so copy it to a location where you can find it.

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

Setting Up Test TransactionsNow that you have created

Click the Details link, and a screen similar to Figure 6-11 is displayed. Figure 6-11These materials have been reproduced with the permission of PayPal, Inc.Copyright 2003 PayPal, Inc. All rightsreserved. Write down or electronically copy the Transaction ID value so you can use that transaction for testing theAPI in the code example later in this chapter. Obtaining and Converting a Security CertificateYou are now ready to perform the last setup step to enable you to use the API obtaining and convert- ing the security certificate. As mentioned previously, because the PayPal API deals with monetary trans- actions, you must use a higher level of security than you do with many other Web APIs discussed in thisbook. To obtain a certificate, log into PayPal Sandbox with your test business (seller) account. Click on the Profiletab, and then click the API Access link. Then, click the API Certificate Request link. Fill in the informationrequested to set up a certificate, and then click the Generate Certificate button. Click the Download buttonto download the text file that contains the certificate. Save the text file to a location on your hard drivewhere you can find it later. As another option, an e-mail is also sent that contains a link for downloading your certificate. Again, forthe test Sandbox environment, the e-mail is placed in your online inbox as opposed to being sent to youractual e-mail address. 156Chapter

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

Setting Up Test TransactionsNow that you have created

Setting Up Test TransactionsNow that you have created a test personal account and a test business account, the next step is to fundthe accounts and create some test transactions. The API cannot be used to add funds to an account a transaction, but simply to work with existing transactions. Thus, you need to use the onlinetools to add some money to the test personal account and then send some money from that account test business account. To do so, log into developer.paypal.com (PayPal Developer Central), click tab, click the Launch Sandbox button, and log in with your test personal account. Begin by manually adding some money to the test personal account you want to use for the purchase. While logged in to the Sandbox account for that user, select Add Funds. Under options, select TransferFunds. Select the account and the dollar amount and click Continue. Because this is a test account, you also have to manually clear the transaction. From the Overviews the transaction should be listed as pending. If you click the Details link, an option to clear the transactionappears. Select the Clear Transaction link and the status of the transaction changes to Completed. Next, you need to set up one or more test transactions so you can work with those transactions using While still logged in to the test personal account, click the Send Money tab. Fill in the informationfor the test business account, including the e-mail address you assigned to that account and the amountyou want to pay it. Follow the online instructions to complete the transaction. Verify that the transaction was successful by logging out of the test personal account and by logging test business account. The payment should be shown on the Overview page, as shown in the exam- ple in Figure 6-10. Notice that the available balance has been reduced by the PayPal service fee. Figure 6-10These materials have been reproduced with the permission of PayPal, Inc.Copyright 2003 PayPal, Inc. All rights reserved.

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

Figure 6-7These materials have been reproduced with the

Figure 6-8These materials have been reproduced with the permission of PayPal, Inc.Copyright 2003 PayPal, Inc. All rights reserved. Figure 6-9These materials have been reproduced with the permission of PayPal, Inc.Copyright 2003 PayPal, Inc.All rights reserved.154Chapter

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

Figure 6-7These materials have been reproduced with the

Figure 6-7These materials have been reproduced with the permission of PayPal, Inc.Copyright 2003 PayPal, Inc. All rights reserved. After you submit the new user registration, a screen similar to Figure 6-8 is displayed. You are instructed to go to your e-mail to confirm the e-mail address. Again, because no e-mail is actu- ally sent, it is really talking about your online virtual inbox. To access the message to confirm youre-mail address, simply visit developer.paypal.com, log in with your developer account, and then clickthe Email tab, as shown in Figure 6-9. From the virtual e-mail inbox, open the confirmation e-mail. Follow the instructions in the message your account. You are prompted to enter the password associated with that test account. Acon- firmation screen is then displayed to indicate your account was activated. You are given the option a bank account from that point. If you select Skip, you can add test bank account and/or credit later. Go ahead and click Continue, where you are taken to a screen that automatically some test bank account information. You just fill in a test account name and click the option to createthe test account. To log into the test user account at any time, log in to the developer.paypal.com site, select the Sandboxoption, and then select the test account you want to log in to. You are then prompted to provide thelogin credentials for that account and redirected to the Sandbox environment for that account. You should make sure to set up a test bank account and a test credit card for this new test user by select- ing Add Credit Card or Add Bank Account option from the main screen after logging in to the Sandboxenvironment with that test user. Repeat the process described previously to create a test business account for a seller.

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

Figure 6-4These materials have been reproduced with the

Figure 6-5These materials have been reproduced with the permission of PayPal, Inc.Copyright 2003 PayPal, Inc. All rights reserved. Figure 6-6These materials have been reproduced with the permission of PayPal, Inc.Copyright 2003 PayPal, Inc. All rights reserved. 152Chapter

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

Figure 6-4These materials have been reproduced with the

Figure 6-4These materials have been reproduced with the permission of PayPal, Inc.Copyright 2003 PayPal, Inc. Allrights reserved. Setting Up Test AccountsAfter you have created a developer account, you can create test accounts. While logged in to your devel- oper account, click the Sandbox option. You need to set up a test Buyer and a test Seller account to example later in this chapter. To do so, click the Create a Test Account link. Ascreen like the oneshown in Figure 6-5 is displayed. Choose the type of account you want to set up personal or business and click the Continue button, as shown in Figure 6-6. Select Personal Account and click Continue. You will repeat these steps later a business account. An Account Sign Up form, as shown in Figure 6-7, is then displayed. Fill in the address information and other information requested on the screen. You do not need to pro- vide real data because this is just a test account. For security reasons, please do not use your actualPayPal password for this test account. You can provide totally fictitious data; you just need to rememberthe username and password that is specified so you can log into that account later. Do not worry aboute-mails being sent to that e-mail address. As mentioned earlier, all e-mails go to your virtual inbox are working in the Sandbox test environment. You can tell you are in the Sandbox by the Sandbox logo on the Web page, or from the URLitself.

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

Supported FeaturesThe PayPal API supports four services in

Figure 6-2These materials have been reproduced with the permission of PayPal, Inc.Copyright 2003 PayPal, Inc. Allrights reserved. Figure 6-3These materials have been reproduced with the permission of PayPal, Inc.Copyright 2003 PayPal, Inc. Allrights reserved.150Chapter

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

Supported FeaturesThe PayPal API supports four services in

Supported FeaturesThe PayPal API supports four services in the current form, which is the beta version of the PayPal API time of this book s writing: .GetTransactionDetails Retrieve details about a particular transaction .TransactionSearch Search for transactions that meet a specified criteria .RefundTransaction Refund a prior transaction in full or in part .MassPay Send one or more payments at a timeEach of these services is examined in more detail later in this chapter. Getting Set Up to Use the PayPal APILike eBay, PayPal has a test environment called the Sandboxwhere you can test the workings of yourprogram without hitting a live server. With PayPal, because money is involved, additional steps must to ensure the communications are highly secure. In this section, I will navigate you through the tedious process of getting a developer account set up, ating some test accounts, adding some money to those test accounts, manually creating transactions, a security certificate. All these setup steps are necessary before you can take advantage of thePayPal API in the test environment. Of course, because money is involved and you are presumably the PayPal API, this chapter focuses on the Sandbox test environment. If you want to work with PayPal API later on, you must change the URLto point to the live site instead. Setting Up a Developer s AccountIn order to access the Sandbox test environment and to access the online documentation for the PayPalAPI, you need a developer s account. First, go to http://developer.paypal.com, as shown in Fig- ure 6-2. Click the link that says Sign Up Now and a signup screen, as shown in Figure 6-3, will be displayed. Fill in the requested information and follow the online instructions for completing the account registra- tion. After you have a developer account, you can revisit developer.paypal.com and log in with yournew account. Ascreen like the one shown in Figure 6-4 is then displayed. After you log into PayPal Developer Central, you have access to the various resources that enable you with the API. The Sandbox option allows you to manage test accounts and log into the Sandboxusing one of the test accounts. The Test Certificates option allows you to view test certificates for youraccounts. The Email option allows you to view a virtual e-mail inbox of the test accounts you have ated. All e-mails that would normally be sent to an actual e-mail are instead placed in the virtual e-online when you work with the Sandbox test environment. Forums are available where you with others regarding the PayPal API. Finally, the Help Center option allows you to down- load code examples and documentation.

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