示例#1
0
 /**
  *
  * @return array
  */
 protected function _loadCollection()
 {
     $ret = array();
     foreach (Axis_Payment::getMethods() as $methodCode => $method) {
         $ret[$methodCode] = $method->getTitle();
     }
     return $ret;
 }
示例#2
0
 /**
  *
  * @static
  * @return array
  */
 public static function collect()
 {
     $ret = array();
     foreach (Axis_Payment::getMethods() as $methodCode => $method) {
         $ret[$methodCode] = $method->getTitle();
     }
     return $ret;
 }
示例#3
0
 /**
  * Return additional paymet form
  * @return string
  * @param object|string $payment
  * @param string $template example: 'view', 'form', 'process' etc
  */
 public function paymentForm($paymentCode, $template)
 {
     if ($paymentCode instanceof Axis_Method_Payment_Model_Abstract) {
         $this->view->payment = $paymentCode;
         $paymentCode = $this->view->payment->getCode();
     } else {
         $this->view->payment = Axis_Payment::getMethod($paymentCode);
     }
     $shortPath = 'payment' . str_replace('_', '/', strtolower($paymentCode)) . '/' . $template . '.phtml';
     $fallbackList = array_unique(array($this->view->templateName, 'fallback', 'default'));
     foreach ($fallbackList as $fallback) {
         $templatePath = $this->view->path . '/app/design/' . $this->view->area . '/' . $fallback . '/templates';
         if (is_readable($templatePath . '/' . $shortPath)) {
             return $this->view->render($shortPath);
         }
     }
     return '';
 }
示例#4
0
 public function listAction()
 {
     $this->_helper->layout->disableLayout();
     $countryId = (int) $this->_getParam('country_id', 0);
     $zoneId = (int) $this->_getParam('zone_id', 0);
     $quantity = (double) $this->_getParam('quantity', 0);
     $weight = (double) $this->_getParam('weight', 0);
     $subtotal = (double) $this->_getParam('subtotal', 0);
     $shippingMethodCode = $this->_getParam('shipping_method_code', null);
     if (empty($shippingMethodCode)) {
         $shippingMethodCode = null;
     }
     $request = array('boxes' => 1, 'qty' => $quantity, 'weight' => $weight, 'price' => $subtotal, 'shipping_method_code' => $shippingMethodCode);
     $request['country'] = Axis::model('location/country')->find($countryId)->current()->toArray();
     $request['zone'] = Axis::model('location/zone')->find($zoneId)->current()->toArray();
     $allowedMethods = Axis_Payment::getAllowedMethods($request);
     $data = array();
     foreach ($allowedMethods['methods'] as $method) {
         $data[] = array('code' => $method['code'], 'name' => $method['title'], 'form' => $this->view->paymentForm($method['code'], 'form'));
     }
     return $this->_helper->json->setData($data)->sendSuccess();
 }
示例#5
0
 /**
  *
  * @param $request shipping request
  * @return bool
  */
 public function isAllowed($request)
 {
     if (!empty($this->_config->minOrderTotal) && $request['price'] < $this->_config->minOrderTotal) {
         return false;
     }
     if (!empty($this->_config->maxOrderTotal) && $request['price'] > $this->_config->maxOrderTotal) {
         return false;
     }
     if (empty($this->_config->geozone) || !intval($this->_config->geozone)) {
         return true;
     }
     if (null !== $request['payment_method_code']) {
         $payment = Axis_Payment::getMethod($request['payment_method_code']);
         $disallowedShippingMethods = $payment->config()->shippings->toArray();
         if (in_array($this->getCode(), $disallowedShippingMethods)) {
             return false;
         }
     }
     if (empty($request['country']['id'])) {
         return true;
     }
     $zoneId = null;
     if (isset($request['zone']['id'])) {
         $zoneId = $request['zone']['id'];
     }
     return Axis::single('location/geozone_zone')->inGeozone($this->_config->geozone, $request['country']['id'], $zoneId);
 }
示例#6
0
 /**
  *
  * @param string $method
  * @param Axis_Sales_Model_Order_Row $order
  * @return mixed bool
  */
 protected function _paymentCallback($method, $order)
 {
     return Axis_Payment::getMethod($order->payment_method_code)->{$method}($order);
 }
示例#7
0
 /**
  * Updates shopping cart totals, available shipping and payment methods
  * Unset shipping and payment methods if needed
  */
 public function updateShoppingCartAction()
 {
     $this->_helper->layout->disableLayout();
     $checkout = $this->_getCheckout();
     $cart = Axis::single('checkout/cart');
     foreach ($this->_getParam('quantity') as $itemId => $quantity) {
         $cart->updateItem($itemId, $quantity);
     }
     $products = $checkout->getCart()->getProducts();
     if (!count($products)) {
         return $this->_helper->json->sendSuccess(array('redirect' => $this->view->href('checkout/cart', true)));
     }
     $shippingMethods = Axis_Shipping::getAllowedMethods($checkout->getShippingRequest());
     $paymentMethods = Axis_Payment::getAllowedMethods($checkout->getPaymentRequest());
     $this->view->checkout = array('shipping_methods' => $shippingMethods, 'payment_methods' => $paymentMethods, 'products' => $products, 'totals' => $checkout->getTotal()->getCollects(), 'total' => $checkout->getTotal()->getTotal());
     return $this->_helper->json->sendSuccess(array('sections' => $this->_renderSections(array('shopping-cart', 'shipping-method', 'payment-method'))));
 }
示例#8
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);
 }