abantecart / ups-php Goto Github PK
View Code? Open in Web Editor NEWPHP SDK to UPS RESTful API
License: MIT License
PHP SDK to UPS RESTful API
License: MIT License
Hi,
the ShipmentResults->PackageResults issue is fixed now in the documentation (UPS-API/api-documentation#30).
Can you please update the package?
There is an issue with the OneOfLabelRecoveryResponseLabelResults class. The class lacks arguments to fetch or retrieve data from the response.
Here is the response from UPS Testing
{ "LabelRecoveryResponse": { "Response": { "ResponseStatus": { "Code": "1", "Description": "Success" }, "TransactionReference": { "CustomerContext": "testing" } }, "ShipmentIdentificationNumber": "1Z12345E8791315509", "LabelResults": { "TrackingNumber": "1Z12345E8791315509", "LabelImage": { "LabelImageFormat": { "Code": "PDF" }, "GraphicImage": "JVBERi0xLjMNJeLjz9MNCjIw=", "URL": "https://www.ups.com/uel/llp/1Z12345E8791315509/link/labelAll/XLBR/0uHrBtnAFwm4NRuUC7XNCqQ7Tb2RRs0D0oimIIqZ3Mse/en_US?loc=en_US&cie=true&pdr=false" }, "Receipt": { "Image": { "ImageFormat": { "Code": "PDF" }, "GraphicImage": "JVBERi0xLjMNJeLjz9MNCjEg" }, "URL": "https://www.ups.com/uel/llp/1Z12345E8791315509/link/receipt/XLBR/0uHrBtnAFwm4NRuUC7XNCqQ7Tb2RRs0D0oimIIqZ3Mse/en_US?loc=en_US&cie=true&pdr=false" } } } }
Hi,
thank you for your work for building this API Wrapper for UPS.
I am not an experienced developer and i am unsure how to use you api. There are examples for authorize and get shipping fees. But
can you give more examples? Like, "how to create a shipping label" and these things?
Thanks a lot
after using command:
composer require abantecart/ups-php
library is downloaded and installed, but PHP doesent see it.
After further investigation i have found that \vendor\composer\autoload_psr4.php doesent have anything related with abantecart nor ups
What i have also done is:
Any other ideas how to use this library?
We should migrate to solution with newest API request.
https://www.drupal.org/project/commerce_ups/issues/3387353#comment-15337989
This library is great candidate to be incorporate for Drupal community.
From perspective of maintainer of this library, our need is to update from :
https://github.com/gabrielbull/php-ups-api
to:
https://github.com/abantecart/ups-php
Do have some experience what change are between?
This main folder is where we need your attention in this update (subfolder not needed):
https://git.drupalcode.org/project/commerce_ups/-/tree/8.x-3.x/src
Is this something that you can help to do as someone who know API?
As you see, there is only few places that need equivalent of API points to work and need only to be replaced as API keys and engine work on older implementation
Thank you for any help!
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;
}
?>
The host in this API is wwwcie.ups.com which , for the locator, only supports.
// United States - Atlantis
// Canada - Toronto
// Germany - Neuss
// Mexico - Mexico City
Do you know which host to use for normal production?
after composer install:
composer require abantecart/ups-php
i successfully installed everything and adjusted the credentials in
getAccessToken.php
and copy getAccessToken.php in root
unfortunately I only get:
Fatal error: Uncaught Error: Class ‘UPS\OAuthClientCredentials\Configuration’ not found in /var/www/getAccessToken.php
that's the simplest example, what's wrong with it?
This note in e.g.
_examples/createShipping.php
makes zero sense!
‘Generate sample code for popular API requests by selecting an example below.
To view a full sample request and response, first click ‘Authorise’ and enter your application credentials,
then populate the required parameters above and click ‘Try it out’.’
There is no ‘example below’ ... that's the problem.
What does this text refer to?
‘example below’ ??
‘Try it out’
and
$additionaladdressvalidation = "additionaladdressvalidation_example"; // string | Valid Values: city = validation will include city.Length 15
additionaladdressvalidation_example!
yes!
There is an issue with the OneOfShipmentResponseShipmentResultsPackageResults class. The class lacks arguments to fetch or retrieve data from the response.
Here is the response from UPS Testing
{ "ShipmentResponse": { "Response": { "ResponseStatus": { "Code": "1", "Description": "Success" }, "Alert": { "Code": "129001", "Description": "Additional Handling has automatically been set on Package 1." }, "TransactionReference": { "CustomerContext": "testing" } }, "ShipmentResults": { "ShipmentCharges": { "TransportationCharges": { "CurrencyCode": "USD", "MonetaryValue": "87.17" }, "ServiceOptionsCharges": { "CurrencyCode": "USD", "MonetaryValue": "31.40" }, "TotalCharges": { "CurrencyCode": "USD", "MonetaryValue": "118.57" } }, "BillingWeight": { "UnitOfMeasurement": { "Code": "LBS", "Description": "Pounds" }, "Weight": "98.0" }, "ShipmentIdentificationNumber": "1ZXXXXXXXXXXXXXXXX", "PackageResults": { "TrackingNumber": "1ZXXXXXXXXXXXXXXXX", "BaseServiceCharge": { "CurrencyCode": "USD", "MonetaryValue": "71.26" }, "ServiceOptionsCharges": { "CurrencyCode": "USD", "MonetaryValue": "31.40" }, "ShippingLabel": { "ImageFormat": { "Code": "GIF", "Description": "GIF" }, "GraphicImage": "R0lGODlheAUgA/cAAAAAAAEBAQICAg" }, "ItemizedCharges": [ { "Code": "100", "CurrencyCode": "USD", "MonetaryValue": "24.50" }, { "Code": "375", "CurrencyCode": "USD", "MonetaryValue": "15.91" }, { "Code": "432", "CurrencyCode": "USD", "MonetaryValue": "6.90" } ] } } } }
Hi,
I'm try to do zip code check for Saturday delivery (using time in transit) and when I use the zip code 84098 in the request, I'm getting an error:
Cannot use "parent" when current class scope has no parent {"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): Cannot use "parent" when current class scope has no parent at /Users/crazyj9/Library/CloudStorage/Dropbox/Code/Sites/GMLapp/vendor/abantecart/ups-php/TimeInTransit/src/TimeInTransit/DestinationPickList.php:181)
Here's the body of the request:
`
UPS\TimeInTransit\TimeInTransit\TimeInTransitRequest Object
(
[container:protected] => Array
(
[origin_country_code] => US
[origin_state_province] =>
[origin_city_name] =>
[origin_town_name] =>
[origin_postal_code] => 04101
[destination_country_code] => US
[destination_state_province] =>
[destination_city_name] =>
[destination_town_name] =>
[destination_postal_code] => 84098
[residential_indicator] => 01
[ship_date] => 2023-12-22
[ship_time] =>
[weight] => 10.5
[weight_unit_of_measure] => LBS
[shipment_contents_value] => 100
[shipment_contents_currency_code] => USD
[bill_type] => 03
[avv_flag] => 1
[number_of_packages] => 1
[drop_off_at_facility_indicator] =>
[hold_for_pickup_indicator] =>
[return_unfilterd_services] =>
[max_list] =>
)
)
`
When I submit this zip code on ups api site, I get a response of destinationAmbiguous=true, which is fine, but the code is failing. Can you take a look please?
Thank you,
John
The PackageResults Property of ShipmentResults can be an array of PackageResults or just the properties of an PackageResults-Object
Single:
"PackageResults": { "TrackingNumber": "1ZXXXXXXXXXXXXXXXX", "ServiceOptionsCharges": { "CurrencyCode": "USD", "MonetaryValue": "0.00" }, "ShippingLabel": { "ImageFormat": { "Code": "ZPL", "Description": "ZPL" }, "GraphicImage": "" } }
Multiple:
"PackageResults": [ { "TrackingNumber": "1ZXXXXXXXXXXXXXXXX", "ServiceOptionsCharges": { "CurrencyCode": "USD", "MonetaryValue": "0.00" }, "ShippingLabel": { "ImageFormat": { "Code": "ZPL", "Description": "ZPL" }, "GraphicImage": "" } }, { "TrackingNumber": "1ZXXXXXXXXXXXXXXXX", "ServiceOptionsCharges": { "CurrencyCode": "USD", "MonetaryValue": "0.00" }, "ShippingLabel": { "ImageFormat": { "Code": "ZPL", "Description": "ZPL" }, "GraphicImage": "" } } ]
The swagger generated classes do not support this and currently only array as PackageResults are supported.
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;
}
?>
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
Hi,
I can't figure out how to fix this. I had a blank directory, used your composer line and am getting this error.
Am I supposed to add another composer line to add the UPS directory? I do not see one in the files.
Fatal error: Uncaught Error: Class "UPS\OAuthClientCredentials\Configuration" not found in /home/NULL/public_html/dadev/wp-content/plugins/rma/ups.php:13 Stack trace: #0 {main} thrown in /home/NULL/public_html/dadev/wp-content/plugins/rma/ups.php on line 13
Thank you
<?php
require __DIR__ . '/vendor/autoload.php';
-- account info removed --
$config = \UPS\OAuthClientCredentials\Configuration::getDefaultConfiguration()
->setUsername($clientId)
->setPassword($password);
Hello
composer require abantecart/ups-php
<?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?
Missing Tracking api after upgrade to v1.0.2
Hello there,
we'd like to incorporate the composer package ups-php
into our codebase.
Will ups-php
stay published open source or are there plans to turn this into a private repository?
I'm asking because there is no license shipped with this repository and we want to avoid the visibility of this repository might change in the future.
Thank you!
testing out rating today, and although a valid API call is made and reports success, all returned results are NULL, thus none of the returned API data is available. seems a generic issue with this wrapper.
Testing the exact same API call manually via CURL works correctly.
Hi,
I'm having installation issues as well. I followed the instructions in this post and still cannot get past the error
Fatal error: Uncaught Error: Class "UPS\OAuthClientCredentials\Configuration" not found in /Users/crazyj9/Library/CloudStorage/Dropbox/Code/Sites/GMLapp/vendor/abantecart/ups-php/_examples/getAccessToken.php:10
Any other ideas to try?
Thank you!
John
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.