Four Key Reasons to Learn Markdown
Back-End Leveling UpWriting documentation is fun—really, really fun. I know some engineers may disagree with me, but as a technical writer, creating quality documentation that will...
Active Shipping is a nifty Shipping API extension for Active Merchant. It provides methods for interacting with common shipping carrier APIs. Recently we used Active Shipping on a client’s e-commerce site to provide customers with many shipping options from several carriers.
To get shipping rates for a carrier, you first need to “package” up some information about what you are shipping. Using the Package class you can build an array of packages. Use each package’s dimensions, weight, and the unit system you are measuring with (this will default to metric) to create a new package. Here in an example package:
From working with Active Shipping and various carrier APIs we have learned that all carriers require a package weight. Some will return results for a package with no dimensions. However, rates will vary greatly depending on the dimensions of your packages, so it is a good idea to always include them so that your rate estimates are accurate.
Along with the array of packages, Active Shipping needs to know some information about the origin and destination of your shipment. Using the Location class you can create an origin and destination location for your shipment. Here is an example of a destination (the origin is built the same way):
The Location class takes country, state, city, and zip. Working with Active Shipping and various carrier APIs we have found you can get away with just using country and zip code if needed.
Once we have an origin, destination, and packages we are ready to make request to the carriers’ APIs. Initialize the carrier you want to you use, then call its find_rates
method:
Each carrier requires its own set of credentials. You can sign up for each carrier’s service on their respective websites. While the UPS codes seem to always “just work”, you will need to pass :test => true
as a param to get Fedex to work while you are testing your application. We were unable to get the USPS API to provide rates in test mode). To get the USPS API to provide rates you will need to contact and have your production API access turned on. The best way to do this is the call the number provided in the confirmation email they sent. Requests made via email seem to take a couple days to get processed.
Active Shipping is just one of the great extensions of Active Merchant. What other Active Merchant extensions are you using in your e-commerce sites/development?
Writing documentation is fun—really, really fun. I know some engineers may disagree with me, but as a technical writer, creating quality documentation that will...
Humanity has come a long way in its technological journey. We have reached the cusp of an age in which the concepts we have...
Go 1.18 has finally landed, and with it comes its own flavor of generics. In a previous post, we went over the accepted proposal and dove...