paolo@bimodesign.com | +34 608 61 64 10

E-Commerce

        

Magento, Aitoc and skin Adyen movil

After almost hundred post in Italian, I've decided starting to write in english. That's my first post and I'm sorry for the grammatical errors that you'll find here. But it's an IT blog at least and I'm sure you'll excuse me ;)

In this post I'll talk of Magento, that I've started developing since only two mounth.
Currently the Aitoc plugin, that we are using to connect to the Adyen payment platform, allows to configure only one skin. I'll show how to add to add another to configure the movil skin too. These are the steps:

Backend
menu system/config/payment methods, section "Hpp"
Modify the file app/code/community/Madia/Adyen/etc/system.xml adding these code

<skinCodeWap translate="label">
   <label>Skin Code Wap</label>
   <comment>The skin code you want to use (You can find this in the admin are of your Adyen account)</comment>
   <frontend_type>text</frontend_type>
   vsort_order>4</sort_order>
   <show_in_default>1</show_in_default>
   <show_in_website>1</show_in_website>
  <show_in_store>1</show_in_store>
</skinCodeWap>   

Note: I assigned the value 4 to the sort_order parameter, in order to show it at the bottom of the another input value Skin, that we'll use for the web environment. If we assign 4, we'll have to change all the ordinal values of the others inputs form.
We don't need anything else, because Magento will save automatically this value into the core_config_data table. The record will be like this

(426,'default',0,'payment/adyen_hpp/skinCodeWap','hwM2tgIZ')

where hwM2tgIZ is the Adyen skin code, that we'll configure in the Adyen platform.
Note: I'm preparing three posts about Adyen and their excellent payment platform. I'll realease as soon as possible.

Frontend
We need to modify this file app/code/community/Madia/Adyen/Model/Adyen/Hpp.php to allow to choose the WEB or Movil skin, depending which type of device the user is using to browser into our e-commerce application.
a) modify the getFormFields() method in this way

$skinCodeWap = $this->_getConfigData('skinCodeWap', 'adyen_hpp');
...

if ($this->isMobile()) {
    $adyFields['skinCode'] = $skinCodeWap;
} else {
    $adyFields['skinCode'] = $skinCode;
}

b) Modify the all code of the getAdyenSharedUrl() method, to choose which type the Adyen file and environment (test/live) called.

public function getAdyenSharedUrl() {
    $brandCode = $this->getInfoInstance()->getCcType();
    $paymentRoutine = $this->_getConfigData('payment_routines', 'adyen_hpp');
    $isConfigDemoMode = $this->getConfigDataDemoMode();
        
    switch ($isConfigDemoMode) {
        case true:
            if ($this->isMobile()) {
                 $url = "https://test.adyen.com/hpp/select.shtml";
            } else {
                 $url = "https://test.adyen.com/hpp/pay.shtml";
            }

            break;
                
            default:
                   
            if ($this->isMobile()) {
                 $url = "https://live.adyen.com/hpp/select.shtml";
            } else {
                 $url = "https://live.adyen.com/hpp/pay.shtml";
            }
            break;
     }
     ...

c) Finally, adding the method isMobile() to check the movil type.
Note: This code is from an stackoverflow.com post

function isMobile(){  

    $regex_match = "/(nokia|iphone|android|motorola|"
       . "^mot\-|softbank|"
       . "foma|docomo|kddi|up\.browser|up\.link|"  
       . "htc|dopod|blazer|netfront|helio|hosin|"
       . "huawei|novarra|CoolPad|webos|techfaith|palmsource|"  
       . "blackberry|alcatel|amoi|ktouch|nexian|"
       . "samsung|^sam\-|s[cg]h|^lge|"
       . "ericsson|philips|sagem|wellcom|bunjalloo|maui|"  
       . "symbian|smartphone|mmp|midp|wap|phone|windows ce|"
       . "iemobile|^spice|^bird|^zte\-|longcos|"
       . "pantech|gionee|^sie\-|portalmmm|"  
       . "jig\s browser|hiptop|^ucweb|^benq|haier|^lct|"
       . "opera\s*mobi|opera\*mini|320x320|240x320|176x220"  
       . ")/i";  

    if (preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT']))) {  
         return TRUE;  
    }  

    if ((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') > 0) or 
        ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))) {  
         return TRUE;  
    }      

    $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4));  
    $mobile_agents = array(  
       'w3c ','acs-','alav','alca','amoi','audi',
       'avan','benq','bird','blac','blaz','brew',
       'cell','cldc','cmd-','dang','doco','eric',
       'hipt','inno','ipaq','java','jigs','kddi',
       'keji','leno','lg-c','lg-d','lg-g','lge-',  
       'maui','maxo','midp','mits','mmef','mobi',
       'mot-','moto','mwbp','nec-','newt','noki',
       'oper','palm','pana','pant','phil','play',
       'port','prox','qwap','sage','sams','sany',
       'sch-','sec-','send','seri','sgh-','shar',  
       'sie-','siem','smal','smar','sony','sph-',
       'symb','t-mo','teli','tim-','tosh','tsm-',
       'upg1','upsi','vk-v','voda','wap-','wapa',
       'wapi','wapp','wapr','webc','winw','winw',
       'xda ','xda-');  

    if (in_array($mobile_ua,$mobile_agents)) {  
       return TRUE;  
    }  

    if (isset($_SERVER['ALL_HTTP']) && 
        strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini') > 0) {  
       return TRUE;  
    }  

    return FALSE;  
}