Sagepay – Magento – Armed Forces – INVALID. 3139 : The DeliveryState format is invalid.

The title says it all. Magento installation with failed transactions using Sagepay fail when the delivery address is Armed Forces Middle East, Armed Forces Africa or Armed Forces Canada. It’s for a good reason – Magento itself sets the region ID for these options as ‘AM’, ‘AF’ and ‘AC’ respectively;

armed-forces-middle-east3

Which is dandy until you realise that these region codes don’t actually exist anywhere. As you can see from this instructional on stamps.com, Middle east and Africa should be designated as ‘AE’ whilst Canada is part of America and should be designated ‘AA’;

armed-forces-middle-east5

This is all fine when your payment processor doesn’t validate your delivery addresses but Sagepay does. It’s a case of updating the directory_country_region table. Hope this helps someone.