Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation Question #8

Closed
graffxdesign opened this issue Dec 2, 2023 · 12 comments
Closed

Installation Question #8

graffxdesign opened this issue Dec 2, 2023 · 12 comments

Comments

@graffxdesign
Copy link

Hello

  1. I went to my blank website root and ran the composer command and installed the files
composer require abantecart/ups-php
  1. I created a new file in my root, upstest.php and added this content.
<?php
require __DIR__ . '/vendor/autoload.php';

$accNumber = '';
$clientId = '';
$password = '';

$config = \UPS\OAuthClientCredentials\Configuration::getDefaultConfiguration()
    ->setUsername($clientId)
    ->setPassword($password);

$apiInstance = new \UPS\OAuthClientCredentials\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
);
$grant_type = "client_credentials"; // string |
$x_merchant_id = $accNumber; // string | Client merchant ID

try {
    $result = $apiInstance->createToken($grant_type, $x_merchant_id);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling DefaultApi->generateToken: ', $e->getMessage(), PHP_EOL;
}

I keep getting the error:

Fatal error: Uncaught Error: Class "UPS\OAuthClientCredentials\Configuration" not found in /home/pelp/public_html/dadev/upstest.php:17 Stack trace: #0 {main} thrown in /home/pelp/public_html/dadev/upstest.php on line 7

Do you know what I am doing wrong?

@abolabo
Copy link
Collaborator

abolabo commented Dec 3, 2023

1.try to remove subfolder vendor and file composer.lock
2. run composer install in the terminal
3. try now your script

@MichalOrm
Copy link

1.try to remove subfolder vendor and file composer.lock 2. run composer install in the terminal 3. try now your script

this did not work for me

@abolabo
Copy link
Collaborator

abolabo commented Jan 24, 2024

this did not work for me

what this mean? any details?

@MichalOrm
Copy link

for example:

<?php

require_once(__DIR__.'/../../../vendor/vendor/autoload.php');

$config = \UPS\OAuthClientCredentials\Configuration::getDefaultConfiguration()
    ->setUsername('test')
    ->setPassword('test');

Fatal error: Uncaught Error: Class 'UPS\OAuthClientCredentials\Configuration' not found in C:\xampp\htdocs\test\index.php:5 Stack trace: #0 {main} thrown in C:\xampp\htdocs\test\index.php on line 5

composer.json:

{
    "require-dev": {
        "phpstan/phpstan": "0.12.100",
        "vimeo/psalm": "3.18.2",
        "phpmd/phpmd" : "2.14.1",
        "cloudstek/php-laff" : "1.1.1"
    },
    "require": {
        "google/apiclient": "2.14.0",
        "nicolab/php-ftp-client": "1.6.1",
        "phpclassic/php-shopify": "1.2.9",
        "php-amqplib/php-amqplib": "3.6.0",
        "hollodotme/fast-cgi-client": "3.1.7",
        "sentry/sdk": "3.5",
        "guzzlehttp/guzzle": "7.3.0 as 6.5",
        "mpdf/mpdf": "8.0.10",
        "picqer/bol-retailer-php-client": "8.1.0",
        "satun14/redmine-api": "v2.0",
        "dragonmantank/cron-expression": "3.3.3",
        "elasticsearch/elasticsearch": "8.10.0",
        "phpoffice/phpspreadsheet": "1.29.0",
        "php-ai/php-ml": "0.9.0",
        "jlevers/selling-partner-api": "5.10.1",     
        "symfony/var-dumper": "^5.4",
        "abantecart/ups-php": "^1.0"
    },
    "config": {
        "allow-plugins": {
            "wikimedia/composer-merge-plugin": true,
            "php-http/discovery": true
        }
    }
}

any other vendor library works just fine


@abolabo
Copy link
Collaborator

abolabo commented Jan 24, 2024

This package is a API set with it's own composer.json files inside of each subdirectory.
Unfortunately i don't know a solution how to install all UPS APIs as one monolith package via "composer require" command.
I added wikimedia-merge-plugin into composer.json and it works when i run "composer install" inside directory of the project(see vendor/composer/autoload_static.php file, you should look on UPS classes inside)
If you run composer require command these UPS classes ignores without any causes.
Asking of help on wikimwedia github-repo does not help.

@jroszkiewicz
Copy link

@abolabo always you can make main package with composer.json, where you can require all "packages" from separated repos.
After all why do you need to separate each api with additional composer.json file?

@abolabo
Copy link
Collaborator

abolabo commented Jan 31, 2024

@abolabo always you can make main package with composer.json, where you can require all "packages" from separated repos. After all why do you need to separate each api with additional composer.json file?

It was not mine idea. See official UPS openapi repo. We just use UPS specs.
But maybe you are right. Probably we can merge all their openapi json specs. Need to think.

@laborb-ch
Copy link

Ran into this problem too. To fix this problem you need change the autoload configuration of your composer.json:

