Table of Contents Previous Next Index

NVP API Web Samples

NVP API Web Samples
This chapter describes the NVP API Web Samples which access the NVP API directly. This section includes the following topics:
l
l
l
l
Descriptions of the Samples
The web samples consist of the following:
l
l
l
l
The main page of the samples, index.html or Default.htm, contains links to each sample.
Note:
We describe the code samples for all programming languages in this section. Language specific filenames are shown as filename.ext. For example, DoDirectPayment.ext stands for DoDirectPayment.java, DoDirectPayment.php, and so forth.
Charging a Credit Card Using Direct Payment
This sample shows how to use Direct Payment to charge a credit card. Access this sample from the following choices displayed on index.html or Default.htm:
In the DoDirectPayment request, the PAYMENTACTION parameter is set to Sale.
In the DoDirectPayment request, the PAYMENTACTION parameter is set to Authorization.
The primary files for this sample are:
This is the main web page for the DoDirectPayment sample. This page allows the user to enter name, address, amount, and credit card information. It also accept input variable paymentType which becomes the value of the PAYMENTACTION parameter.
When the user clicks the Submit button, DoDirectPaymentReceipt.ext is called.
The code collects transaction parameters from the form displayed by DoDirectPayment.ext then constructs and sends the DoDirectPayment request string to the PayPal server. The paymentType variable becomes the PAYMENTACTION parameter of the request string.
After the PayPal server returns the response, the code displays the API request and response in the browser. If the response from PayPal was a success, it displays the response parameters. If the response was an error, it displays the errors.
Accepting PayPal in Express Checkout
This sample shows how to use Express Checkout to accept payments using PayPal. Access this sample from the following choices displayed on index.html or Default.htm:
In the SetExpressCheckout request, the PAYMENTACTION parameter is set to Sale.
ExpressCheckout - Authorization
In the SetExpressCheckout request, the PAYMENTACTION parameter is set to Authorization.
In the SetExpressCheckout request, the PAYMENTACTION parameter is set to Order.
The primary files for this sample are:
This is the main web page for the Express Checkout sample. The page allows the user to enter amount and currency type. It also accept input variable paymentType which becomes the value of the PAYMENTACTION parameter.
This file is called after the user clicks on a button during the checkout process to use PayPal's Express Checkout. The user logs in to their PayPal account.
The code collects transaction parameters from the form displayed by SetExpressCheckout.ext then constructs and sends a SetExpressCheckout request string to the PayPal server. The paymentType variable becomes the PAYMENTACTION parameter of the request string. The RETURNURL parameter is set to this file; this is how ReviewOrder.ext is called twice.
On the first pass, the buyer completed the authorization in their PayPal account; now the code gets the payer details by sending a GetExpressCheckoutDetails request to the PayPal server. Then the code calls GetExpressCheckoutDetails.ext.
Note:
Be sure to check the value of PAYPAL_URL. The buyer is sent to this URL to authorize payment with their PayPal account. For testing purposes, this should be set to the PayPal sandbox.
Calls GetExpressCheckoutDetails.ext, CallerService.ext, and Display.ext.
Displays the payer details returned by the GetExpressCheckoutDetails response and calls DoExpressCheckoutPayment.ext to complete the payment authorization.
Calls DoExpressCheckoutPayment.ext and CallerService.ext.
This functionality is called to complete the payment with PayPal and display the result to the buyer.
The code constructs and sends the DoExpressCheckoutPayment request string to the PayPal server.
Called by GetExpressCheckoutDetails.ext and CallerService.ext.
Getting Transaction Details
This sample shows how to use the GetTransactionDetails request. Access this sample from the following choice displayed on index.html or Default.htm:
The main page displays a text box where the user enters a transaction ID. When the user clicks the Submit button, the code constructs an NVP API request to GetTransactionDetails and sends it to the PayPal server.
The primary files for this sample are:
This is the main page for GetTransactionDetails sample. This page displays a text box where the user enters a transaction ID and a Submit button that calls TransactionDetails.ext.
Sends a GetTransactionDetails NVP API request to PayPal.
The code retrieves the transaction ID and constructs the NVP API request string to send to the PayPal server. The request to PayPal uses an API signature.
After receiving the response from the PayPal server, the code displays the request and response in the browser. If the response was a success, it displays the response parameters. If the response was an error, it displays the errors received.
Common Files
The following files are common to the samples.
Table C.4
Calls DoDirectPayment.ext, SetExpressCheckout.ext, and GetTransactionDetails.html.
Called by TransactionDetails.ext, ReviewOrder.ext, DoDirectPaymentReceipt.ext, and Display.ext.
Called by DoDirectPaymentReceipt.ext, TransactionDetails.ext, and DoExpressCheckoutPayment.ext.
Sample API User with API Signature
The samples come with an API signature for use with the samples and the PayPal Sandbox. This API signature belongs to the following user:
 
AIzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU
IMPORTANT:
You must protect the API signature values in your implementation. Consider storing these values in a secure location other than your web server document root and setting the file permissions so that only the system user executing your ecommerce application can access it.
The sample code does not store these values securely. The sample code should never be used in production.
Samples Using Classic ASP
This section contains information for configuring and running the NVP API Web Samples Using Classic ASP.
Required Software
No additional software is required.
Download and Unzip the Samples
The latest version of the Web Samples are available at https://www.paypal.com/IntegrationCenter/ic_nvp.html.
1.
2.
Installing the Samples
The samples must be installed in IIS. The samples require IIS version 5.1 or above.
Create a virtual directory named PayPalClassicAspNvpSamples in IIS that points to Samples_Root.
Running the Samples
First, make sure that you have installed the required software and the samples.
You can run the samples by entering the following address in a web browser:
http://name_of_Server:port/PayPalClassicAspNvpSamples/Default.htm
Samples Using PHP
This section contains information for configuring and running the NVP API Web Samples Using PHP.
Required Software
The following software is required:
Table C.6
You must install and configure PHP with the Apache HTTP Server.
Download and Unzip the Samples
The latest version of the Web Samples are available at https://www.paypal.com/IntegrationCenter/ic_nvp.html.
1.
2.
Installing the Samples
Copy the sample folder, php_nvp_samples, to the docroot of the Apache HTTP Server. By default docroot is in datadir/htdocs.
Running the Samples
First, make sure that you have installed the required software and the samples.
You can run the samples by entering the following address in a web browser:
http://name_of_Apache_HTTP_Server:port/php_nvp_samples/index.html
Samples Using ColdFusion
This section contains information for configuring and running the NVP API Web Samples Using ColdFusion.
Required Software
The following software is required:
Table C.7
Download and Unzip the Samples
The latest version of the Web Samples are available at https://www.paypal.com/IntegrationCenter/ic_nvp.html.
1.
2.
Installing the Samples
Note:
Copy the sample folder to your ColdFusion application server web document root, ColdFusionMX7_root_directory\wwwroot.
Running the Samples
First, make sure that you have installed the required software and the samples.
You can run the samples by entering the following address in a web browser:
http://name_of_Server:port/cf_nvp_samples/index.html