public function test_convertLegacyOption_converts_two_options_specified_as_one()
 {
     $newOption = new PaymentOption();
     $newOption->setCallToActionText('Pay by bankwire')->setLogo('http://example.com/logo.png')->setAction('http://example.com/submit')->setMethod('POST')->setForm(null)->setInputs(array('key' => 42));
     $singleLegacyOption = array('cta_text' => 'Pay by bankwire', 'logo' => 'http://example.com/logo.png', 'action' => 'http://example.com/submit', 'method' => 'POST', 'form' => null, 'inputs' => array('key' => 42));
     $legacyOption = array($singleLegacyOption, $singleLegacyOption);
     $this->assertEquals(array($newOption, $newOption), PaymentOption::convertLegacyOption($legacyOption));
 }
 /**
  * Legacy options were specified this way:
  * - either an array with a top level property 'cta_text'
  * 	and then the other properties
  * - or a numerically indexed array or arrays as described above
  * Since this was a mess, this method is provided to convert them.
  * It takes as input a legacy option (in either form) and always
  * returns an array of instances of Core_Business_Payment_PaymentOption
  */
 public static function convertLegacyOption(array $legacyOption)
 {
     if (!$legacyOption) {
         return;
     }
     if (array_key_exists('cta_text', $legacyOption)) {
         $legacyOption = array($legacyOption);
     }
     $newOptions = array();
     $defaults = array('action' => null, 'form' => null, 'method' => null, 'inputs' => array(), 'logo' => null);
     foreach ($legacyOption as $option) {
         $option = array_merge($defaults, $option);
         $newOption = new Core_Business_Payment_PaymentOption();
         $newOption->setCallToActionText($option['cta_text'])->setAction($option['action'])->setForm($option['form'])->setInputs($option['inputs'])->setLogo($option['logo'])->setMethod($option['method']);
         $newOptions[] = $newOption;
     }
     return $newOptions;
 }
 public function hookAdvancedPaymentOptions($param)
 {
     $legacyOptions = Hook::exec('displayPaymentEU', array(), null, true);
     $newOptions = array();
     Media::addJsDef(array('aeuc_tos_err_str' => Tools::htmlentitiesUTF8($this->l('You must agree to our Terms of Service before going any further!', 'advancedeucompliance'))));
     Media::addJsDef(array('aeuc_submit_err_str' => Tools::htmlentitiesUTF8($this->l('Something went wrong. If the problem persists, please contact us.', 'advancedeucompliance'))));
     Media::addJsDef(array('aeuc_no_pay_err_str' => Tools::htmlentitiesUTF8($this->l('Select a payment option first.', 'advancedeucompliance'))));
     Media::addJsDef(array('aeuc_virt_prod_err_str' => Tools::htmlentitiesUTF8($this->l('Please check "Revocation of virtual products" box first !', 'advancedeucompliance'))));
     if ($legacyOptions) {
         foreach ($legacyOptions as $module_name => $legacyOption) {
             if (!$legacyOption) {
                 continue;
             }
             foreach (Core_Business_Payment_PaymentOption::convertLegacyOption($legacyOption) as $option) {
                 $option->setModuleName($module_name);
                 $to_be_cleaned = $option->getForm();
                 if ($to_be_cleaned) {
                     $cleaned = str_replace('@hiddenSubmit', '', $to_be_cleaned);
                     $option->setForm($cleaned);
                 }
                 $newOptions[] = $option;
             }
         }
         return $newOptions;
     }
     return null;
 }
Example #4
0
 public function hookAdvancedPaymentOptions($params)
 {
     if (!$this->active) {
         return;
     }
     if (!$this->checkCurrency($params['cart'])) {
         return;
     }
     $options = array();
     $paysystems = $this->getPaySystems($params);
     foreach ($paysystems as $paysystem) {
         $po = new Core_Business_Payment_PaymentOption();
         $po->setCallToActionText($paysystem['name'])->setAction($this->context->link->getModuleLink($this->name, 'payment', array('id_universalpay_system' => $paysystem['id_universalpay_system']), true))->setLogo(Media::getMediaPath(_PS_IMG_ . 'pay/' . $paysystem['id_universalpay_system'] . '.jpg'))->setModuleName($this->name);
         $options[] = $po;
     }
     return $options;
 }