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;
 }
예제 #3
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;
 }