PayPal APIs_ Up and Running_ A Developer's Guide - Michael Balderas [2]
Search transactions using a specified search criteria
Retrieve details of a specific transaction
Accept PayPal for multiparty payments
Accept PayPal for subscriptions or freemium models. (Freemium models offer a basic product or service free of charge, while charging a premium for advanced features. A good example is something like CCleaner: you can download it and use it free, and pay for a license if you want support. You can also make donations to future development—and they accept PayPal for both.)
PayPal’s NVP API makes it simple to integrate PayPal payments into your specific web application. You, the merchant, construct an NVP string and post it via HTTPS (HTTP Secure, aka TLS/SSL) to the PayPal authorization server. PayPal posts back an NVP-formatted response that you then parse in your web application for the information relevant to the payment. Figure 1-1 shows a basic request and response workflow.
Figure 1-1. Basic NVP request and response
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
Note
Adaptive APIs also require an APP ID during the request.
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 features of the NVP API, such as Express Checkout, require calls to multiple API operations. Other APIs like Direct Pay only require one call. But typically, you are required to:
Call an API operation—for example, SetExpressCheckout—that sets up the return URL PayPal uses to redirect your buyer’s browser after the buyer finishes on PayPal. Other setup routines can be performed by this same API operation.
Call additional API operations after receiving the buyer’s permission on PayPal, such as GetExpressCheckoutDetails or DoExpressCheckoutPayment.
Figure 1-2 shows the execution workflow between your application and PayPal.
Figure 1-2. Advanced Express Checkout NVP request and response
Getting Started
There are two methods for integrating PayPal’s NVP API into your application: direct integration and integration through a Software Development Kit (referred to as SDK). I focus on direct integration into your website and applications.
Direct Versus SDK Integration
Direct integration allows you to use the programming language of your choice to communicate via the NVP API. This is the most flexible approach and allows direct access to the Name-Value Pair elements of the API. SDK integration provides simple functions for integration using the NVP API. There are SDKs are provided for Java, ASP.NET, PHP, Coldfusion, and Ruby. This type of integration typically wraps the HTTPS interfaces in the respective language, making the operations more natural for the developer to work with, because they are formatted in a familiar language and require just a few simple function calls to access.
Testing Versus Live Implementation
PayPal provides a sandbox environment to use while developing your application. The environment replicates the live environment, but true payment processing doesn’t occur when using the sandbox. Once you have fully developed and debugged your application, you can then switch to the live environment and start taking payments. Switching between the two is as simple as changing the target server and the API credentials used to access the server. The rest of your application will remain unchanged.
Tip
I recommend setting up your API credentials in separate files within your application. This way, you can have your sandbox credentials in one file and your production credentials in another file, referenced accordingly. For added security, I would locate these files on your server outside the default webroot, so that they cannot be called