This chapter describes the NVP API Web Samples which access the NVP API directly. This section includes the following topics:
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.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:
Table C.1 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. Submits a credit card transaction to PayPal using a DoDirectPayment request.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.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:
ExpressCheckout - Authorization
Table C.2 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.When the user clicks the Submit button, ReviewOrder.ext is called. ReviewOrder.ext 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. This functionality is called after the buyer returns from PayPal and has authorized the payment.Displays the payer details returned by the GetExpressCheckoutDetails response and calls DoExpressCheckoutPayment.ext to complete the payment authorization. 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.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.
Table C.3 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.
Table C.4 This is the configuration file for the samples.This file contains the parameters needed to make an API call.The samples come with an API signature for making API calls to the PayPal sandbox. The API signature is described in “Sample API User with API Signature”. Display.ext Displays request and response parameters. If there is an error, displays request and error parameters.The samples come with an API signature for use with the samples and the PayPal Sandbox. This API signature belongs to the following user:
Table C.5
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.This section contains information for configuring and running the NVP API Web Samples Using Classic ASP.The latest version of the Web Samples are available at https://www.paypal.com/IntegrationCenter/ic_nvp.html.http://name_of_Server:port/PayPalClassicAspNvpSamples/Default.htm
Table C.6 PHP with CURL extension enabled The latest version of the Web Samples are available at https://www.paypal.com/IntegrationCenter/ic_nvp.html.Copy the sample folder, php_nvp_samples, to the docroot of the Apache HTTP Server. By default docroot is in datadir/htdocs.http://name_of_Apache_HTTP_Server:port/php_nvp_samples/index.htmlThis section contains information for configuring and running the NVP API Web Samples Using ColdFusion.
Table C.7 The latest version of the Web Samples are available at https://www.paypal.com/IntegrationCenter/ic_nvp.html.Copy the sample folder to your ColdFusion application server web document root, ColdFusionMX7_root_directory\wwwroot.http://name_of_Server:port/cf_nvp_samples/index.html