When developing a shipping module in Magento, you may need to store sensitive information, such as a Client ID, securely. This can be achieved by marking specific fields as backend_encrypted in your system.xml configuration file. Below is an example of how to set this up:
<client_id translate="label">
<label>Client ID</label>
<frontend_type>obscure</frontend_type>
<backend_model>adminhtml/system_config_backend_encrypted</backend_model>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</client_id>
Once you have configured the field, you might encounter an issue when trying to retrieve the value using $this->getConfigData('client_id');. The returned value will be encrypted, which is not suitable for direct use in API calls, such as those made via cURL.
To resolve this, ensure that your configuration is set up correctly in config.xml as well. You should include the backend_model attribute for the client_id field:
<default>
<carriers>
<your_shipping_method>
<client_id backend_model="adminhtml/system_config_backend_encrypted" />
</your_shipping_method>
</carriers>
</default>
With this setup, Magento will handle the decryption of the value automatically when you call $this->getConfigData('client_id');, allowing you to use the plain text value for your shipping API requests without additional decryption steps.