PHP使用Paypal进行自适应支付:您的付款无法完成。请返回参与网站,然后重试

时间:2015-01-10 05:01:25

标签: php paypal paypal-sandbox paypal-adaptive-payments

我在最后一页完成交易后实现自适应付款的代码我得到的错误是您的付款无法完成。请返回参与网站,然后重试。这段代码有什么问题。这是我的代码。

enter code here
 <?php

 //turn php errors on
//ini_set("track_errors", true);

//set PayPal Endpoint to sandbox


$url = trim("https://svcs.sandbox.paypal.com/AdaptivePayments/Pay");




 $API_UserName = "s.patel_api1.sactp.ca"; //TODO
 $API_Password = "PA9YLDURHKTU52LH"; //TODO
 $API_Signature = "An5ns1Kso7MWUdW4ErQKJJJ4qi4-AOPwV4AdrC6q3hsN81pmNWMXn7f-"; //TODO
 $receiver_email = "rushi.mtech@gmail.com"; //TODO

 $amount = 25; //TODO

         //Default App ID for Sandbox    
     $API_AppID = "APP-80W284485P519543T";

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




              $bodyparams = array (   "requestEnvelope.errorLanguage" => "en_US",
              "actionType" => "PAY",
              "cancelUrl" => "http://localhost/success.php",
              "returnUrl" => "http://localhost/cancel.php",
              "currencyCode" => "CAD",
              "receiverList.receiver.email" => $receiver_email,
              "receiverList.receiver.amount" => $amount
);

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


try
{


      $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);

 //parse the ap key from the response

     $keyArray = explode("&", $response);

      foreach ($keyArray as $rVal){
     list($qKey, $qVal) = explode ("=", $rVal);
       $kArray[$qKey] = $qVal;
     }
     $rushi;
  //print the response to screen for testing purposes
   If ( $kArray["responseEnvelope.ack"] == "Success") {

     foreach ($kArray as $key =>$value){
 // echo $key . ": " .$value . "<br/>";
    if($key == "payKey")
     {
    $rushi = $value;
    echo $rushi;
    }  
    }
    }
     else {
          echo 'ERROR Code: ' .  $kArray["error(0).errorId"] . " <br/>";
         echo 'ERROR Message: ' .  urldecode($kArray["error(0).message"]) . " <br/>";
           }   

      } 


     catch(Exception $e) {
      echo "Message: ||" .$e->getMessage()."||";
       }


?>

另外我从here嵌入了html,请指导我

0 个答案:

没有答案