Online Book Reader

Home Category

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

By Root 162 0
code for your order confirmation page. You can copy the code from the box generated by the Wizard and paste it into your order confirmation handler (see Example 2-5). Step 6 completes the Integration Wizard, as shown in Figure 2-12.

Figure 2-10. Express Checkout Integration Wizard step 4

Figure 2-11. Express Checkout Integration Wizard step 5

Figure 2-12. Express Checkout Integration Wizard step 6

Example 2-1. paypalfunctions.php

/********************************************

PayPal API Module

Defines all the global variables and the wrapper functions

********************************************/

$PROXY_HOST = '127.0.0.1';

$PROXY_PORT = '808';

$SandboxFlag = true;

//'------------------------------------

//' PayPal API Credentials

//' Replace with your API Username

//' Replace with your API Password

//' Replace with your Signature

//'------------------------------------

$API_UserName="mdbald_1287976381_biz_api1.michaelbalderas.com";

$API_Password="1287976406";

$API_Signature="APOxIKm-Fx0tSYmLLbuPFN42APwdAhhNTtvJ8YhTD2ALC9poKmbhBaf6";

// BN Code is only applicable for partners

$sBNCode = "PP-ECWizard";

/*

' Define the PayPal Redirect URLs.

' This is the URL where the buyer is first sent to authorize payment with their

' PayPal account. Change the URL depending on whether you are testing on the sandbox

' or the live PayPal site.

'

' For the sandbox, the URL is

' https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=

' For the live site, the URL is

' https://www.paypal.com/webscr&cmd=_express-checkout&token=

*/

if ($SandboxFlag == true)

{

$API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";

$PAYPAL_URL = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";

}

else

{

$API_Endpoint = "https://api-3t.paypal.com/nvp";

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

}

$USE_PROXY = false;

$version="64";

if (session_id() == "")

session_start();

/* An express checkout transaction starts with a token that identifies

to PayPal your transaction. In this example, when the script sees

a token, the script knows that the buyer has already authorized

payment through PayPal. If no token was found, the action is

to send the buyer to PayPal to first authorize payment.

*/

/*

'----------------------------------------------------------------------------------

' Purpose: Prepares the parameters for the SetExpressCheckout API Call.

' Inputs:

' paymentAmount: Total value of the shopping cart

' currencyCodeType: Currency code value the PayPal API

' paymentType: paymentType has to be one of the following values:

' Sale or Order or Authorization

' returnURL: The page where buyers return to after they are done

' with the payment review on PayPal

' cancelURL: The page where buyers return to when they cancel the

' payment review on PayPal

'----------------------------------------------------------------------------------

*/

function CallShortcutExpressCheckout( $paymentAmount, $currencyCodeType,

$paymentType, $returnURL, $cancelURL)

{

//--------------------------------------------------------------------------------

// Construct the parameter string that describes the SetExpressCheckout

// API call in the shortcut implementation

$nvpstr="&PAYMENTREQUEST_0_AMT=". $paymentAmount;

$nvpstr = $nvpstr . "&PAYMENTREQUEST_0_PAYMENTACTION=" . $paymentType;

$nvpstr = $nvpstr . "&RETURNURL=" . $returnURL;

$nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;

$nvpstr = $nvpstr . "&PAYMENTREQUEST_0_CURRENCYCODE=" . $currencyCodeType;

$_SESSION["currencyCodeType"] = $currencyCodeType;

$_SESSION["PaymentType"] = $paymentType;

//'-------------------------------------------------------------------------------

//' Make the API call to PayPal

//' If the API call succeeded, then redirect the buyer to PayPal to begin to

//' authorize payment.

//' If an error occurred, show the resulting errors.

//'--------------------------------------------------------------------------------

Return Main Page Previous Page Next Page

®Online Book Reader