gpt4 book ai didi

php - 使用 Paypal REST api 和 PHP cURL 发布发票(草稿)不断返回 415 Unsupported Media Type

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

我正在使用来自 their website 的 paypal 创建发票样本 json

我得到了一个足够好的 token ,我将其与帖子一起提交,因为错误不是 401 Unauthorized 而是 415 Unsupported Media Type(现在最近是 500 Internal Server Error)这让我相信我'我很可能把那部分做对了……所以我会提供一些代码,希望有人能捕获我遗漏的一些明显的东西:

创建PaypalInvoice.php

function paypalCreateDraftRequest($token,$jsondraft){
global $url;
$sUrl = "/v1/invoicing/invoices";
$accept = "Accept:application/json";
$acceptlang = "Accept-Language:en_US";
$contenttype = "Content-Type: application/json";
$contentlen = "Content-Length: " . strlen($jsondraft);
// $jsondraft is a string of json from paypal example
$authorization = "Authorization: Bearer ".$token["access_token"];
$headers = array($accept,$acceptlang,$contenttype,$contentlen,$authorization);
$fields_string = $jsondraft;
$ch = curl_init();
$options = array (CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_FAILONERROR => true,
CURLOPT_URL => $url.$sUrl,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $fields_string,
CURLOPT_HEADER => false, // don't return headers
CURLOPT_SSL_VERIFYPEER => false, // TODO: fix certificate provider list problem later
CURLOPT_CONNECTTIMEOUT => 6, // timeout on connect
CURLOPT_TIMEOUT => 10 ); // timeout on response

curl_setopt_array ( $ch, $options );
try {
$result=curl_exec( $ch );
$log->LogDebug($result);
//$header = curl_getinfo ( $ch );
$err = curl_errno ( $ch );
$errmsg = curl_error ( $ch );
curl_close($ch);
if ($errmsg) throw new Exception($errmsg);
return $result;
} catch (Exception $e) { throw $e; }

}

来自 paypal 的示例发票:

{
"merchant_info": {
"email": "dennis@sample.com",
"first_name": "Dennis",
"last_name": "Doctor",
"business_name": "Medical Professionals, LLC",
"phone": {
"country_code": "001",
"national_number": "5032141716"
},
"address": {
"line1": "1234 Main St.",
"city": "Portland",
"state": "OR",
"postal_code": "97217",
"country_code": "US"
}
},
"billing_info": [
{
"email": "example@example.com"
}
],
"items": [
{
"name": "Sutures",
"quantity": 100,
"unit_price": {
"currency": "USD",
"value": 5
}
}
],
"note": "Medical Invoice 16 Jul, 2013 PST",
"payment_term" :{
"term_type": "NET_45"
},
"shipping_info": {
"first_name": "Sally",
"last_name": "Patient",
"business_name": "Not applicable",
"address": {
"line1": "1234 Broad St.",
"city": "Portland",
"state": "OR",
"postal_code": "97216",
"country_code": "US"
}
}
}

最佳答案

我发现了问题:

来自 paypal 的发票文件:

Note: The merchant specified in an invoice must have a PayPal account in good standing.

显然不应使用示例帐户“dennis@sample.com”。当我使用自己的沙盒帐户获取商家信息时,一切都神奇地有效...

也许其他人可能遇到这个问题,现在发布解决方案。也许我的示例代码也有帮助...

关于php - 使用 Paypal REST api 和 PHP cURL 发布发票(草稿)不断返回 415 Unsupported Media Type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23300533/

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