2011-03-29 143 views
2

我試圖使用PayPal的PHP SDK及其Adaptive Payments API來創建後端腳本,以自動完成我們網站附屬公司的付款。我已將以下常量設置爲我通過paypal給出的相應值:PayPal自適應付款錯誤:API憑據不正確。錯誤代碼:520003

define('API_AUTHENTICATION_MODE','3token'); 
define('API_USERNAME', 'xxx'); 
define('API_PASSWORD', 'xxx'); 
define('API_SIGNATURE', 'xxx'); 
define('PAYPAL_REDIRECT_URL', 'https://www.paypal.com/webscr&cmd=_ap-payment&paykey='); 
define('DEVELOPER_PORTAL', 'https://developer.paypal.com'); 
define('DEVICE_ID', 'PayPal_Platform_PHP_SDK'); 
define('APPLICATION_ID', 'xxx'); //(Using correct APP ID given by paypal after registering application 

其中'xxx'等於正確值。

有什麼我失蹤了嗎?每次我試圖發送一個支付與我們的帳戶,我得到錯誤520003.

這是我的職責嘗試發送付款:

function ImplicitPayment() { 
    global $Accounts1; 
    global $Accounts; 
    global $Affiliates; 
    global $fault; 
    global $mAmount; 
    global $mCompanyName; 
    global $mEditAffiliate_ID; 
    global $mEmailAffiliate; 
    global $mLocalFlag; 
    global $mPayPalEmailAccount; 
    global $mToday; 
    global $mPayPalTestEmail; 
    global $mLocalFlag; 


    if (!isset($Affiliates)) { 
     $Affiliates = new DB('affiliates'); 
    } 

    $Affiliates->select('SELECT * FROM affiliates 
               LEFT JOIN accounts 
               ON accounts.EMAIL_NO = affiliates.EMAIL_NO 
               WHERE affiliates.AFFILIATE = %d 
                AND affiliates.ACTIVE = 1 
                AND affiliates.SHUTOFF != 1 
                AND affiliates.DELETED != 1 
                AND accounts.ACTIVE = 1 
                AND accounts.SHUTOFF != 1;', $mEditAffiliate_ID); 
    $Affiliates->getNext(); 

    if (FALSE) { 
     if (date('d') < 10) { 
      //make commission payment late (at beginning of month 2) 
      $mAmount = $Affiliates->d->COMM_DUE - $Affiliates->d->COMM - $Affiliates->d->COMM1; 
     } else { 
      $mAmount = $Affiliates->d->COMM_DUE - $Affiliates->d->COMM; 
     } 
    } 


    $mAmount = $_REQUEST['mAmount']; 

    $mEmailAffiliate = $Affiliates->d->EMAIL; 

    include_once(SCRIPTPATH . '/admin/paypal_adaptive_payments/AdaptivePayments.php'); 
    include_once(SCRIPTPATH . '/admin/paypal_adaptive_payments/web_constants.php'); 

    try { 

    /* The servername and serverport tells PayPal where the buyer 
     should be directed back to after authorizing payment. 
     In this case, its the local webserver that is running this script 
     Using the servername and serverport, the return URL is the first 
     portion of the URL that buyers will return to after authorizing payment    */ 

     $serverName = $_SERVER['SERVER_NAME']; 
     $serverPort = $_SERVER['SERVER_PORT']; 
     $url=dirname('http://'.$serverName.':'.$serverPort.$_SERVER['REQUEST_URI']); 

     /* The returnURL is the location where buyers return when a 
     payment has been succesfully authorized. 
     The cancelURL is the location buyers are sent to when they hit the 
     cancel button during authorization of payment during the PayPal flow     */ 

     $returnURL = 'http://www.realadventures.com/'; //$_SERVER["DOCUMENT_ROOT"] . $_SERVER['PHP_SELF']; 
     $cancelURL = 'http://www.realadventures.com/'; //$_SERVER["DOCUMENT_ROOT"] . $_SERVER['PHP_SELF']; 
     $currencyCode = 'USD'; 
     $email = $mPayPalEmailAccount; //$_REQUEST["email"]; 
     $preapprovalKey = "";  // No preapprovalKey for an implicit use case 
     $requested = ''; 
     $receiverEmail = ''; 
     $count = 1; //count($_POST['receiveremail']); 

     $payRequest = new PayRequest(); 
     $payRequest->actionType = "PAY"; 
     $payRequest->cancelUrl = $cancelURL; 
     $payRequest->returnUrl = $returnURL; 
     $payRequest->clientDetails = new ClientDetailsType(); 
     $payRequest->clientDetails->applicationId = APPLICATION_ID; 
     $payRequest->clientDetails->deviceId = DEVICE_ID; 
     $payRequest->clientDetails->ipAddress = "127.0.0.1"; 
     $payRequest->currencyCode = $currencyCode; 
     $payRequest->senderEmail = $email; 
     $payRequest->requestEnvelope = new RequestEnvelope(); 
     $payRequest->requestEnvelope->errorLanguage = "en_US"; 

     if ($preapprovalKey != "") { 
      $payRequest->preapprovalKey = $preapprovalKey; 
     } 

     $receiver1 = new receiver(); 
     $receiver1->email = $mEmailAffiliate; //$_POST['receiveremail'][0]; 
     $receiver1->amount = $mAmount; 

     $payRequest->receiverList = new ReceiverList(); 
     $payRequest->receiverList = array($receiver1); 

     /* Make the call to PayPal to get the Pay token 
     If the API call succeded, then redirect the buyer to PayPal 
     to begin to authorize payment. If an error occured, show the 
     resulting errors */ 

     $ap = new AdaptivePayments(); 
     $response=$ap->Pay($payRequest); 

     if (strtoupper($ap->isSuccess) == 'FAILURE') { 
      $_SESSION['FAULTMSG'] = $ap->getLastError(); 
      DisplayErrors(); 

      //$location = "APIError.php"; 
      //header("Location: $location"); 
     } else { 
      $_SESSION['payKey'] = $response->payKey; 
      if ($response->paymentExecStatus == "COMPLETED") { 
       //DisplayDetails(); 
       //$location = "PaymentDetails.php"; 
       //header("Location: $location"); 
      } else { 

       $token = $response->payKey; 
       $payPalURL = PAYPAL_REDIRECT_URL.'_ap-payment&paykey='.$token; 

       DisplayErrors(); 

       //header("Location: ".$payPalURL); 
      } 
     } 

    } catch(Exception $ex) { 

     $fault = new FaultMessage(); 
     $errorData = new ErrorData(); 
     $errorData->errorId = $ex->getFile() ; 
      $errorData->message = $ex->getMessage(); 
      $fault->error = $errorData; 
     $_SESSION['FAULTMSG']=$fault; 

     DisplayErrors(); 

     //$location = SCRIPTPATH . "/admin/APIError.php"; 
     //header("Location: $location"); 

    } 

} 

編輯: 此外,$ mPayPalEmailAccount被設置爲相同的值作爲API_USERNAME

回答