abantecart / ups-php

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

Example not working #17

Closed 35develr closed 4 months ago

35develr commented 4 months ago

HP Fatal error: Uncaught Error: Class "UPS\OAuthClientCredentials\Configuration" not found in /var/www/ppp/ups/getAccessToken.php:11 Stack trace:

0 {main}

thrown in /var/www/ppp/ups/getAccessToken.php on line 11

i used composer with php8.1

<?php
require_once 'vendor/autoload.php';
//YOUR ACCOUNT NUMBER (6 characters)
$accNumber = 'XXXXXX';
//UPS API Credentials (obtain after APP creation)
$clientId = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX';
$password = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX;

$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;
}

?>
daanggc commented 4 months ago

Fixed this by adding:

"extra": {
        "merge-plugin": {
            "include": [
                "*/composer.json",
                "OAuthClientCredentials/composer.json",
                "Rating/composer.json",
                "vendor/abantecart/ups-php/*/composer.json"
            ],
            "recurse": true,
            "replace": false,
            "merge-extra": false
        }
},

In composer.json of my local project.