PayPal REST API发货地址不适用于cURL请求
问题描述:
我想这是一个两部分问题,所以基本上我正在使用PayPal的REST API,并且我想要设置付款。我创建了这个数组,我使用了json_encode,并将其转换为下面的json代码,所以基本上运输地址对象有问题,因为一旦我删除它,一切都可以顺利进行。当我通过the documentation查找时,我无法真正发现问题,我已经将它放入item_list对象中,就像它应该填写所有必填字段,以便我猜测可能是错误的语法PayPal REST API发货地址不适用于cURL请求
$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()卷曲请求时,它的反应要么返回一个空字符串,在这种情况下它不起作用,或者它返回包含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对象的代码你已经走你的对象有点失灵,试试这样:
$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"
)
)
)
)
)
);
那么它工作得很好我现在正在做的事情,我真的不明白这一点。 – user3788675 2014-10-10 19:46:40
@ user3788675看到我的编辑 – 2014-10-10 19:49:50
我不认为你阅读我的问题,“运送地址对象有问题,因为只要我将其删除,一切顺利” – user3788675 2014-10-10 19:51:16