Online Book Reader

Home Category

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

By Root 186 0
details

//' of the authorization, including any of the buyer's shipping information.

//' Remember, the authorization is not a completed transaction

//' at this stage - the buyer still needs an additional step to finalize

//' the transaction.

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

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

//' Build a second API request to PayPal, using the token as the

//' ID to get the details on the payment authorization

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

$nvpstr="&TOKEN=" . $token;

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

//' Make the API call and store the results in an array.

//' If the call was a success, show the authorization details, and provide

//' an action to complete the payment.

//' If failed, show the error.

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

$resArray=hash_call("GetExpressCheckoutDetails",$nvpstr);

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

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

{

$_SESSION['payer_id'] = $resArray['PAYERID'];

}

return $resArray;

}

/*

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

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

'

' Inputs:

' sBNCode: The BN code used by PayPal to track the transactions

' from a given shopping cart.

' Returns:

' The NVP Collection object of the GetExpressCheckoutDetails Call Response.

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

*/

function ConfirmPayment( $FinalPaymentAmt )

{

/* Gather the information to make the final call to

finalize the PayPal payment. The variable nvpstr

holds the name-value pairs.

*/

//Format the other parameters that were stored in the session from the previous calls

$token = urlencode($_SESSION['TOKEN']);

$paymentType = urlencode($_SESSION['PaymentType']);

$currencyCodeType = urlencode($_SESSION['currencyCodeType']);

$payerID = urlencode($_SESSION['payer_id']);

$serverName = urlencode($_SERVER['SERVER_NAME']);

$nvpstr = '&TOKEN=' . $token . '&PAYERID=' . $payerID .

'&PAYMENTREQUEST_0_PAYMENTACTION='.

$paymentType . '&PAYMENTREQUEST_0_AMT=' . $FinalPaymentAmt .

'&PAYMENTREQUEST_0_CURRENCYCODE=' . $currencyCodeType .'&IPADDRESS='.

$serverName;

/* Make the call to PayPal to finalize payment

If an error occurred, show the resulting errors.

*/

$resArray=hash_call("DoExpressCheckoutPayment",$nvpstr);

/* Display the API response back to the browser.

If the response from PayPal was a success, display the response parameters.

If the response was an error, display the errors received using APIError.php.

*/

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

return $resArray;

}

/*

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

' Purpose: This function makes a DoDirectPayment API call

'

' Inputs:

' paymentType: paymentType has to be one of the following values: Sale or Order or

' Authorization

' paymentAmount: Total value of the shopping cart

' currencyCode: Currency code value in the PayPal API

' firstName: first name as it appears on credit card

' lastName: Last name as it appears on credit card

' street: Buyer's street address line as it appears on credit card

' city: Buyer's city

' state: Buyer's state

' countryCode: Buyer's country code

' zip: Buyer's zip

' creditCardType: Buyer's credit card type (e.g., Visa, MasterCard ... )

' creditCardNumber: Buyer's credit card number without any spaces, dashes, or any other

' characters

' expDate: Credit card expiration date

' cvv2: Card Verification Value

'

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

'

' Returns:

' The NVP Collection object of the DoDirectPayment Call Response.

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

*/

function DirectPayment( $paymentType,

Return Main Page Previous Page Next Page

®Online Book Reader