PayPal REST API送货地址无法处理cURL请求


PayPal REST API shipping address not working upon a cURL request

我想这是一个由两部分组成的问题,所以基本上我正在使用PayPal的RESTapi,我想设置一个支付。我制作了这个数组,在上面使用json_encode,它将其转换为下面的json代码,所以基本上发货地址对象有问题,因为一旦我删除它,一切都会顺利进行。当我查看文档时,我真的找不到问题,我已经把它放在item_list对象中,就像它说的那样,填写了所有必需的字段,所以我猜语法可能有问题

$json_object = array(
    "intent" => "sale",
    "redirect_urls" => array(
        "return_url" => "localhost/oauth2/src/OAuth2/success.php",
        "cancel_url" => "localhost"
    ),
    "payer" => array(
        "payment_method" => "paypal"
    ),
    "transactions" => array(
            0 => array(
            "amount" => array(
                "total" => "12.00",
                "currency" => "USD"
            ),
            "description" => "payment description",
            "item_list" => array(
                "items" => array(
                    0 => array(
                        "quantity" => "1",
                        "name" => "jacket",
                        "price" => "12.00",
                        "sku" => "dasd",
                        "currency" => "USD",
                        "description" => "blue"
                    )
                ),
                   "shipping_address" => array(
                    "recipient_name" => "John Johnson",
                    "line1" => "Whatever street 2",
                    "line2" => "Another street 2",
                    "city" => "London",
                    "country_code" => "UK",
                    "postal_code" => "NR30 1LY",
                    "state" => "England",
                    "phone" => "3123123123"
                )
            )
        )
    )
);

编码到

{
  "intent": "sale",
  "redirect_urls": {
    "return_url": "localhost/oauth2/src/OAuth2/success.php",
    "cancel_url": "localhost"
  },
  "payer": {
    "payment_method": "paypal"
  },
  "transactions": [
    {
      "amount": {
        "total": "12.00",
        "currency": "USD"
      },
      "description": "payment description",
      "item_list": {
        "items": [
          {
            "quantity": "1",
            "name": "jacket",
            "price": "12.00",
            "sku": "dasd",
            "currency": "USD",
            "description": "blue"
          }
        ],
        "shipping_address": {
          "recipient_name": "John Johnson",
          "line1": "Whatever street 2",
          "line2": "Another street 2",
          "city": "London",
          "country_code": "UK",
          "postal_code": "NR30 1LY",
          "state": "England",
          "phone": "3123123123"
        }
      }
    }
  ]
}

我想问的另一个问题是,在我var_dump()curl请求的响应之后,它要么返回一个空字符串,在这种情况下它不起作用,要么返回包含JSON对象的所需请求,我永远不会得到错误或任何

以下是我用来提交上方JSON对象的代码

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment");
curl_setopt($ch, CURLOPT_HEADER, $token);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", $token));
$response = curl_exec($ch);
curl_close($ch);

你的对象有点乱了,试着这样做:

$json_object = array(
    "intent" => "sale",
    "redirect_urls" => array(
        "return_url" => "localhost/oauth2/src/OAuth2/success.php",
        "cancel_url" => "localhost"
    ),
    "payer" => array(
        "payment_method" => "paypal",
        "payer_info" => array(
            "shipping_address" => array(
                "recipient_name" => "John Johnson",
                "line1" => "Whatever street 2",
                "line2" => "Another street 2",
                "city" => "London",
                "country_code" => "UK",
                "postal_code" => "NR30 1LY",
                "state" => "England",
                "phone" => "3123123123"
            )
        )
    ),
    "transactions" => array(
            0 => array(
            "amount" => array(
                "total" => "12.00",
                "currency" => "USD"
            ),
            "description" => "payment description",
            "item_list" => array(
                "items" => array(
                    0 => array(
                        "quantity" => "1",
                        "name" => "jacket",
                        "price" => "12.00",
                        "sku" => "dasd",
                        "currency" => "USD",
                        "description" => "blue"
                    )
                )
            )
        )
    )
);