- Notifications
You must be signed in to change notification settings - Fork51
mattsears/stamps
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Stamps is Stamps.com backed library for creating postage labels,calculate the shipping cost of packages, standardize domesticaddresses via USPS CASS certified Address Matching Software, and trackshipments.
Create postage stamp labels in png and pdf formats.
Standardizes shipping address that complies with the USPS addressformatting guidelines.
Validates city, state, and postal code combinations.
Calculate shipping rates based on distance and package weight.
Request USPS carrier pick ups.
Track shipment history.
Purchase postage.
Register for the Stamps.comDeveloperProgram to receive a freetest account.
Standardize Shipping Address - Ship-to addresses must bestandardized based on USPS rules for proper address conventions beforea shipping label can be issued.
Get Rates - allow users to view and select the best shippingservice for their needs.
Generate the Shipping Label - after choosing a shippingservice and ship-to address is standardized, the
Stamps.create
methodwill generate the indicium required to ship the item. Ifthe customer changes their mind, they may want to select an optionthat initiates aStamps.cancel
.Stamps.cancel
refunds postage andvoids the shipping label.Print the Shipping Label - Call the returned URL to obtain the shipping label image.A URL is returned by the
Stamps.create
call in the :url item. Theintegration will connect to this URL to retrieve their shipping labeland customs forms for printing.
Once you have a test account with integration id, we can simple passthem to the configure block:
# Authenticate you stamps.com credentialsStamps.configure do |config| config.integration_id = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXX' config.username = 'STAMPS USERNAME' config.password = 'STAMPS PASSWORD'end
Now we can now be able to retrieve information about our account:
Stamps.account
Standardizes shipping address that complies with the USPS addressformatting guidelines
standardized_address = Stamps.clean_address( :address => { :full_name => 'The White House', :address1 => '1600 Pennsylvania Avenue, NW', :city => 'Washington', :state => 'DC', :zip_code => '20500'})
To get a list of rates for all available USPS services based on theZIP Code or the foreign country being shipped to for a given packageweight and size.
rates = Stamps.get_rates( :from_zip_code => '45440', :to_zip_code => '20500', :weight_lb => '0.5', :ship_date => '2011-04-07')
To generate the postage based on the shipping information provided in the request.Thecreate!
method will return a URL that references either an image of thedomestic shipping label or a multi-page PDF document for internationallabels with customs forms.
stamp = Stamps.create!( :tracking_number => true, :rate => rates.first, :to => standardized_address, :from => { :full_name => 'Littlelines', :address1 => '50 Chestnut Street', :address2 => 'Suite 234', :city => 'Beavervcreek', :state => 'OH', :zip_code => '45440' }, :memo => 'Thanks for shopping with us!')
Now we can view or print the postage label:
stamp.url
If you want to see the data logged to and from the api:
Stamps.configure do |config| config.log_messages = trueend
By default Stamps will return responses as a Hash. To make Stampsreturn a Hashie instead:
Stamps.configure do |config| config.format = :hashieend
A return address can be specified in the configuration block aswell. This address will be used when the :from address is not specifiedwhen creating new stamps
Stamps.configure do |config| config.return_address = { :full_name => 'Littlelines', :address1 => '50 Chestnut Street', :address2 => 'Suite 234', :city => 'Beavercreek', :state => 'OH', :zip_code => '45440', :phone_number => '9375545027' }end
First install the gem:
gem install stamps
Add it to your Gemfile:
gem 'stamps'
- Source hosted atGitHub.
- Report Issues/Questions/Feature requests onGitHub Issues.
Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate changeyou make.