The PayPal NVP API provides three primary methods related to Express Checkout. These operations initialize the transaction, obtain information about the buyer, and complete the transaction. Table 2-2 outlines these methods and some of the most fundamental parameters for each of them.
Table 2-2. Express Checkout API operations
API operation | Description |
---|---|
SetExpressCheckout | Sets up the Express Checkout transaction. You can specify
information to customize the look and feel of the PayPal site
and the information it displays. At a minimum, you must specify
the following information:
|
GetExpressCheckoutDetails | Obtains information about the buyer from PayPal, including shipping information. |
DoExpressCheckoutPayment | Completes the Express Checkout transaction, including the actual total amount of the order. |
Figure 2-6 provides an overview of the Express Checkout user experience from a software developer’s perspective. Before digging in deeper, it may be helpful to think through the following cursory explanation of these Express Checkout integration points. For the purposes of this checkout flow, let’s assume that a buyer has just initiated a checkout action on your site by clicking a “Pay with PayPal” button (the Checkout Entry Point) and will choose to complete the checkout process.
Behind the scenes, you invoke the
SetExpressCheckout
API and pass along details
about the order, such as how much it costs and where to
redirect the user when the transaction is completed or
cancelled.
You redirect the buyer to paypal.com by constructing a
URL that includes a token parameter returned in the response
from SetExpressCheckout
so that PayPal can
identify the buyer and details of the purchase, such as its
amount.
The buyer confirms shipping and payment information for
the purchase directly on paypal.com, and PayPal redirects the
buyer back to your website along with token
and PayerID
parameters.
Behind the scenes, you invoke the
GetExpressCheckoutDetails
API operation using the
token parameter to request details about the purchase, such as
where to ship it, an email address to send an order
confirmation, etc.
The buyer performs a final review of the order, including pertinent details you may have just fetched from PayPal, and finalizes the purchase by clicking a Complete Purchase button.
Behind the scenes, you invoke the
DoExpressCheckoutPayment
API using the token
and PayerID
parameters to identify the
user and securely complete the purchase.
You display an order confirmation and optionally take additional actions, such as sending the buyer an email confirmation or shipping a physical item.
The remainder of this section takes a closer look at each of these API operations.
A few special caveats such as additional required parameters for requests do apply for Express Checkout integrations involving digital goods purchases and some Adaptive Payments scenarios. This chapter overlooks these caveats and focuses on a typical integration. See Chapters 3 and 4 for specifics on Digital Goods purchases and using Adaptive Payments, respectively.
SetExpressCheckout
initializes the Express Checkout session and is the same operation you
executed in Making a PayPal Request with GAE to
make your first API request to PayPal. It allows you to pass variables
that format how the PayPal pages look and specify where to redirect
the buyer’s browser based upon success of the payment transaction.
Table 2-3
outlines the fields required for SetExpressCheckout
requests, and Table 2-4
outlines the fields you can expect back in a response for SetExpressCheckout
.
See SetExpressCheckout
API Operation for full details on a litany of other optional
fields that can be passed in for
SetExpressCheckout
.
Table 2-3. SetExpressCheckout request fields
Field | Description |
---|---|
METHOD | Must be SetExpressCheckout |
RETURNURL | URL to which the customer’s browser is returned after choosing to pay with PayPal. PayPal recommends that the value be the final review page on which the customer confirms the order and payment or billing agreement.Limitation: Up to 2,048 characters. |
CANCELURL | URL to which the customer is returned if he does not approve the use of PayPal to pay you. PayPal recommends that the value be the original page on which the customer chose to pay with PayPal or establish a billing agreement.Limitation: Up to 2,048 characters. |
PAYMENTREQUEST_
n _AMT | The total cost of the transaction to the customer. If
shipping and tax charges are known, include them in this
value; if not, this value should be the current subtotal of
the order. If the transaction includes one or more one-time
purchases, this field must equal the sum of the purchases. Set
this field to Limitations: Must not exceed $10,000 USD in any currency. No currency symbol. Must have two decimal places, the decimal separator must be a period (.), and the optional thousands separator must be a comma (,). |
If you have done any previous work with Express Checkout, you
may want to take note that AMT
has been deprecated in
favor of PAYMENTREQUEST_
n
_AMT
to accommodate tallying up multiple items in a checkout. Simply use
PAYMENTREQUEST_0_AMT
if dealing with only one item.
Additionally, PAYMENTACTION
is deprecated in favor of
PAYMENTREQUEST_
n
_PAYMENTACTION
and is no longer a required field, and it now defaults to
Sale
.
Table 2-4. SetExpressCheckout response fields
Field | Description |
---|---|
TOKEN | A time-stamped token that acts as a session identifier
that is used in subsequent API requests to tell PayPal that
you are processing this payment with Express Checkout.
The token expires after three hours. If you set the
token in the |
GetExpressCheckoutDetails
obtains information about an Express Checkout transaction. The
response essentially echoes back the information and values enabled in
SetExpressCheckout
, although it
does return a few other important fields such as PAYERID
,
and it is possible that the response may contain additional fields
such as NOTE
. For example, the response may contain a
NOTE
field that the buyer may have entered in if the
ALLOW
NOTE
field was set in
SetExpressCheckout
. Table 2-5
describes the required
GetExpress
CheckoutDetails
fields.
As a best practice, it is recommended that you invoke
GetExpressCheckoutDetails
as part of an Express Checkout
integration, but it is not technically required that you do so.
See GetExpressCheckoutDetails API Operation for full details on this API.
DoExpressCheckoutPayment
completes the Express Checkout transaction and returns the payment
response. In the case of a billing agreement that you specified in the
SetExpressCheckout
API call, it is
officially created when you call the DoExpressCheckoutPayment
API operation. For
a minimal Express Checkout integration, you’d only need to properly
invoke DoExpressCheckoutPayment
after first setting up
the transaction with SetExpressCheckout
and handling the
PayPal redirects. Table 2-6
lists some common DoExpressCheckoutPayment
request fields. The
number of fields returned from DoExpressCheckoutPayment
is rather extensive. Although you may not necessarily need to use all
of these values, Table 2-7
describes some of them to give you an idea of the breadth of
information that’s available to you after a checkout has been
completed.
Table 2-6. DoExpressCheckoutPayment request fields
Field | Description |
---|---|
METHOD | Must be DoExpressCheckoutPayment . |
TOKEN | A time-stamped token, the value of which was returned
by the Set Express Checkout response and passed on to
the Get Express Checkout Details request. |
PAYERID | Unique PayPal customer account identification number.
This value is obtained by parsing the query string immediately
after PayPal redirects the customer back to your site or by
parsing the results returned from GetExpressCheckoutDetails . |
PAYMENTREQUEST_
n _AMT | The total cost of the transaction to the customer. If
shipping and tax charges are known, include them in this
value; if not, this value should be the current subtotal of
the order. If the transaction includes one or more one-time purchases, this field must equal the sum of the purchases. Set this field to Limitations: Must not exceed $10,000 USD in any currency. No currency symbol. Must have two decimal places, the decimal separator must be a period (.), and the optional thousands separator must be a comma (,). |
PAYMENTREQUEST_
n _PAYMENTACTION | How you want to obtain your payment.
If the transaction does not include a one-time purchase, this field is ignored. You cannot set this value toSale in
SetExpressCheckout request
and then change this
value to Authorization or
Order on the final API
DoExpressCheckoutPayment
request. If the value is set to Authorization or Order in SetExpressCheckout , the value
may be set to Sale or the same value (either
Authorization or Order ) in DoExpressCheckoutPayment . |
Table 2-7. DoExpressCheckoutPayment response fields
Field | Description |
---|---|
TOKEN | A time-stamped token, the value of which was returned
by the SetExpressCheckout
response. |
PAYMENTTYPE | Information about the payment. |
SUCCESSPAGEREDIRECTREQUESTED | Flag that indicates whether you need to redirect the customer to back to PayPal after completing the transaction. |
PAYMENTINFO_
n _TRANSACTIONID | Unique transaction ID of the payment. If the PaymentAction of the request was Authorization or Order , this value is your AuthorizationID for use with the
Authorization and Capture APIs. |
PAYMENTINFO_
n _TRANSACTIONTYPE | The type of transaction. Valid values are cart and express- checkout . |
PAYMENTINFO_
n _PAYMENTTYPE | Indicates whether the payment is instant or delayed.
Valid values are none ,
echeck , and instant . |
PAYMENTINFO _ n
_ORDERTIME | The time/date stamp of the payment. |
PAYMENTINFO_
n _AMT | The final amount charged, including any shipping and taxes from your Merchant Profile. |
PAYMENTINFO_
n _FEEAMT | PayPal fee amount charged for the transaction. |
PAYMENTINFO_
n _TAXAMT | Tax charged on the transaction. |
PAYMENTINFO_
n _EXCHANGERATE | Exchange rate if a currency conversion occurred. Relevant only if you are billing in the customer’s nonprimary currency. If the customer chooses to pay with a currency other than the primary currency, the conversion occurs in the customer’s account. |
PAYMENTINFO_
n _PAYMENTSTATUS | The status of the payment, which will be one of the
following:
|
PAYMENTINFO_
n _ PROTECTION
ELIGIBILITY | The type of seller protection in force for the
transaction, which is one of the following
values:
|
PAYMENTREQUEST_
n _ PAYMENT
REQUEST ID | The unique identifier of the specific payment request.
The value should match the one passed in the DoExpressCheckout request. |
L_PAYMENTINFO_
n _FMFfilterIDn | Filter ID, including the filter type (PENDING , REPORT , or DENY ), the filter ID, and the entry
number, n , starting from 0. Filter
ID is one of the following values [AVS stands for Address
Verification System]:
|
L_PAYMENTINFO_
n _FMFfilterNAME
n | Filter name, including the filter type (PENDING , REPORT , or DENY ), the filter NAME , and the entry number,
n , starting from 0. |
PAYMENTREQUEST_
n _SHORTMESSAGE | Payment error short message. |
PAYMEMNTREQUEST_
n _LONGMESSAGE | Payment error long message. |
PAYMENTREQUEST_
n _ERRORCODE | Payment error code. |
PAYMENTREQUEST_
n _SEVERITYCODE | Payment error severity code. |
PAYMENTREQUEST_
n _ACK | Application-specific error values indicating more about the error condition. |
SHIPPINGCALCULATIONMODE | Describes how the options that were presented to the
user were determined,
and is one of the following values:
|
INSURANCEOPTIONSELECTED | The Yes/No option that you chose for insurance. |
SHIPPINGOPTIONISDEFAULT | Is true if the buyer chose the default shipping option.
Value will be either TRUE
or FALSE . |
SHIPPINGOPTIONAMOUNT | The shipping amount that was chosen by the buyer. Limitations: Must not exceed $10,000 USD in any currency. No currency symbol. Must have two decimal places, the decimal separator must be a period (.), and the optional thousands separator must be a comma (,). |
SHIPPINGOPTIONNAME | This is true if the buyer chose the default shipping option. |
PAYMENTREQUEST_
n _ SELLER PAYPAL ACCOUNTID | Unique identifier for the merchant. For parallel payments, this field contains either the Payer ID or the email address of the merchant. |
See DoExpressCheckoutPayment API Operation for more details on this API, but do note that it’s well worth the time to peruse the full details of this lengthy table, even though it might seem a bit pedantic to at first—a misinformed understanding of this table can result in faulty logic in your implementation that can really hurt your bottom line. The sidebar explains one possible scenario involving a commonly overlooked payment type involving what’s known in PayPal lingo as an eCheck.