abantecart / ups-php

PHP SDK to UPS RESTful API
MIT License
13 stars 9 forks source link

Uncaught Error: Class "OneOfRateResponseResponseAlert" not found #9

Closed Thedemon007 closed 8 months ago

Thedemon007 commented 8 months ago

I try run a example with this code but no work

Code:

<?php
require_once ('../vendor/autoload.php');
// Configure OAuth2 access token for authorization: oauth2
/** @see getAccessToken.php */
$token = 'you_token';
$config = UPS\Rating\Configuration::getDefaultConfiguration()->setAccessToken($token);

$apiInstance = new UPS\Rating\Request\DefaultApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client(),
    $config
);
$body = array(
  "RateRequest" => array(
    "Request" => array(
      "TransactionReference" => array(
        "CustomerContext" => "CustomerContext"
      )
    ),
    "Shipment" => array(
      "Shipper" => array(
        "Name" => "Roberto Perez",
        "ShipperNumber" => "123456", //accNumber
        "Address" => array(
          "AddressLine" => array(
            "ShipperAddressLine",
            "ShipperAddressLine",
            "ShipperAddressLine"
          ),
          "City" => "TIMONIUM",
          "StateProvinceCode" => "MD",
          "PostalCode" => "21093",
          "CountryCode" => "US"
        )
      ),
      "ShipTo" => array(
        "Name" => "ShipToName",
        "Address" => array(
          "AddressLine" => array(
            "ShipToAddressLine",
            "ShipToAddressLine",
            "ShipToAddressLine"
          ),
          "City" => "Alpharetta",
          "StateProvinceCode" => "GA",
          "PostalCode" => "30005",
          "CountryCode" => "US"
        )
      ),
      "ShipFrom" => array(
        "Name" => "ShipFromName",
        "Address" => array(
          "AddressLine" => array(
            "ShipFromAddressLine",
            "ShipFromAddressLine",
            "ShipFromAddressLine"
          ),
          "City" => "TIMONIUM",
          "StateProvinceCode" => "MD",
          "PostalCode" => "21093",
          "CountryCode" => "US"
        )
      ),
      "PaymentDetails" => array(
        "ShipmentCharge" => array(
          "Type" => "01",
          "BillShipper" => array(
            "AccountNumber" => "123456" //accNumber
          )
        )
      ),
      "Service" => array(
        "Code" => "03",
        "Description" => "Ground"
      ),
      "NumOfPieces" => "1",
      "Package" => array(
        "SimpleRate" => array(
          "Description" => "SimpleRateDescription",
          "Code" => "XS"
        ),
        "PackagingType" => array(
          "Code" => "02",
          "Description" => "Packaging"
        ),
        "Dimensions" => array(
          "UnitOfMeasurement" => array(
            "Code" => "IN",
            "Description" => "Inches"
          ),
          "Length" => "5",
          "Width" => "5",
          "Height" => "5"
        ),
        "PackageWeight" => array(
          "UnitOfMeasurement" => array(
            "Code" => "LBS",
            "Description" => "Pounds"
          ),
          "Weight" => "1"
        )
      )
    )
  )
);
$version = "v1"; // string | Indicates Rate API to display the new release features in Rate API response based on Rate release. See the New section for the latest Rate release. Supported values: v1, v1601, v1607, v1701, v1707, v2108, v2205. Length 5
$requestoption = "rate"; // string | Valid Values: Rate = The server rates (The default Request option is Rate if a Request Option is not provided). Shop = The server validates the shipment, and returns rates for all UPS products from the ShipFrom to the ShipTo addresses. Rate is the only valid request option for Ground Freight Pricing requests. . Length 10
$trans_id = "trans_id_example"; // string | An identifier unique to the request. Length 32
$transaction_src = "testing"; // string | An identifier of the client/source application that is making the request.Length 512
$additionalinfo = ""; // string | Valid Values: timeintransit = The server rates with transit time information combined with requestoption in URL.Rate is the only valid request option for Ground Freight Pricing requests. Length 15

try {
    $result = $apiInstance->rate(json_encode($body), $version, $requestoption, $trans_id, $transaction_src, $additionalinfo);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling DefaultApi->rate: ', $e->getMessage(), PHP_EOL;
}
?>
Error:

PHP Fatal error: Uncaught Error: Class "OneOfRateResponseResponseAlert" not found in /home/demon/php/simple_ups_rate/Rating/src/ObjectSerializer.php:298 Stack trace: #0 /home/demon/php/simple_ups_rate/Rating/src/ObjectSerializer.php(315): UPS\Rating\ObjectSerializer::deserialize() #1 /home/demon/php/simple_ups_rate/Rating/src/ObjectSerializer.php(315): UPS\Rating\ObjectSerializer::deserialize() #2 /home/demon/php/simple_ups_rate/Rating/src/ObjectSerializer.php(315): UPS\Rating\ObjectSerializer::deserialize() #3 /home/demon/php/simple_ups_rate/Rating/src/Request/DefaultApi.php(171): UPS\Rating\ObjectSerializer::deserialize() #4 /home/demon/php/simple_ups_rate/Rating/src/Request/DefaultApi.php(107): UPS\Rating\Request\DefaultApi->rateWithHttpInfo() #5 /home/demon/php/simple_ups_rate/_examples/getRates_.php(115): UPS\Rating\Request\DefaultApi->rate() #6 {main} thrown in /home/demon/php/simple_ups_rate/Rating/src/ObjectSerializer.php on line 298

abolabo commented 8 months ago

You should to runcomposer install command inside directory to rebuild the code.

Thedemon007 commented 8 months ago

You should to runcomposer install command inside directory to rebuild the code.

Thanks, i tried but it no solve

abolabo commented 8 months ago

You should to runcomposer install command inside directory to rebuild the code.

Thanks, i tried but it no solve

https://github.com/abantecart/ups-php/issues/10#issuecomment-1858182148

Thedemon007 commented 8 months ago

#10 (comment)

OAuthClientCredentials work but Rating not, anyway i download the zip file of #10 (comment) and tried run i add line var_dump( is_file('../Rating/vendor/autoload.php'));

first run Same error but var_dump() return: bool(false)

So i do this: cd ../Rating composer install

Tried run again get same error but var_dump() return: bool(true)

abolabo commented 8 months ago

did you removed composer.lock and vendor directory before "composer install" command? You should

Thedemon007 commented 8 months ago

did you removed composer.lock and vendor directory before "composer install" command? You should

I tried again this time removing composer.lock and vendor directory and get same error

abolabo commented 8 months ago
So i do this:
cd ../Rating
composer install

did you unpack ups.zip that i posted above? It already contains correct vendor subfolder and all api installed. In your case you tried to install one of many different APIs of UPS. Just unpack zip and use vendor/autoload.php file.

laborb-ch commented 6 months ago

This is still an issue in the most recent version.