tracking_number
tracking_number copied to clipboard
Valid DHL eCommerce tracking numbers fail validation
Problem
This gem seems to support DHL eCommerce, but DHL eCommerce tracking numbers fail validation.
It seems the problem is this gem expects DHL eCommerce tracking numbers to start with a 2-letter prefix like "GM", but in my experience they are all-numeric (14 digits).
These are real DHL eCommerce tracking numbers generated between May and July, 2024:
dhl_ecommerce_tracking_numbers = %w[51087693037816 60120172242323 60120174971147]
dhl_ecommerce_tracking_numbers.map do |tracking_code|
t = TrackingNumber.new(tracking_code)
t.valid?
end
=> [false, false, false]
Proposal
DHL eCommerce tracking numbers should pass validation.
Additional info
- DHL has many different pages for checking shipment status. For some reason, most of these pages don't recognize DHL eCommerce tracking numbers and none recognize them when they're freshly-generated. It seems eCommerce tracking numbers are not recognized until they're scanned. I've found this endpoint seems to be the most useful: https://www.dhl.com/us-en/home/tracking/tracking-parcel.html
- I have not been able to find any information about DHL tracking code format, checksum, etc.
@jkeen this is an awesome gem, I've been using it for years. Thanks for maintaining it!
If you can point me in the right direction, I'd be happy to submit a PR.
@dan-jensen
https://parcelsapp.com/en/carriers/dhl-ecommerce this is where I got that info from.
If you're finding e-commerce numbers that don't fit that, then sounds like there are other cases that haven't been handled. Add your tracking numbers to that "valid" block in the data you pointed to, and then modify the regex to make that that first character group optional (probably just a ? after the inner parentheses would do it) and see if all the tests pass.
Tentative PR here: https://github.com/jkeen/tracking_number_data/pull/104