简体   繁体   中英

Paypal Adaptive Payments (Chained) - Unilateral receiver not allowed in chained payment

I have been trying to implement split payments using the Paypal Adaptive Payments API. I have got a simple parallel payment to work, however this shows both split payments to the buyer.

Basically I am selling a membership. Our local association should get 75% of the funds and 25% is passed on to the governing body. The member should only see the total amount as being a 2015 membership so I started to look into chained payments instead. This on the face of it looks like a very simple code change but is causing me issues in relation to unilateral payments.

I am implementing this in php.

So here is the paypal send method

function PaypalSend($payment_details, $api_function){

    // initial endpoint that starts the transaction
    $paypalInitialEndpoint = 'https://svcs.sandbox.paypal.com/AdaptivePayments/';

    // set http headers
    $headers = array(
        'Connection: Close',
        'X-PAYPAL-SECURITY-USERID: testseller_api1.nipf.com',
        'X-PAYPAL-SECURITY-PASSWORD: 1381912839',
        'X-PAYPAL-SECURITY-SIGNATURE: AzykGe5AzfK.mJFMRzBwIcTap-LcAsmsP4AhYzk1Y-07mh-xPLc-goK3',
        'X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T',
        'X-PAYPAL-REQUEST-DATA-FORMAT: JSON',
        'X-PAYPAL-RESPONSE-DATA-FORMAT: JSON'
    );

    // setup curl request and http headers
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $paypalInitialEndpoint . $api_function);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payment_details));
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    if(!($res = curl_exec($ch)) ) 
    {   
        error_log(curl_error($ch));    
        curl_close($ch);    
        exit;
    }

    curl_close($ch);

    return json_decode($res, TRUE);     
}

And here is my chained payment method. This code needs a lot of refactoring but was fully functional with the parallel payments with only minor changes to this current code.

function sendChainedPayment(){

    $purchase_details_array = array(
        "actionType" => "PAY",
        "currencyCode" => "GBP",
        "feesPayer" => "PRIMARYRECEIVER",
        "memo" => "blah blah blah",
        "receiverList" => array(
            "receiver" => array(
                array(
                    "amount" => "30.00", 
                    "email" => "testseller@nipf.com",
                    "primary" => "true"
                ),
                array(
                    "amount" => "10.00", 
                    "email" => "testseller@gbpf.com",
                    "primary" => "false"
                )           
            )
        ),
        "returnUrl" => "http://localhost/membershipSuccess.php",
        "cancelUrl" => "http://localhost/membershipCancel.php",
        "requestEnvelope" => array(
            "errorLanguage" => "en_UK",
            "detailLevel" => "ReturnAll"
        )
    );

    $response = PaypalSend($purchase_details_array, "Pay");

    //echo json_encode($response) . "<br /><br />";

    $payKey = $response['payKey'];

    $payment_details = array(
        "requestEnvelope" => array(
            "errorLanguage" => "en_UK",
            "detailLevel" => "ReturnAll"
        ),
        "payKey" => $payKey,
        "receiverOptions" => array(
            array(
                "receiver" => array("email" => "testseller@nipf.com"),
                "invoiceData" => array(
                    "item" => array(
                        array(
                            "name" => "Membership 2015",
                            "price" => "30.00",
                            "identifier" => "Membership 2015: joe bloggs"
                        )
                    )                                               
                )
            ),
            array(
                "receiver" => array("email" => "testseller@gbpf.com"),
                "invoiceData" => array(
                    "item" => array(
                        array(
                            "name" => "Membership 2015 (Fee)",
                            "price" => "10.00",
                            "identifier" => "Membership 2015 (Fee): joe bloggs"
                        )
                    )                                               
                )
            )
        )
    );

    $response = PaypalSend($payment_details, "SetPaymentOptions");

    //echo json_encode($response) . "<br /><br />";

    $paypalCustomerUrl = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey=' . $payKey;

    echo $paypalCustomerUrl;

    //header('Location: ' . $paypalCustomerUrl);        
}

I am getting the following response JSON with the first callout. I think this is to do with the accounts being just sandbox accounts rather than real accounts but how am I meant to test this in the sandbox if the accounts all have to be real accounts? In this case the account used as the API account is the primary receiver.

{"responseEnvelope":{"timestamp":"2015-02-04T14:37:26.598-08:00","ack":"Failure","correlationId":"749bd1d709e76","build":"15089777"},"error":[{"errorId":"520009","domain":"PLATFORM","subdomain":"Application","severity":"Error","category":"Application","message":"Account Account not found. Unilateral receiver not allowed in chained payment is restricted","parameter":["Account not found. Unilateral receiver not allowed in chained payment"]}]}

I was getting the same error message, and I fixed it by making sure that the 2 email addresses that I was sending payments to in the API call were both sandbox accounts. They didn't exist as real email addresses, but they did need to exist as paypal accounts. (Previously I was sending them to 2 actual live paypal accounts that didn't exist in the sandbox).

Judging by the error message, " Account not found . Unilateral receiver not allowed in chained payment", it just can't find your account, probably because they are not sandbox accounts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM