php - 我的代码沙盒 Paypal future 付款有什么问题

标签 php ios curl paypal paypal-sandbox

我已经在我的应用中启用了 future 付款权限并使用了开发人员仪表板。但还没有工作,请查找错误 http://developer.paypal.com/并登录 https://developer.paypal.com/developer/accountStatus在那里你可以看到你有什么许可证。

 $data = array(
                "intent" => "authorize",
                "payer" => array(
                    "payment_method" => "paypal"
                ),
                "transactions" => array(
                    array("amount" => array(
                        "currency" => "USD",
                        "total" => "1.88"
                    ),
                        "description" => "future of sauces")
                ));

        $data_string = json_encode($data);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment");
        $headers = array(
            'Content-Type: application/json',
            'PayPal-Client-Metadata-Id: d6743cbb53ea4470a53bfe458f0cb885',
            'Authorization: Bearer A103.B7d5318JDS6NA1zGh02avjCx16oxnBPadUat5z9SlGVGEiOhoAeMuqyz0anGSICS.FAkzECypTS1IXfemHcpVa5yyrGu',
        );
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        //curl_setopt($ch, CURLINFO_HEADER_OUT, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        $result = curl_exec($ch);
        $information = curl_getinfo($ch);
        curl_close($ch);
        print_r($information);
        die;

放在这里

{"name":"PERMISSION_DENIED","message":"No permission for the requested operation","information_link":"https://developer.paypal.com/docs/api/#PERMISSION_DENIED","debug_id":"5b39efd4cf370"}Array
(
    [url] => https://api.sandbox.paypal.com/v1/payments/payment
    [content_type] => application/json
    [http_code] => 403
    [header_size] => 592

最佳答案

我做了一个Paypal Module,希望这段代码能帮到你。

$result_json = json_decode($result);

/* Check if authentication is valid */
if (isset($result_json->access_token))
{
    $enc_data = json_encode($data);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://api.sandbox.paypal.com/v1/payments/payment');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, !in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1')));
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $enc_data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Authorization: Bearer '.$result_json->access_token,
        'PayPal-Client-Metadata-Id: ************'
    ));

    $result = curl_exec($ch);
    $json_result = json_decode($result);
    curl_close($ch);
}

json_encode($data) 有一些额外的信息可能对您可能尝试做的交易没有用,但它只是一个例子。

{
    "intent": "sale",
    "payer": {
        "payment_method": "credit_card",
        "payer_info": {
            "email": "...",
            "shipping_address": {
                [...]
            }
        },
        "funding_instruments": [
            {
                "credit_card": {
                    [...]
                    }
                }
            }
        ]
    },
    "transactions": [
        {
            "amount": {
                "total": 32.91,
                "currency": "USD"
            },
            "item_list": {
                "items": [
                    {
                        "quantity": 1,
                        "name": "Product Name",
                        "price": 16.51,
                        "currency": "USD"
                    },
                    {
                        "quantity": 1,
                        "name": "Product Name 2",
                        "price": "16.40",
                        "currency": "USD"
                    },
                    {
                        "quantity": 1,
                        "name": "Shipping",
                        "price": 0,
                        "currency": "USD"
                    }
                ],
                "shipping_address": {
                    [...]
                }
            }
        }
    ]
}

关于php - 我的代码沙盒 Paypal future 付款有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35837796/

相关文章:

linux - CURL (35) SSL 连接错误/NSS 错误 -5961

php - 如何获取mysql中的第一个值?

php - JSON对象作为数组中的数组如何保持while循环继续

ios - 如何使用 protected init 来模拟对象

ios - 在 Swift 中初始化通用 RGB

java - Spring 4.x/3.x (Web MVC) REST API 和 JSON2 Post 请求,如何一劳永逸?

php - 如何使用 Sound Cloud API 通过标签搜索特定用户的轨道?

php - 请求 MP3 文件时设置 apache 为 PHP 提供服务

ios - CLLocationManager 委托(delegate)方法未在后台调用

c++ - libcurl 如何更改编码 url 行为