Skip to content

Instantly share code, notes, and snippets.

@billwscott
Forked from jeffharrell/gist:3134368
Created July 20, 2012 16:08
Show Gist options
  • Save billwscott/3151596 to your computer and use it in GitHub Desktop.
Save billwscott/3151596 to your computer and use it in GitHub Desktop.
The one page PayPal Express Checkout guide (using cURL)

One page PayPal Express Checkout guide using cURL

To integrate with Express Checkout have your API credentials ready and read on.

Step 1 - Send your transaction data to PayPal (your API credentials are required for safety):

curl https://api-3t.paypal.com/nvp \
  -d method=SetExpressCheckout \
  -d amt=1.00 \
  -d returnurl=http://example.com/success \
  -d cancelurl=http://example.com/cancel \
  -d version=92.0 \
  -d user=${API_USER} \
  -d pwd=${API_PWD} \
  -d signature=${API_SIGNATURE} 

Step 2 - A query string formatted response will be returned, e.g.:

TOKEN=EC-6V0052576B2719609&TIMESTAMP=2012-07-18T03:44:53Z&CORRELATIONID=1b1f2f903d3e7&ACK=Success&VERSION=47.0&BUILD=3300093

Step 3 - Copy the token value from the response, add it to the following URL, then redirect your browser there:

https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=

PayPal will send the browser back to the redirecturl you originally provided. URL parameters for PayerId and Token are appended as query params. Save these!

Step 4 - Using the token and payerid you can request the transaction details:

curl https://api-3t.sandbox.paypal.com/nvp \
  -d method=GetExpressCheckoutDetails \
  -d token=${RETURNED_TOKEN} \
  -d payerid=${RETURNED_PAYERID} \
  -d user=${API_USER} \
  -d pwd=${API_PWD} \
  -d signature=${API_SIGNATURE}

Step 5 - Finally, commit the transaction and you've completed your payment:

curl https://api-3t.sandbox.paypal.com/nvp \
  -d method=DoExpressCheckoutPayment \
  -d token=${RETURNED_TOKEN} \
  -d payerid=${RETURNED_PAYERID} \
  -d amt=1.00 \
  -d paymentaction=Sale \
  -d user=${API_USER} \
  -d pwd=${API_PWD} \
  -d signature=${API_SIGNATURE} \
  -d version=92.0

That's it! You've just completed a basic transaction with Express Checkout. Now see what you can do with all of the advanced settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment