dta25920 2015-02-04 23:17
浏览 93

Paypal自适应付款(已链接) - 单边收款人不允许进行链式付款

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"]}]}
  • 写回答

1条回答 默认 最新

  • dongxin8392 2015-03-06 21:09
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法