Paypal Adaptivepayments问题时,从cURL请求



我在php中创建了一个简单的web应用程序,它使用paypal的adaptivePayments/Pay Api,我使用POSTMAN进行了一些测试,一切工作正常,我发出初始请求并获得我的payKey,也使用此payKey我可以使用/adaptivePayments/PaymentDetails Api检查交易的状态,问题是当我尝试通过php代码发出请求时:

    $endpoint = 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay';
    $payload['actionType']                       = "PAY";
    $payload['clientDetails']['applicationId']   = "APP-80W284485P519543T";
    $payload['clientDetails']['ipAddress']       = "xxx.xxx.xxx.xxx";
    $payload['currencyCode']                     = "USD";
    $payload['feesPayer']                        = "EACHRECEIVER";
    $payload['memo']                             = "Transaction";
    $payload['receiverList']['receiver']         = $receivers;
    $payload['requestEnvelope']['errorLanguage'] = "en_US";
    $payload['returnUrl']                        = "URL";
    $payload['cancelUrl']                        = "URL";
    $json = json_encode($payload);
    $ch = curl_init($endpoint);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'X-PAYPAL-SECURITY-USERID: ACCOUNT',
        'X-PAYPAL-SECURITY-PASSWORD: PASSWORD',
        'X-PAYPAL-SECURITY-SIGNATURE: SIGNATURE',
        'X-PAYPAL-REQUEST-DATA-FORMAT: JSON',
        'X-PAYPAL-RESPONSE-DATA-FORMAT: JSON',
        'X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T',
        'Content-Type: application/json',
        'Content-Length: ' . strlen($json)
    ));
    $result = curl_exec($ch);

$receivers是一个PHP数组,它包含有关电子邮件和付款金额的信息,类似如下:

Array
(
    [0] => Array
        (
            [amount] => 19.8
            [email] => client2-ubs@gmail.com
            [primary] => 
        )

    [1] => Array
        (
            [amount] => 20.7
            [email] => client1-ubs@gmail.com
            [primary] => 
        )

    [2] => Array
        (
            [amount] => 45
            [email] => store-ubs@gmail.com
            [primary] => 1
        )
    )

我没有得到任何错误,我甚至得到了payKey,我用它来创建html按钮,这样用户就可以支付他的商品,问题是当我检查支付状态/AdaptivePayments/PaymentDetails,我得到:

{
    "responseEnvelope": {
        "timestamp": "2015-08-06T23:59:23.075-07:00",
        "ack": "Success",
        "correlationId": "bab22ca0bd887",
        "build": "17603431"
    },
    "cancelUrl": "https://23410a33.ngrok.com/universal-bank-of-souls/",
    "currencyCode": "USD",
    "paymentInfoList": null,
    "returnUrl": "https://23410a33.ngrok.com/universal-bank-of-souls/",
    "status": "CREATED",
    "payKey": "AP-8ML17897XK803351A",
    "actionType": "PAY",
    "feesPayer": "EACHRECEIVER",
    "sender": {
        "useCredentials": "false"
    }
}

由于一些奇怪的原因paymentInfoList是空的,所以用户在点击paypal按钮的那一刻看到一个错误(交易错误)。

如前所述,如果我使用POSTMAN进行交易,然后检查状态,我会得到正确的响应:

{
    "responseEnvelope": {
        "timestamp": "2015-08-07T00:14:08.510-07:00",
        "ack": "Success",
        "correlationId": "b9049ba0d4cf1",
        "build": "17603431"
    },
    "cancelUrl": "URL",
    "currencyCode": "USD",
    "memo": "Bank of souls payment",
    "paymentInfoList": {
        "paymentInfo": [
            {
                "receiver": {
                    "amount": "123.30",
                    "email": "client2-ubs@gmail.com",
                    "primary": "false",
                    "paymentType": "SERVICE",
                    "accountId": "SLKM4ZQ5FMSHG"
                },
                "pendingRefund": "false"
            },
            {
                "receiver": {
                    "amount": "510.30",
                    "email": "client1-ubs@gmail.com",
                    "primary": "false",
                    "paymentType": "SERVICE",
                    "accountId": "8PUDR7LSRS4MJ"
                },
                "pendingRefund": "false"
            },
            {
                "receiver": {
                    "amount": "704.00",
                    "email": "store-ubs@gmail.com",
                    "primary": "true",
                    "paymentType": "SERVICE",
                    "accountId": "E29BAQX7C7P3N"
                },
                "pendingRefund": "false"
            }
        ]
    },
    "returnUrl": "URL",
    "status": "CREATED",
    "payKey": "AP-9MU4806743660523S",
    "actionType": "PAY",
    "feesPayer": "EACHRECEIVER",
    "reverseAllParallelPaymentsOnError": "false",
    "sender": {
        "useCredentials": "false"
    }
}

(paymentInfoList实际上包含一个带有商品的json对象,但这是使用POSTMAN手动执行请求)

这可能是PHP的问题吗?一些调试curl连接的想法对我很有帮助。

PD:我已经调试了一整天,我甚至print_r $json变量(我得到json格式)和复制/粘贴直接在邮差和它的作品,但由于某种原因相同的请求使用curl不发送$receiver信息。

解决了,我正在使用两种不同的api凭据发出请求(创建订单和请求订单信息),此外,paypal在接收与原件不同的api凭据时似乎隐藏了订单货物,但仍然显示订单状态(create, COMPLETED等)

相关内容

  • 没有找到相关文章

最新更新