尝试将 PayPal REST Orders API 用于 PayPal Market Places 时出现卷曲问题

curl issue when trying to use PayPal REST Orders API for PayPal Market Places

我正在尝试按照本文档中所示的订单集成指南进行操作:https://developer.paypal.com/docs/marketplaces/orders/integration-guide/

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

注意:未定义变量:第75行C:\xampp\htdocs\ordersAPI.php中的数据 注意:未定义变量:数据在C:\xampp\htdocs\ordersAPI.php第85行

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

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

                            <?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 行的函数调用中作为参数传递。这就是导致错误的原因。

此外,虽然 'CREATE ORDER' 调用会起作用,但如果您尝试下一步,即 'PAY FOR ORDER' 调用,则会生成错误 500,因为您正在尝试使用 MarketPlaces API 用于 PayPal,尚未获准用于 MarketPlaces API。

请参阅 PayPal 网站上的 this article

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

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