PayPal Website Payments Pro integration on your ecommerce Website: Name-Value Pair Interface
The PayPal Name-Value Pair API (NVP API) enables you to leverage the functionality of the PayPal API by simply sending an HTTP request to PayPal and specifying request parameters using name-value pairs. The NVP API is a lightweight alternative to the PayPal SOAP API (i.e., SOAP module is not required) and provides access to the same set of functionality as the SOAP API.
You can use either HTTP Post or Get protocol to send payment information to PayPal, for example:
https://secure.myecommercesite.com/payment.php?USER=someone@unknowncompany.com&PWD=mypassword
&METHOD=GetExpressCheckoutDetails&TOKEN=EC-23T233ZP3DFB
With the NVP API, you can:
- Accept payments using Website Payments Pro.
- Search your transaction history and query details on past transactions.
- Automate back office functionality, such as capturing authorizations and processing refund
1, Download SDK (Java, .Net, PHP) from https://www.paypal.com/IntegrationCenter/ic_nvp.html, and development guide from https://www.paypal.com/en_US/pdf/PP_NVPAPI_DeveloperGuide.pdf
2, If you want to use PHP version, download it from here: https://www.paypal.com/IntegrationCenter/sdk/PayPal_PHP_NVP_Samples.zip
3, Extract code to a directory on your ecommerce web site, open index.html and run test page.
4, Open a Business Website Payments Pro account with PayPal, get your PayPal API Credentials.
5, Edit configuration file constants.php, replace the following lines with your API credentials:
define('API_USERNAME', 'sdk-three_api1.sdk.com');
define('API_PASSWORD', 'QFZCWN5HZM8VBG7Q');
define('API_SIGNATURE', 'A.d9eRKfd1yVkRrtmMfCFLTqa6M9AyodL0SJkhYztxUi8W9pCXF6.4NI');
if you want to go live with your code, change the following line from
define('PAYPAL_URL', 'https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=');
to
https://www.paypal.com/webscr&cmd=_express-checkout&token=
If you get 10002 error message, i.e.,
Error Number :10002
Short : Security error
Long : Security header is not valid
it is most likely you were using a wrong Paypal server for API_ENDPOINT (in constants.php file). Here is a list of servers you should use:
For HTTPS protocol:
API Servers for API Signature Security
If you use an API signature, post the request to one of these servers:
Sandbox: https://api-3t.sandbox.paypal.com/nvp
Live: https://api-3t.paypal.com/nvp
API Servers for API Certificate Security
If you use an API certificate, post the request to one of these servers:
Sandbox: https://api.sandbox.paypal.com/nvp
Live: https://api.paypal.com/nvp
To add shipping address, you need to include the following shipping information in both DoDirectPayment.php and DoDirectPaymentReceipt.php files:
SHIPTONAME
SHIPTOSTREET
SHIPTOSTREET2
SHIPTOCITY
SHIPTOCOUNTRYCODE
SHIPTOPHONENUM
SHIPTOZIP
So the URL posted to the PayPal server will be like this:
requiredSecurityParameters]&METHOD=DoDirectPayment&CREDITCARDTYPE=VISA
&ACCT=4683075410516684&EXPDATE=012007&CVV2=808&AMT=212.95
&FIRSTNAME=Designer&LASTNAME=Fotos&IPADDRESS=255.55.167.002
&STREET=1234+Easy+Street&CITY=San+Jose&STATE=CA&COUNTRY=United+States
&ZIP=95110&COUNTRYCODE=US&PAYMENTACTION=Sale
&SHIPTONAME=Louise+P.+Flowerchild&SHIPTOSTREET=1234+Easy+Street
&SHIPTOSTREET2=Apt+22+bis&SHIPTOCITY=New+Orleans&SHIPTOSTATE=LA
&SHIPTOCOUNTRYCODE=US&SHIPTOPHONENUM=504-555-1212&SHIPTOZIP=70114