0

我正在尝试使用 PayPal AdaptivePayments API,并且正在尝试为 paypal IPN 设置 URL,该 URL 应该是“ipnNotificationUrl”,但我不知道在请求中添加它的位置。这是我的代码:

ini_set("track_errors", true);

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

/*
*******************************************************************
PayPal API Credentials
Replace <API_USERNAME> with your API Username
Replace <API_PASSWORD> with your API Password
Replace <API_SIGNATURE> with your Signature
*******************************************************************
*/

//PayPal API Credentials
$API_UserName = "sbapi_1287090601_biz_api1.paypal.com"; //TODO
$API_Password = "1287090610"; //TODO
$API_Signature = "ANFgtzcGWolmjcm5vfrf07xVQ6B9AsoDvVryVxEQqezY85hChCfdBMvY"; //TODO

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

$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" => "r_1_1266351681_biz@paypal.com", //TODO
                                            "receiverList.receiver(0).amount" => "20.0", //TODO
                                            "receiverList.receiver(1).email" => "r_2_1266352427_biz@paypal.com", //TODO
                                            "receiverList.receiver(1).amount" => "30.0" //TODO
                                            );

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

    //parse the ap key from the response
    $keyArray = explode("&", $response);

    foreach ($keyArray as $rVal){
        list($qKey, $qVal) = explode ("=", $rVal);
            $kArray[$qKey] = $qVal;
    }

    //set url to approve the transaction
    $payPalURL = "https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=" . $kArray["payKey"];

    //print the url to screen for testing purposes
    If ( $kArray["responseEnvelope.ack"] == "Success") {
        echo '<p><a href="' . $payPalURL . '" target="_blank">' . $payPalURL . '</a></p>';
     }
    else {
        echo 'ERROR Code: ' .  $kArray["error(0).errorId"] . " <br/>";
      echo 'ERROR Message: ' .  urldecode($kArray["error(0).message"]) . " <br/>";
    }

    /*
    //optional code to redirect to PP URL to approve payment
    If ( $kArray["responseEnvelope.ack"] == "Success") {

      header("Location:".  $payPalURL);
      exit;
       }
     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()."||";
  }

非常感谢!

4

1 回答 1

0

它应该在 $bodyparms 数组中:

 "returnUrl" => "http://www.paypal.com",
 "ipnNotificationUrl" => "http://www.baseem.com/ipnhandler.php",
于 2013-01-30T07:31:10.897 回答