Online Book Reader

Home Category

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

By Root 187 0
preapproval, set the

// preapprovalKey here

$reverseAllParallelPaymentsOnError = ""; // Do not specify for basic payment

$trackingId = generateTrackingID(); // generateTrackingID function is

// found in paypalplatform.php

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

// Make the Pay API call

//

// The CallPay function is defined in the paypalplatform.php file,

// which is included at the top of this file.

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

$resArray = CallPay ($actionType, $cancelUrl, $returnUrl, $currencyCode,

$receiverEmailArray, $receiverAmountArray, $receiverPrimaryArray,

$receiverInvoiceIdArray, $feesPayer, $ipnNotificationUrl, $memo,

$pin, $preapprovalKey, $reverseAllParallelPaymentsOnError,

$senderEmail, $trackingId

);

$ack = strtoupper($resArray["responseEnvelope.ack"]);

if($ack=="SUCCESS")

{

if ("" == $preapprovalKey)

{

// redirect for web approval flow

$cmd = "cmd=_ap-payment&paykey=" . urldecode($resArray["payKey"]);

RedirectToPayPal ( $cmd );

}

else

{

// payKey is the key that you can use to identify the payment resulting

// from the Pay call.

$payKey = urldecode($resArray["payKey"]);

// paymentExecStatus is the status of the payment

$paymentExecStatus = urldecode($resArray["paymentExecStatus"]);

}

}

else

{

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

//error information returned by PayPal.

//TODO - There can be more than 1 error, so check for "error(1).errorId",

// then "error(2).errorId", and so on until you find no more errors.

$ErrorCode = urldecode($resArray["error(0).errorId"]);

$ErrorMsg = urldecode($resArray["error(0).message"]);

$ErrorDomain = urldecode($resArray["error(0).domain"]);

$ErrorSeverity = urldecode($resArray["error(0).severity"]);

$ErrorCategory = urldecode($resArray["error(0).category"]);

echo "Preapproval API call failed. ";

echo "Detailed Error Message: " . $ErrorMsg;

echo "Error Code: " . $ErrorCode;

echo "Error Severity: " . $ErrorSeverity;

echo "Error Domain: " . $ErrorDomain;

echo "Error Category: " . $ErrorCategory;

}

?>

Example 4-5. parallelpayment.php

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

// When you integrate this code,

// look for TODO as an indication

// that you may need to provide a value or take

// action before executing this code.

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

require_once ("paypalplatform.php");

// ==================================

// PayPal Platform Parallel Payment Module

// ==================================

// Request specific required fields

$actionType = "PAY";

$cancelUrl = "https://mycancelurl"; // TODO - If you are not executing the Pay call

// for a preapproval, then you must set a valid

// cancelUrl for the web approval flow that

// immediately follows this Pay call

$returnUrl = "https://myreturnurl"; // TODO - If you are not executing the Pay call

// for a preapproval, then you must set a valid

// returnUrl for the web approval flow that

// immediately follows this Pay call

$currencyCode = "USD";

// A parallel payment can be made among two to six receivers

// TODO - Specify the receiver emails

// Remove or set to an empty string the array entries for receivers that you

// do not have

$receiverEmailArray = array(

'receiver0email',

'receiver1email',

'receiver2email',

'receiver3email',

'receiver4email',

'receiver5email'

);

// TODO - Specify the receiver amounts as the amount of money, for example, '5' or '5.55'

// Remove or set to an empty string the array entries for receivers that you

// do not have

$receiverAmountArray = array(

'receiver0amount',

'receiver1amount',

'receiver2amount',

'receiver3amount',

'receiver4amount',

'receiver5amount'

);

// For parallel payment, no primary indicators are needed, so set empty array.

$receiverPrimaryArray = array();

// TODO - Set invoiceId to uniquely identify the transaction associated with

// each receiver

// Set the array entries with value for receivers that you have

// Each of the array values must

Return Main Page Previous Page Next Page

®Online Book Reader