UPS
UPS copied to clipboard
code is not working
the code simply is not working, I tried with codeigniter, regular php and all the same. it's always returning null. same example you posted I have been using. and only null in return. if I changed the Ups class to extend Ups_Live_Rates I would get invalid argument supplied for foreach. if you do :
var_dump(get_class_methods($this->ups));
var_dump(method_exists($this->ups,'get_rate'));
return $rate = $this->ups->get_rate('90007', $packages);
results would be:
array(5) {
[0]=>
string(11) "__construct"
[1]=>
string(4) "load"
[2]=>
string(6) "__call"
[3]=>
string(3) "get"
[4]=>
string(3) "set"
}
bool(false)
NULL
you would get null and false for method exists.
any help, been struggling with this since morning?!
What I understood from the code is that an object called rates
will be available, however I'm posting what would I tried:
$this->ups->set_country_code('US');
$this->ups->set_shipping_type('03');
var_dump(get_class_methods($this->ups->rates));
var_dump(method_exists($this->ups->rates,'get_rate'));
return $rate = $this->ups->rates->get_rate('90007', $packages);
this would return true for the check. a new error will rise up which is:
Message: Invalid argument supplied for foreach()
Filename: ups/Ups_Live_Rates.php
Line Number: 433
and same error for line 357
@mamdouhweb Hello. Faced with the same problem today. What I found out:
- "get_rates" function is not accessible from $ups object, you have to write $ups->rates->get_rates
- function get_rates from "Ups_Live_Rates" accept only one argument - array of packages you want to send. You passed string '90007' and received "Message: Invalid argument supplied for foreach()"
As I understand example message is a little bit old. @objectivehtml please, explain how to use your library properly :)
yeah, I already did that, if take a look at mt 2nd comment. $this->ups->rates->get_rates()
but even if you try to pass the first parameter as packages u'll get the same error. with or without a 2nd parameter.
@KoulSlou
Here is my experiment. This code at least send request to USP and get response. The problem is that response contain error message from UPS service:
$origin = array(
'state' => 'OK',
'postal_code' => '73145',
'country_code' => 'US'
);
$auth_params = array(
'access_key' => *********,
'username' => 'KoulSlou',
'password' => ********,
'account_number' => *********,
'origin' => $origin
);
$upsRateApi = new Ups_Live_Rates($auth_params);
$packages = array(
array(
'height' => 12,
'width' => 12,
'depth' => 1,
'weight' => 2.0
),
array(
'height' => 6,
'width' => 6,
'depth' => 2,
'weight' => 1.0
)
);
$upsRateApi->set_destination('73084');
$rate = $upsRateApi->get_rate($packages);
var_dump($rate);
Response contains error "No packages in shipment".
yeah, same here also.
I found out that problem is actually not with packages, but with ShipTo, ShipFrom elements. If you set this value as array(not just zipcode string) then these values will be incorrectly converted to xml.
What I mean. According to UPS documentation acceptable format of these fields is:
<ShipTo>
<CompanyName>
<Address>
<AddressLine1></AddressLine1>
<AddressLine2></AddressLine2>
<AddressLine3></AddressLine3>
<City></City>
........
</Address>
</ShipTo>
But if you check what xml is actually generated you will see that field <Address> is missing. To check what is cause of problem in your case I advice you to check string:
$result = $this->curl($data);
in file Ups_Live_Rates.php in function get_rate(). See what curl return to you. In my case it contains
<ErrorLocation>
<ErrorLocationElementName>RatingServiceSelectionRequest/Shipment/ShipTo/Address</ErrorLocationElementName>
</ErrorLocation>
I will check it out. but I think that it's time to @objectivehtml join us. Right!?!
Code is not working for Codeigniter UPS Api My code is:
'IN', 'postal_code' => '46060', 'country_code' => 'US' ); $auth_params = array( 'access_key' => 'XXXXX', 'username' => 'developer', 'password' => 'XXXXX@0', 'account_number' => 'XXXX', 'origin' => $origin ); $this->CI->load->library('Ups', $auth_params); $packages = array( array( 'height' => 12, 'width' => 12, 'depth' => 1, 'weight' => 2 ), array( 'height' => 6, 'width' => 6, 'depth' => 2, 'weight' => 1 ) ); $destination = '33010'; $destination = array( 'state' => 'FL', 'postal_code' => '33010', 'country_code' => 'US' ); $rate = $this->CI->ups->get_rate($destination, $packages); } } ``` Error: Severity: Notice Message: Undefined property: Ups::$CI Filename: controllers/ups.php # Line Number: 26 A PHP Error was encountered Severity: Notice Message: Trying to get property of non-object Filename: controllers/ups.php # Line Number: 26 Fatal error: Call to a member function library() on a non-object in E:\xampp\htdocs\apex\brs\application\controllers\ups.php on line 26