{
    "autoload": {
        "psr-4": {
            "UPS\\AddressValidation\\": "vendor/abantecart/ups-php/AddressValidation/src/",
            "UPS\\DangerousGoods\\": "vendor/abantecart/ups-php/DangerousGoods/src/",
            "UPS\\LandedCost\\": "vendor/abantecart/ups-php/LandedCost/src/",
            "UPS\\Locator\\": "vendor/abantecart/ups-php/Locator/src/",
            "UPS\\OAuthAuthCode\\": "vendor/abantecart/ups-php/OAuthAuthCode/src/",
            "UPS\\OAuthClientCredentials\\": "vendor/abantecart/ups-php/OAuthClientCredentials/src/",
            "UPS\\Paperless\\": "vendor/abantecart/ups-php/Paperless/src/",
            "UPS\\Pickup\\": "vendor/abantecart/ups-php/Pickup/src/",
            "UPS\\PreNotification\\": "vendor/abantecart/ups-php/PreNotification/src/",
            "UPS\\QuantumView\\": "vendor/abantecart/ups-php/QuantumView/src/",
            "UPS\\Rating\\": "vendor/abantecart/ups-php/Rating/src/",
            "UPS\\Shipping\\": "vendor/abantecart/ups-php/Shipping/src/",
            "UPS\\TForceFreightPickup\\": "vendor/abantecart/ups-php/TForceFreightPickup/src/",
            "UPS\\TForceFreightPickupCancel\\": "vendor/abantecart/ups-php/TForceFreightPickupCancel/src/",
            "UPS\\TForceFreightRating\\": "vendor/abantecart/ups-php/TForceFreightRating/src/",
            "UPS\\TForceFreightShipping\\": "vendor/abantecart/ups-php/TForceFreightShipping/src/",
            "UPS\\TimeInTransit\\": "vendor/abantecart/ups-php/TimeInTransit/src/",
            "UPS\\Tracking\\": "vendor/abantecart/ups-php/Tracking/src/",
            "UPS\\UPSTrackAlert\\": "vendor/abantecart/ups-php/UPSTrackAlert/src/"
        }
    }
}

@evs-xsarus
Copy link

@abolabo can't this be fixed by creating separate repositories for each API and referencing those repo's in the global ups-php package ? Installing only ups-locator, it's now just not possible.

@abolabo
Copy link
Collaborator

abolabo commented Apr 23, 2024

@abolabo can't this be fixed by creating separate repositories for each API and referencing those repo's in the global ups-php package ? Installing only ups-locator, it's now just not possible.

this package based on official UPS api-spec repository (see readme). They changing their API quantities permanentaly. Since summer 2023 i had seen at least 4 renaming of apis. I think to create of separate repo for each their API is a mistake.

@evs-xsarus
Copy link

Maybe this will stabilize in the coming year.

@icweb
Copy link

icweb commented May 1, 2024

Ran into this problem too. To fix this problem you need change the autoload configuration of your composer.json:

{
    "autoload": {
        "psr-4": {
            "UPS\\AddressValidation\\": "vendor/abantecart/ups-php/AddressValidation/src/",
            "UPS\\DangerousGoods\\": "vendor/abantecart/ups-php/DangerousGoods/src/",
            "UPS\\LandedCost\\": "vendor/abantecart/ups-php/LandedCost/src/",
            "UPS\\Locator\\": "vendor/abantecart/ups-php/Locator/src/",
            "UPS\\OAuthAuthCode\\": "vendor/abantecart/ups-php/OAuthAuthCode/src/",
            "UPS\\OAuthClientCredentials\\": "vendor/abantecart/ups-php/OAuthClientCredentials/src/",
            "UPS\\Paperless\\": "vendor/abantecart/ups-php/Paperless/src/",
            "UPS\\Pickup\\": "vendor/abantecart/ups-php/Pickup/src/",
            "UPS\\PreNotification\\": "vendor/abantecart/ups-php/PreNotification/src/",
            "UPS\\QuantumView\\": "vendor/abantecart/ups-php/QuantumView/src/",
            "UPS\\Rating\\": "vendor/abantecart/ups-php/Rating/src/",
            "UPS\\Shipping\\": "vendor/abantecart/ups-php/Shipping/src/",
            "UPS\\TForceFreightPickup\\": "vendor/abantecart/ups-php/TForceFreightPickup/src/",
            "UPS\\TForceFreightPickupCancel\\": "vendor/abantecart/ups-php/TForceFreightPickupCancel/src/",
            "UPS\\TForceFreightRating\\": "vendor/abantecart/ups-php/TForceFreightRating/src/",
            "UPS\\TForceFreightShipping\\": "vendor/abantecart/ups-php/TForceFreightShipping/src/",
            "UPS\\TimeInTransit\\": "vendor/abantecart/ups-php/TimeInTransit/src/",
            "UPS\\Tracking\\": "vendor/abantecart/ups-php/Tracking/src/",
            "UPS\\UPSTrackAlert\\": "vendor/abantecart/ups-php/UPSTrackAlert/src/"
        }
    }
}

This fixed it for me. Easiest solution might be to add this to the README.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants