Online Book Reader

Home Category

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

By Root 160 0

$city = "<>"; //' Set this to the customer's city that was entered on

// the Billing page.

$state = "<>"; //' Set this to the customer's state that was entered

// on the Billing page.

$zip = "<>"; //' Set this to the zip code of the customer's address that was

// entered on the Billing page.

$countryCode = "<>"; //' Set this to the PayPal code for the

//Country of the customer's address that was entered on the Billing page.

$currencyCode = "<>"; //' Set this to the PayPal code for

// the Currency used by the customer.

/*

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

' Calls the DoDirectPayment API call

'

' The DirectPayment function is defined in PayPalFunctions.php, included at the top of

' this file.

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

*/

$resArray = DirectPayment ( $paymentType, $paymentAmount, $creditCardType,

$creditCardNumber, $expDate, $cvv2, $firstName, $lastName, $street,

$city, $state, $zip, $countryCode, $currencyCode );

$ack = strtoupper($resArray["ACK"]);

if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")

{

//Getting transaction ID from API response.

$TransactionID = urldecode9$resArray["TRANSACTIONID"]);

echo "Your payment has been successfully processed";

}

else

{

//Display a user-friendly Error on the page using any of the following error information

//returned by PayPal.

$ErrorCode = urldecode($resArray["L_ERRORCODE0"]);

$ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);

$ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);

$ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);

echo "Direct credit card payment API call failed. ";

echo "Detailed Error Message: " . $ErrorLongMsg;

echo "Short Error Message: " . $ErrorShortMsg;

echo "Error Code: " . $ErrorCode;

echo "Error Severity Code: " . $ErrorSeverityCode;

}

}

?>

Example 2-4. shipping.php

/*==================================================================

PayPal Express Checkout Call

===================================================================

*/

// Check to see whether the Request object contains a variable named 'token'.

$token = "";

if (isset($_REQUEST['token']))

{

$token = $_REQUEST['token'];

}

// If the Request object contains the variable 'token', then it means that the

// user is coming from the PayPal site.

if ( $token != "" )

{

require_once ("paypalfunctions.php");

/*

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

' Calls the GetExpressCheckoutDetails API call

'

' The GetShippingDetails function is defined in PayPalFunctions.jsp,

' included at the top of this file.

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

*/

$resArray = GetShippingDetails( $token );

$ack = strtoupper($resArray["ACK"]);

if( $ack == "SUCCESS" || $ack == "SUCESSWITHWARNING")

{

/*

' The information that is returned by the GetExpressCheckoutDetails call should be

' integrated by the partner into his Order Review page.

*/

$email = $resArray["EMAIL"]; // ' Email address of payer.

$payerId = $resArray["PAYERID"]; // ' Unique PayPal customer account

// identification number.

$payerStatus = $resArray["PAYERSTATUS"]; // ' Status of payer.

// Limited to 10 single-byte alphabetic

// characters.

$salutation = $resArray["SALUTATION"]; // ' Payer's salutation.

$firstName = $resArray["FIRSTNAME"]; // ' Payer's first name.

$middleName = $resArray["MIDDLENAME"]; // ' Payer's middle name.

$lastName = $resArray["LASTNAME"]; // ' Payer's last name.

$suffix = $resArray["SUFFIX"]; // ' Payer's suffix.

$cntryCode = $resArray["COUNTRYCODE"]; // ' Payer's country of residence in the form of

// ISO standard 3166 two-character country codes.

$business = $resArray["BUSINESS"]; // ' Payer's business name.

$shipToName = $resArray["SHIPTONAME"]; // ' Person's name associated with this address.

$shipToStreet = $resArray["SHIPTOSTREET"]; // ' First street address.

$shipToStreet2 = $resArray["SHIPTOSTREET2"]; // ' Second street address.

$shipToCity = $resArray["SHIPTOCITY"]; // ' Name of

Return Main Page Previous Page Next Page

®Online Book Reader