PayPal自适应支付IMPLICIT Pay API

9
我基本上想使用Adaptive Payments的PAY调用程序,从我的PayPal帐户立即编程并发送资金到其他帐户。根据文档,只要我指定senderEmail(我的PayPal地址,用于设置Adaptive Payments),这应该完全可行。
然而,当我进行调用时,结果总是“CREATED”而不是“COMPLETED”。 Created表示系统仍然希望我手动登录PayPal并批准付款。我真的需要这些支付在当场自动发生。谢谢您的帮助。
以下是我的请求字符串:
currencyCode=USD&
returnUrl=http%3A%2F%2Fwww.website.com%2F&
actionType=PAY&
cancelUrl=http%3A%2F%2Fwww.website.com%2F&
receiverList.receiver%280%29.email=receiver%40gmail.com&
receiverList.receiver%280%29.amount=1.00&
requestEnvelope.senderEmail=me%40gmail.com&
clientDetails.deviceId=mydevice&
clientDetails.ipAddress=127.0.0.1&
clientDetails.applicationId=APP-ZZZZZZZZZZZZZ&
requestEnvelope.errorLanguage=en_US&
memo=memo&
feesPayer=EACHRECEIVER&
ipnNotificationUrl=http%3A%2F%2Fwww.website.com%2Fpay.php

以下为PayPal的响应:

[responseEnvelope.timestamp] => 2012-03-01T19:09:57.290-08:00
[responseEnvelope.ack] => Success
[responseEnvelope.correlationId] => 71efd416a2100
[responseEnvelope.build] => 2486531
[payKey] => AP-ZZZZZZZZZZZZZZZ
[paymentExecStatus] => CREATED

在上述情况下,PayPal是否要求您再次输入密码? - Sripaul
1个回答

21

忘记我之前说的一切。问题并不是沙盒和生产环境之间的不一致性,而是“senderEmail”参数错误。

只需更改:

requestEnvelope.senderEmail=me@gmail.com&

收件人:

senderEmail=me@gmail.com&
例如,以下代码返回一个"已完成(COMPLETED)"的隐式支付。
<?php

function AdaptiveCall($bodyparams, $method, $payKey) {

try
{

    $body_data = http_build_query($bodyparams, "", chr(38));
    $url = trim("https://svcs.sandbox.paypal.com/AdaptivePayments/".$method."");
    $params = array("http" => array( 
                        "method" => "POST",
                        "content" => $body_data,
                            "header" => "X-PAYPAL-SECURITY-USERID: xxxxxxxxx\r\n" .
                                        "X-PAYPAL-SECURITY-SIGNATURE: xxxxxxxxxxx\r\n" .
                                        "X-PAYPAL-SECURITY-PASSWORD: xxxxxxx\r\n" .
                                        "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T\r\n" .
                                        "X-PAYPAL-REQUEST-DATA-FORMAT: NV\r\n" .
                                        "X-PAYPAL-RESPONSE-DATA-FORMAT: NV\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;
    }

 //print the response to screen for testing purposes
    If ( $kArray["responseEnvelope.ack"] == "Success") {
        echo "<strong>".$method ."</strong><br>";
         foreach ($kArray as $key =>$value){
        echo $key . ": " .$value . "<br/>";

    }
    // Return payKey
    global $payKey;
    if(!empty($kArray['payKey'])) { $payKey = $kArray['payKey']; return($payKey); }

     }
    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()."||";
  }
}



//Create Pay body
$bodyparams = array (   "requestEnvelope.errorLanguage" => "en_US",
                        'actionType' => 'PAY',
                        'currencyCode' => 'USD',
                        'receiverList.receiver(0).email' => 'another_account@domain.tld',
                        'receiverList.receiver(0).amount' => '1.00',
                        'senderEmail' => 'xxxxxxxxx',
                        'memo' => 'Test memo',
                        'ipnNotificationUrl' => 'http://xxxxxxxx',
                        'cancelUrl' => 'http://xxxxxxxxx',
                        'returnUrl' => 'http://xxxxxxxxxx'
                    );

                    // Call Pay API
AdaptiveCall($bodyparams, "Pay");

?>

支付响应:
responseEnvelope.timestamp: 2012-03-03T09%3A10%3A22.900-08%3A00
responseEnvelope.ack: 成功
responseEnvelope.correlationId: 4bc5cfc4a7514
responseEnvelope.build: 2486531
payKey: AP-1XJ7636763429720C
paymentExecStatus: 已完成


17
我能为你买一杯咖啡或其他什么吗?=) - Authman Apatira
我正在做基本相同的事情。但是我不知道如何处理returnUrlcancelUrl。如果没有Webflow,我们能跳过它们吗? - Haralan Dobrev
根据PayPal的说法,“它始终是必需的,但仅用于需要批准的付款(显式付款)”,因此您可以使用一些虚假的URL。 - Matanya
我按照你说的做了,但是没有用。http://stackoverflow.com/questions/37329755/implicit-paypal-payment-pay-you-do-not-have-permission-to-execute-this-payme - Dario Rusignuolo
何时调用AdaptiveCall函数?请帮忙。 - san
谢谢!它对我有效,但不适用于fopen,使用curl对我有效。但它确实帮了我很多,非常感谢。 - Abhishek Pandey

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接