Online Book Reader

Home Category

PayPal APIs_ Up and Running_ A Developer's Guide - Michael Balderas [12]

By Root 154 0
’s browser to your site.

TOKEN=tokenValue

Specify the payer ID returned by PayPal when it redirects the customer’s browser to your site.

PAYERID=id

Specify the total amount of the payment, including shipping, handling, and tax, and include the currency if not in U.S. dollars.

AMT=amount

CURRENCYCODE=currencyID

Specify the payment action. Even though the action is a Sale, it is best to explicitly set the payment action. Refer to Table 2-3’s PAYMENT_n_PAYMENTACTION field description for allowed values.

Execute the DoExpressCheckoutAPI operation, and test that the response was successful.

Express Checkout Integration


PayPal Express Checkout is the quickest and best solution for straight-out shopping cart checkouts. PayPal’s Integration Wizard, found at https://www.paypal-labs.com/integrationwizard/ecpaypal/main.php, helps you implement Express Checkout on your site. The wizard takes you through five configuration steps, described next.

The Integration Wizard starts by presenting a basic overview of what the tool will do. You can choose to watch the introduction or skip it at this point (Figure 2-6).

Figure 2-6. Express Checkout Integration Wizard opening screen

Step 1 allows you to choose the programming language you want to use for the integration (see Figure 2-7). For the purposes of this example we are going to use PHP, but you can choose any of the following options:

Active Server Pages (ASP)

ASP.NET-C#(ASPX)

ASP.NET-VB.NET(ASPX)

Java Server Pages (JSP)

Java SDK

PHP

You also are asked to specify the return and cancel URLs. The return URL is where the purchaser will be returned to once the transaction is completed. The cancel URL is where the purchaser is sent to if she cancels the checkout, typically back to your site’s shopping cart. The payment type will be one of the following:

Sale

Authorization

Order

Figure 2-7. Express Checkout Integration Wizard step 1

The Currency Code section contains a list of currencies, both foreign and domestic, from which to choose. For this example, we will choose U.S. Dollar [USD].

The form element generated in step 2 (see Figure 2-8) wraps around your shopping cart order form, and allows you to submit the payment via PayPal (see Example 2-6). It will also generate a button on-screen. You must be sure to enable a PHP $_SESSION and set the variable $_SESSION['Payment_Amount'] that contains the amount of the purchase; otherwise, the generated code will not work properly.

Figure 2-8. Express Checkout Integration Wizard step 2

You now have the option to download expresscheckout.php (see Example 2-1), and paypalfunctions.php (see Example 2-2). You will need to modify the paypalfunction.php file with your API credentials. For instructions on creating those credentials, refer to Creating an API Signature. Additionally, after you have completed testing and are ready to go live, change $SandboxFlag='true' to $SandboxFlag='false'. This will change the endpoints to the live PayPal endpoint.

Note

For security reasons, I recommend putting your paypalfunctions.php file in a location accessible to expresscheckout.php and the other generated files, but outside your main webroot. This will help to prevent anyone from potentially obtaining your API credentials.

Step 3 generates code for your billing page that will be used if someone chooses PayPal from the billing options page instead of the main shopping cart page (see Figure 2-9).

Figure 2-9. Express Checkout Integration Wizard step 3

You must be sure to enable a PHP $_SESSION and set the variable $_SESSION['Payment_Amount']that contains the amount of the purchase; otherwise, the generated code will not work properly. You can copy the code from the box generated by the Wizard, and paste it into your billing handler (see Example 2-3).

Step 4 (Figure 2-10) generates code to add to your shipping page. You can copy the code from the box generated by the Wizard and paste it into your shipping handler (see Example 2-4). Step 5 (Figure 2-11) generates

Return Main Page Previous Page Next Page

®Online Book Reader