PayPal APIs_ Up and Running_ A Developer's Guide - Michael Balderas [31]
Figure 4-10. Adaptive Payments Integration Wizard step 1
Figure 4-11. Adaptive Payments Integration Wizard step 2
Figure 4-12. Adaptive Payments Integration Wizard step 3
Figure 4-13. Adaptive Payments Integration Wizard step 4
Figure 4-14. Adaptive Payments Integration Wizard step 5
Example 4-1. paypalplatform.php
/********************************************
PayPal Adaptive Payments API Module
Defines all the global variables and the wrapper functions
********************************************/
$PROXY_HOST = '127.0.0.1';
$PROXY_PORT = '808';
$Env = "sandbox";
//------------------------------------
// PayPal API Credentials
// Replace // Replace // Replace //------------------------------------ $API_UserName = " $API_Password = " $API_Signature = " // AppID is preset for sandbox use // If your application goes live, you will be assigned a value for the live // environment by PayPal as part of the live onboarding process. $API_AppID = "APP-80W284485P519543T"; $API_Endpoint = ""; if ($Env == "sandbox") { $API_Endpoint = "https://svcs.sandbox.paypal.com/AdaptivePayments"; } else { $API_Endpoint = "https://svcs.paypal.com/AdaptivePayments"; } $USE_PROXY = false; if (session_id() == "") session_start(); function generateCharacter () { $possible = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); return $char; } function generateTrackingID () { $GUID = generateCharacter().generateCharacter().generateCharacter(); $GUID .=generateCharacter().generateCharacter().generateCharacter(); $GUID .=generateCharacter().generateCharacter().generateCharacter(); return $GUID; } /* '------------------------------------------------------------------------------- ' Purpose: Prepares the parameters for the Refund API Call. ' The API credentials used in a Pay call can make the Refund call ' against a payKey, or a tracking id, or to specific receivers of a payKey or ' a tracking id that resulted from the Pay call. ' ' A receiver itself with its own API credentials can make a Refund call against ' the transactionId corresponding to their transaction. ' The API credentials used in a Pay call cannot use transactionId to issue a refund ' for a transaction for which they themselves were not the receiver. ' ' If you do specify specific receivers, you must provide the amounts as well. ' If you specify a transactionId, then only the receiver of that transactionId ' is affected. Therefore the receiverEmailArray and receiverAmountArray should ' have 1 entry each if you do want to give a partial refund. ' Inputs: ' ' Conditionally Required: ' One of the following: payKey or trackingId or trasactionId or ' (payKey and receiverEmailArray and receiverAmountArray) or ' (trackingId and receiverEmailArray and receiverAmountArray) ' or (transactionId and receiverEmailArray ' and receiverAmountArray) ' Returns: ' The NVP Collection object of the Refund call response. '------------------------------------------------------------------------------------ */ function CallRefund( $payKey, $transactionId, $trackingId, $receiverEmailArray, $receiverAmountArray ) { /* Gather the information to make the Refund call. The variable nvpstr holds the name-value pairs. */ $nvpstr = ""; // conditionally required fields if ("" != $payKey) { $nvpstr = "payKey=" . urlencode($payKey); if (0 != count($receiverEmailArray)) { reset($receiverEmailArray); while (list($key, $value) = each($receiverEmailArray)) { if ("" != $value) { $nvpstr .= "&receiverList.receiver(" . $key . ").email=" . urlencode($value); } } } if (0 != count($receiverAmountArray)) { reset($receiverAmountArray); while (list($key, $value) = each($receiverAmountArray)) { if ("" != $value) { $nvpstr