21

I'm working on a shipping module. In system.xml I set some fields to be backend_encrypted. Here is the node:

<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>

I need that value to pass using cURL to shipping API but, when I try to retrieve it using $this->getConfigData('client_id');, it come out encrypted.

I was looking in other modules and I see values stored the same but somehow, they manage to get the right value.

Any idea how to get it?

Eddie C.
  • 918
  • 10
  • 16
Ovidiu
  • 2,921
  • 5
  • 28
  • 36

2 Answers2

36

In order to use $this->getConfigData('client_id'); without manually decrypting it, you need to update your config.xml by adding <client_id backend_model="adminhtml/system_config_backend_encrypted" />, see example below

In your config.xml

...
    <default>
        <carriers>
            <magepal>
                ......
                <client_id backend_model="adminhtml/system_config_backend_encrypted" />
            </magepal>
        </carriers>
    </default>
</config>
MagePal Extensions
  • 17,646
  • 2
  • 47
  • 62
  • 2
    Adding this will transparently decrypt the configuration values, which I suppose in 9 out of 10 cases is what is actually wanted. While Tim's solution works, I think this is the more correct answer. – nnevala Jun 27 '13 at 22:34
  • ^^ Whilst the accepted answer 'works', this definitely does seem more 'correct'. – Chris S Jan 08 '15 at 17:06
32

Just use Mage::helper('core')->decrypt($this->getConfigData('client_id'));

user487772
  • 8,800
  • 5
  • 47
  • 72
  • works, thanks. but why I haven't see any reference to decrypt on any other module? And if you can help, I'm using it wrong, where it's not supposed to be? – Ovidiu Dec 20 '11 at 14:39
  • You are doing everything right. If you will search Magento code for "decrypt" you will get plenty of references. – user487772 Dec 20 '11 at 14:44