How to Create One-Time Payments Using Express Checkout
This guide describes how to complete an Express Checkout transaction using the Set-Get-Do series of API operations.
For demonstration purposes, this guide makes requests using the PayPal Sandbox. For information on making calls using the NVP/SOAP APIs, including obtaining the needed API credentials and how to make test calls using the Sandbox, see Apps 101.
The figure below shows the flow of calls through a typical Express Checkout transaction. It illustrates how the transaction flow interacts with the PayPal customer and how your requests interact with PayPal (the Sandbox in this example).
1. Set Up the Payment Information
When a customer initiates a check out, call
SetExpressCheckout to specify the payment action, amount of payment, return URL, and cancel URL.
curl https://api-3t.sandbox.paypal.com/nvp \ -s \ --insecure \ -d USER=callerID # User ID of the PayPal caller account \ -d PWD=callerPswd # Password of the caller account \ -d SIGNATURE=callerSig # Signature of the caller account \ -d METHOD=SetExpressCheckout \ -d VERSION=93 \ -d PAYMENTREQUEST_0_PAYMENTACTION=SALE # type of payment \ -d PAYMENTREQUEST_0_AMT=19.95 # amount of transaction \ -d PAYMENTREQUEST_0_CURRENCYCODE=USD # currency of transaction \ -d RETURNURL=http://www.example.com/success.html # URL of your payment confirmation page \ -d CANCELURL=http://www.example.com/cancel.html # URL redirect if customer cancels payment
Note: Example calls are shown in cURL, and the code is wrapped and commented for readability.
SetExpressCheckout response contains a token value that you use in subsequent calls to complete the transaction:
2. PayPal Returns a Token
SetExpressCheckout request is successful, PayPal returns a token string in the
Token response field. The default lifetime of this token is 3 hours. You will need this token in the subsequent steps.
# SetExpressCheckout response ... TOKEN=EC%2d4RX1920730957200V ...
Important: You must URL-decode the returned token value before you can use it in other Express Checkout calls.
3. Redirect the Customer to PayPal for Approval
Using the token valued returned from
SetExpressCheckout, redirect the customer to PayPal so they can approve the transaction:
The redirect presents the customer with a PayPal log-in page. After the customer logs in, PayPal displays the transaction details on the Payments Review page. The customer approves the payment on this page by clicking Continue.
4. PayPal Redirects the Customer Back to Your Site
If the customer approves the payment, PayPal directs the customer to the payment confirmation page (the return URL specified in your
SetExpressCheckout call in Step 1). If the customer doesn't authorize the payment, PayPal directs the customer to the cancel URL that you also specified in your
SetExpressCheckout call, and you can attempt to re-initiate the checkout.
5. Obtain Approved Payment Details
If the customer approves the payment, call
GetExpressCheckoutDetails to obtain the
PayerID (which uniquely identifies the customer), and any other details you might need for transaction processing. For example, you can use the transaction details to display the customer's shipping data, and other information, on your payment confirmation page.
Use the following sample by replacing tokenValue with the token from the
curl https://api-3t.sandbox.paypal.com/nvp \ -s \ --insecure \ -d USER=callerID \ -d PWD=callerPswd \ -d SIGNATURE=callerSig \ -d METHOD=GetExpressCheckoutDetails \ -d VERSION=93 \ -d TOKEN=tokenValue
The response from this call includes the
PayerID value, which is needed to capture the payment:
# GetExpressCheckoutDetails response TOKEN=EC%2d4RX1920730957200V ... &PAYERID=6B9DKHQRKW4SG ...
6. Complete the Transaction
In addition to the transaction details, your payment confirmation page should include a Confirm button. When the customer confirms the payment, call
DoExpressCheckoutPayment to capture (collect) the payment. The following sample shows how to specify the
PayerID and token value returned from the previous calls:
curl https://api-3t.sandbox.paypal.com/nvp \ -s \ --insecure \ -d USER=callerID \ -d PWD=callerPswd \ -d SIGNATURE=callerSig \ -d METHOD=DoExpressCheckoutPayment \ -d VERSION=93 \ -d TOKEN=tokenValue \ -d PAYERID=payerID # customer's unique PayPal ID \ -d PAYMENTREQUEST_0_PAYMENTACTION=SALE # payment type \ -d PAYMENTREQUEST_0_AMT=19.95 # transaction amount \ -d PAYMENTREQUEST_0_CURRENCYCODE=USD # transaction currency, e.g. US dollars
When PayPal processes
DoExpressCheckoutPayment, it captures the payment by transferring the funds from the customer account to the appropriate merchant account and sends a confirmation e-mail to the customer.
For more details on how to use Express Checkout, see the following resources:
For information on using the PayPal APIs, how to use the Sandbox for testing, and how to move your app into production, see links provided on the Apps 101 page.