PayPal Adaptive Payments IMPLICIT Pay API

前端 未结 1 1178
灰色年华
灰色年华 2021-02-04 14:02

I am basically trying to use the PAY call of Adaptive Payments to programmatically and immediately send funds from my own paypal account to other accounts. According to the docu

相关标签:
1条回答
  • 2021-02-04 14:46

    Forget everything I said earlier. The problem isn't an inconsistency between Sandbox and Live either, but rather a wrong parameter for 'senderEmail'.

    Simply change:

    requestEnvelope.senderEmail=me@gmail.com&
    

    To:

    senderEmail=me@gmail.com&
    

    For example, the following returns a 'COMPLETED' implicit payment.

    <?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");
    
    ?>
    

    Pay response:
    responseEnvelope.timestamp: 2012-03-03T09%3A10%3A22.900-08%3A00
    responseEnvelope.ack: Success
    responseEnvelope.correlationId: 4bc5cfc4a7514
    responseEnvelope.build: 2486531
    payKey: AP-1XJ7636763429720C
    paymentExecStatus: COMPLETED

    0 讨论(0)
提交回复
热议问题