Exemplo n.º 1
0
 /**
  * Apply Payment method if possible
  *
  * @param mixed $data
  * @return void
  * @throws Axis_Exception
  */
 public function setPaymentMethod($data)
 {
     if (!is_array($data)) {
         $data = array('method' => $data);
     }
     if (empty($data['method'])) {
         return $this->setPaymentMethodCode(null);
     }
     if (!in_array($data['method'], Axis_Payment::getMethodNames())) {
         throw new Axis_Exception(Axis::translate('checkout')->__("'%s' method not found among installed modules", $data['method']));
     }
     $method = Axis_Payment::getMethod($data['method']);
     if (!$method instanceof Axis_Method_Payment_Model_Abstract || !$method->isEnabled() || !$method->isAllowed($this->getPaymentRequest())) {
         throw new Axis_Exception(Axis::translate('checkout')->__('Selected payment method is not allowed'));
     }
     $this->setPaymentMethodCode($data['method']);
     $this->_payment = $method;
     $this->payment()->saveData($data);
 }