gpt4 book ai didi

paypal - 尝试将 PayPal REST Orders API 用于 PayPal Market Places 时出现 curl 问题

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

我正在尝试遵循本文档中所示的订单集成指南:https://developer.paypal.com/docs/marketplaces/orders/integration-guide/

我能够完成获取访问 token 以及“创建订单”部分的所有内容。但是,当我尝试在我的本地主机中调用 Create Order 时,我得到以下输出:

注意: undefined variable :数据在C:\xampp\htdocs\ordersAPI.php第75行注意: undefined variable :数据在C:\xampp\htdocs\ordersAPI.php第85行

我一直在绞尽脑汁想弄清楚为什么会这样。我一直在查看各种堆栈问题,但我无法弄清楚我遗漏了什么。似乎我确实定义了“数据”变量,所以我不确定哪里出错了,也不确定为什么返回 1。

尝试在我发现的另一个测试站点上测试我的凭据时,我也收到返回 500 的错误。所以我不确定是账户有问题,还是我的代码有问题。我不认为这是一个帐户问题,因为它给出了有关 undefined variable 的错误。

                            <?php

$data = '{
"purchase_units": [
{
"reference_id": "item_bought",
"description": "item_description",
"amount": {
"currency": "USD",
"details": {
"subtotal": "100.00",
"shipping": "0.00",
"tax": "0.00"
},
"total": "100.00"
},
"payee": {
"email": "selleraccount@gmail.com"
},
"items": [
{
"name": "widget",
"sku": "sku03",
"price": "50.00",
"currency": "USD",
"quantity": "1",
"category": "PHYSICAL"
},
{
"name": "gadget",
"sku": "sku04",
"price": "50.00",
"currency": "USD",
"quantity": "1",
"category": "PHYSICAL"
}
],
"shipping_address": {
"recipient_name": "Billy Bob",
"line1": "123 Test Street",
"line2": "Building 17",
"city": "Lawrence",
"country_code": "US",
"postal_code": "66047",
"state": "KS",
"phone": "(123) 456-7890"
},
"shipping_method": "United Postal Service",
"partner_fee_details": {
"receiver": {
"email": "ordersapitest@gmail.com"
},
"amount": {
"value": "20.00",
"currency": "USD"
}
},
"payment_linked_group": 1,
"custom": "silk",
"invoice_number": "invoice_1234",
"payment_descriptor": "FakeShop"
}
],
"redirect_urls": {
"return_url": "https://marketplace.com/return",
"cancel_url": "https://marketplace.com/cancel"
}
}';


function marketplace(){

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/checkout/orders");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json",
"Content-Type: application/json",
"Authorization: Bearer A21AAFA2Ty6rGJc74cTukhyCRz5pHU3vX736qtr4qSfhDmEzawiU8u91w69GxZtmYDalxaljYbeqi6ovZmOQCyTEETom8ZkFQ",
"PayPal-Request-Id: 5Qy7c8A1H8iQqyp",
"Content-length: ".strlen($data))
);
$httpResponse= curl_exec($ch);
if(!$httpResponse) {
$response = "API failed: ".curl_error($ch).'('.curl_errno($ch).')';
return $response;
}
$httpResponseAr = explode("&", $httpResponse);
return $httpResponseAr;
}

$result = marketplace();
echo $json = json_encode($result, JSON_PRETTY_PRINT);

//print_r($result);

?>

最佳答案

$data 变量未作为参数传递到第 71 行的市场函数中,也未作为参数传递到第 96 行的函数调用中。这就是导致错误的原因。

此外,虽然“创建订单”调用会起作用,但如果您尝试下一步调用“支付订单”,则会生成错误 500,因为您正在尝试使用 PayPal 的 MarketPlaces API,并且尚未批准用于 MarketPlaces API。

请参阅this article在 Paypal 的网站上。

https://www.paypal-knowledge.com/infocenter/index?page=content&id=FAQ2138&expand=true&locale=en_US

您还可以在以下位置找到有关 PP4MP 的更多信息:
https://developer.paypal.com/docs/marketplaces/pp4mp/

关于paypal - 尝试将 PayPal REST Orders API 用于 PayPal Market Places 时出现 curl 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46221953/

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