gpt4 book ai didi

php - PayPal REST API 送货地址不适用于 cURL 请求

转载 作者:太空宇宙 更新时间:2023-11-03 16:29:27 25 4
gpt4 key购买 nike

我想这是一个由两部分组成的问题,所以基本上我正在使用 PayPal 的 REST api 并且我想设置付款。我制作了这个数组,我在它上面使用了 json_encode 并将它转换成它下面的 json 代码,所以基本上送货地址对象有问题,因为一旦我删除它,一切都会顺利进行。当我浏览 the documentation 时,我真的找不到问题,我已经按照它说的那样将它放入 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"
)
)
)
)
)
);

关于php - PayPal REST API 送货地址不适用于 cURL 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26306886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com