Business::Shipping - API for shipping-related tasks
Archive::Zip (any) Bundle::DBD::CSV (any) Cache::FileCache (any) Class::MethodMaker (any) Config::IniFiles (any) Crypt::SSLeay (any) Data::Dumper (any) Devel::Required (0.02) Error (any) LWP::UserAgent (any) XML::DOM (any) XML::Simple (2.05)
Example usage for a rating request:
use Business::Shipping; my $rate_request = Business::Shipping->rate_request( shipper => 'Offline::UPS', service => 'GNDRES', from_zip => '98682', to_zip => '98270', weight => 5.00, ); $rate_request->submit() or die $rate_request->error(); print $rate_request->total_charges();
Business::Shipping is an API for shipping-related tasks.
* Shipping cost calculation * Tracking, availability, and other services are planned for future addition.
* Online UPS (using the Internet and UPS servers) * Offline UPS (using tables stored locally) * Online USPS * Offline FedEX and USPS are planned for support in the future.
rate_request()
This method is used to request shipping rate information from online providers or offline tables. A hash is accepted as input with the following key values:
Business::Shipping::RateRequest::SHIPPER
. For example, ``Offline::UPS''.
An object is returned if the operation is successful, or 'undef' otherwise.
use Business::Shipping; use Business::Shipping::Shipment::UPS; my $shipment = Business::Shipping::Shipment::UPS->new(); $shipment->init( from_zip => '98682', to_zip => '98270', service => 'GNDRES', # # user_id, etc. needed here. # );
$shipment->add_package( id => '0', weight => 5, );
$shipment->add_package( id => '1', weight => 3, ); my $rate_request = Business::Shipping::rate_request( shipper => 'Online::UPS' ); # # Add the shipment to the rate request. # $rate_request->shipment( $shipment ); $rate_request->submit() or print $rate_request->error();
print $rate_request->package('0')->get_charges( 'GNDRES' ); print $rate_request->package('1')->get_charges( 'GNDRES' ); print $rate_request->get_total_price( 'GNDRES' );
The 'event_handlers' argument takes a hashref telling Business::Shipping what to do for error, debug, trace, and the like. The value can be one of four options:
* 'STDERR' * 'STDOUT' * 'carp' * 'croak'
For example:
$rate_request->init( 'event_handlers' => ({ 'error' => 'STDOUT', 'debug' => undef, 'trace' => undef, 'debug3' => undef, }) ); The default is 'STDERR' for error handling, and nothing for debug/trace handling. The option 'debug3' adds additional debugging messages that are not included in the normal 'debug'. Note that you can still access error messages even without an 'error' handler, by accessing the return values of methods. For example:
$rate_request->init( %values ) or print $rate_request->error(); However, if you don't save the error value before the next call, it could be overwritten by a new error.