示例#1
0
<?php

// Include required library files.
require_once '../includes/config.php';
require_once '../includes/paypal.class.php';
require_once '../includes/paypal.adaptive.class.php';
// Create PayPal object.
$PayPalConfig = array('Sandbox' => $sandbox, 'DeveloperAccountEmail' => $developer_account_email, 'ApplicationID' => $application_id, 'DeviceID' => $device_id, 'IPAddress' => $_SERVER['REMOTE_ADDR'], 'APIUsername' => $api_username, 'APIPassword' => $api_password, 'APISignature' => $api_signature, 'APISubject' => $api_subject);
$PayPal = new PayPal_Adaptive($PayPalConfig);
// Prepare request arrays
$CancelPreapprovalFields = array('PreapprovalKey' => '');
$PayPalRequestData = array('CancelPreapprovalFields' => $CancelPreapprovalFields);
// Pass data into class for processing with PayPal and load the response array into $PayPalResult
$PayPalResult = $PayPal->CancelPreapproval($PayPalRequestData);
// Write the contents of the response array to the screen for demo purposes.
echo '<pre />';
print_r($PayPalResult);
 function cancel_preapprovals($sel_backing)
 {
     // $sel_backing is preapproved backing record to be cancelled
     // use old sdk
     global $PayPalConfig;
     $PayPal = new PayPal_Adaptive($PayPalConfig);
     $DataArray = array();
     $CancelPreapprovalFields = array('PreapprovalKey' => $sel_backing['preapproval_key']);
     $DataArray['CancelPreapprovalFields'] = $CancelPreapprovalFields;
     $PayPalResult = $PayPal->CancelPreapproval($DataArray);
     // $PayPalResult array(
     //	'Errors' => $Errors,
     //	'Ack' => $Ack,
     //	'Build' => $Build,
     //	'CorrelationID' => $CorrelationID,
     //	'Timestamp' => $Timestamp,
     //	'XMLRequest' => $XMLRequest,
     //	'XMLResponse' => $XMLResponse
     // }
     wrtlog("DEBUG in cancel_preapprovals PayPalResult: " . print_r($PayPalResult, true));
     if (strtolower($PayPalResult['Ack']) == 'success') {
         $this->cancel_preapprovals_backer_dbupdate($sel_backing, $PayPalResult);
         $this->cancel_preapprovals_backer_mail($sel_backing, $PayPalResult);
     } else {
         wrtlog("WARNING: project #{$sel_backing['projectId']} backing #{$sel_backing['backingId']} could not be cancelled: " . print_r($PayPalResult, true));
         $this->cancel_preapprovals_backer_dbupdate($sel_backing, $PayPalResult);
         // still mark it cancelled
         // at this point - we are silent on outcome to the backer... tbd
     }
 }