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

时间:2015-02-04 23:17:37

标签: php api paypal paypal-adaptive-payments chained-payments

我一直在尝试使用Paypal Adaptive Payments API实施拆分付款。我有一个简单的并行付款工作,但这显示了对买方的拆分付款。

基本上我是在卖会员资格。我们当地的协会应获得75%的资金,25%的资金转入理事机构。会员只应将总金额视为2015年会员资格,因此我开始研究链式付款。从表面上看,这似乎是一个非常简单的代码更改,但却导致了与单边付款有关的问题。

我在php中实现这个。

所以这是paypal发送方法

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

这是我的链式付款方式。此代码需要大量重构,但在并行付款时功能完全正常,只对当前代码进行了少量更改。

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

我在第一个标注时收到以下响应JSON。我认为这与帐户只是沙盒帐户而不是真实帐户有关,但如果帐户都必须是真实帐户,我打算如何在沙箱中测试?在这种情况下,用作API帐户的帐户是主要接收方。

{"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 个答案:

答案 0 :(得分:4)

我收到了相同的错误消息,我通过确保我在API调用中发送付款的2个电子邮件地址都是沙箱帐户来修复它。它们不是真正的电子邮件地址,但它们确实需要作为paypal帐户存在。 (之前我将它们发送到2个沙箱中不存在的实际PayPal帐户。)

根据错误消息判断,“未找到帐户。单方收件人不允许进行链式付款”,它只是找不到您的帐户,可能是因为它们不是沙盒帐户。

相关问题