This chapter provides a very brief overview of PayPal’s Name-Value Pair (NVP) APIs, the primary way that you’ll interact with PayPal products throughout the remainder of this book. Since using the NVP APIs is as simple as making some HTTP requests and parsing the responses, we’ll get a Python project up and running with Google App Engine (GAE) as part of this initial overview. Future chapters all use Python-based GAE projects, so unless you’re definitely planning to port the code without running it, you should make the most of this opportunity to learn the basics. After reading this chapter, it is highly recommended that you check out and run the sample code for Tweet Relevance as introduced in Appendix A.
PayPal’s NVP API makes it simple to integrate payments into your application. As the merchant, your web application constructs an NVP string and transmit it via HTTPS (HTTP Secure) to the PayPal authorization server, and PayPal sends back an NVP-formatted response that your web application parses for the information relevant to the payment. Figure 1-1 shows this basic request and response workflow, which is typical of just about any web application.
The request identifies:
The name or method of the API operation to be performed and its version
PayPal API credentials
Operation-specific parameters formatted as name/value pairs
Various PayPal products may require additional specific request
parameters as indicated by PayPal’s official documentation. For
example, Adaptive Payments APIs also require an APP ID
field to be specified.
The PayPal API server executes the operation and returns a response containing:
Acknowledgment of success or failure (including any warnings returned in case of failure)
PayPal tracking information specific to the API operation
Response-specific information required to fulfill the request
Some PayPal products such as Express Checkout require calls to multiple API operations, while others such as Direct Pay (part of Website Payments Pro) only require one call. We’ll review Express Checkout in the next chapter, but Figure 1-2 is included to illustrate its typical flow, which should look pretty familiar and intuitive if you’ve ever used PayPal. Either way, interacting with PayPal products is just a series of API calls that allow you to accomplish a wide variety of tasks. A few examples of the possible transactions PayPal products support include:
Accepting PayPal as part of a streamlined checkout process
Charging a credit card
Capturing previously authorized payments
Reauthorizing or voiding previous authorizations
Paying single or multiple recipients
Issuing full or partial refunds
Searching transactions histories
Retrieving details of specific transactions
Processing payments involving more than one party
Setting up recurring subscription charges
Accepting Donations
Figure 1-2. A typical Express Checkout in which a merchant site establishes a session with PayPal and then redirects the buyer to PayPal for specification of shipping and payment information. Once the buyer confirms transaction details, PayPal redirects the buyer back to the merchant site where it regains control of the checkout and can issue additional requests to PayPal for final payment processing.
With a broad understanding of how payment transactions are implemented, let’s briefly segue into an overview of GAE and how to implement HTTP requests, the essential skill required to interact with PayPal APIs.