2012-02-19 14 views
3

私と他のプログラマーは数日間喜んでいませんでした。現時点で私たちが達成しようとしているのは、PayPalからの返答を受け取ることだけです。残念ながら、PayPal APIはひどく書類に書かれています。ここでPHP - PayPalの統合 - 複数のアカウントへの支払い

は、私たちのコードです:

<?php 
    class Paypal { 
      /** 
      * Last error message(s) 
      * @var array 
      */ 
      protected $_errors = array(); 

      /** 
      * API Credentials 
      * Use the correct credentials for the environment in use (Live/Sandbox) 
      * @var array 
      */ 
      protected $_credentials = array(
        'USER' => '*************************', 
        'PWD' => '****************', 
        'SIGNATURE' => '************************************************', 
      ); 

      /** 
      * API endpoint 
      * Live - https://api-3t.paypal.com/nvp 
      * Sandbox - https://api-3t.sandbox.paypal.com/nvp 
      * @var string 
      */ 
      protected $_endPoint = 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay'; 

      /** 
      * API Version 
      * @var string 
      */ 
      protected $_version = '74.0'; 


      public function newstartpayment() { 
        //set PayPal Endpoint to sandbox 
        $url = trim("https://svcs.sandbox.paypal.com/AdaptivePayments/Pay"); 

      //PayPal API Credentials 
      $API_UserName = $_credentials['USER']; 
      $API_Password = $_credentials['PWD']; 
      $API_Signature = $_credentials['SIGNATURE']; 

      //Default App ID for Sandbox  
      $API_AppID = "******************"; 

      $API_RequestFormat = "NV"; 
      $API_ResponseFormat = "NV"; 

      //Create request payload with minimum required parameters 
      $bodyparams = array (
        "requestEnvelope.errorLanguage" => "en_US", 
        "actionType" => "PAY", 
        "currencyCode" => "USD", 
        "cancelUrl" => "http://www.paypal.com", 
        "returnUrl" => "http://www.paypal.com", 
        "receiverList.receiver(0).email" => "************@paypal.com", //TODO 
        "receiverList.receiver(0).amount" => "40", //TODO 
        "receiverList.receiver(0).primary" => "true", //TODO 
        "receiverList.receiver(1).email" => "****************@paypal.com", //TODO 
        "receiverList.receiver(1).amount" => "30", //TODO 
        "receiverList.receiver(1).primary" => "false", //TODO 
        'USER' => '************************', 
        'PWD' => '***********', 
        'SIGNATURE' => '*************************************' 
      ); 

      // convert payload array into url encoded query string 
      $body_data = http_build_query($bodyparams, "", chr(38)); 

      try 
      { 
        //create request and add headers 
        $params = array("http" => array( 
        "method" => "POST", 
        "content" => $body_data, 
        "header" => "X-PAYPAL-SECURITY-USERID: " . $API_UserName . "\r\n" . 
        "X-PAYPAL-SECURITY-SIGNATURE: " . $API_Signature . "\r\n" . 
        "X-PAYPAL-SECURITY-PASSWORD: " . $API_Password . "\r\n" . 
        "X-PAYPAL-APPLICATION-ID: " . $API_AppID . "\r\n" . 
        "X-PAYPAL-REQUEST-DATA-FORMAT: " . $API_RequestFormat . "\r\n" . 
        "X-PAYPAL-RESPONSE-DATA-FORMAT: " . $API_ResponseFormat . "\r\n" 
        )); 

        //create stream context 
        $ctx = stream_context_create($params); 

        //open the stream and send request 
        $fp = @fopen($url, "r", false, $ctx); 

        //get response 
        $response = stream_get_contents($fp); 

        //check to see if stream is open 
        if ($response === false) { 
          throw new Exception("php error message = " . $php_errormsg); 
        } 

        //close the stream 
        fclose($fp); 

        return $response; 
      } 
        catch (Exception $e) { 
          error_log($e->getMessage()); 
          print_r($e); 
          return false; 
        } 
    } 

    $paypal = new Paypal(); 

    ?> 

[OK]を、このコードが実行されると今、私たちは次のエラーを取得する:

Paypal returned: 2012-02-19T15:07:01.883-08:00Failureff3b99b56fcb72486531520003PLATFORMApplicationErrorApplicationAuthentication failed. API credentials are incorrect.

私たちはロープの終わりにある、してくださいために神の助けの愛..

+0

「APIの資格情報が間違っています。」というエラーは明らかです。 –

+1

API資格情報が完全にチェックされています。 –

+0

ライブアカウントの資格情報ですか? Sandboxエンドポイントに対しては機能しません。その逆もありません。 https://developer.paypal.com/>テストアカウント>を事前に設定してテスト販売アカウントを取得し、代わりにこれらのAPI認証情報を使用してください。 – Robert

答えて

0

あなたはpypalサンドボックスまたはライブpaypal APIクレデンシャルを使用しています。

+0

サンドボックス私たちはサンドボックスでテストしています。アカウントはサンドボックスです –

関連する問題