示例#1
0
 private function getPaymentMethods()
 {
     $this->loadLanguageFile('backend/Settings');
     $this->application->loadLanguageFiles();
     $handlers = array();
     foreach (array_merge($this->application->getPaymentHandlerList(true), array($this->config->get('CC_HANDLER')), $this->application->getExpressPaymentHandlerList(true)) as $class) {
         $handlers[$class] = $this->translate($class);
     }
     foreach (OfflineTransactionHandler::getEnabledMethods() as $offline) {
         $handlers[$offline] = OfflineTransactionHandler::getMethodName($offline);
     }
     return $handlers;
 }
 public function getFields()
 {
     $app = ActiveRecordModel::getApplication();
     $app->loadLanguageFile('backend/Settings');
     $app->loadLanguageFiles();
     $config = $app->getConfig();
     $handlers = array();
     foreach (array_merge($app->getPaymentHandlerList(true), array($config->get('CC_HANDLER')), $app->getExpressPaymentHandlerList(true)) as $class) {
         $handlers[$class] = $app->translate($class);
     }
     foreach (OfflineTransactionHandler::getEnabledMethods() as $offline) {
         $handlers[$offline] = OfflineTransactionHandler::getMethodName($offline);
     }
     return array(array('type' => 'select', 'label' => '_payment_method', 'name' => 'method', 'options' => $handlers));
 }
示例#3
0
 public function index()
 {
     $nodes = array();
     foreach (EavField::getEavClasses() as $class => $id) {
         $nodes[] = array('ID' => $id, 'name' => $this->translate($class));
     }
     // get offline payment methods
     $offlineMethods = array();
     foreach (OfflineTransactionHandler::getEnabledMethods() as $method) {
         $id = substr($method, -1);
         $offlineMethods[] = array('ID' => $method, 'name' => $this->config->get('OFFLINE_NAME_' . $id));
     }
     if ($offlineMethods) {
         $nodes[] = array('ID' => 'offline methods', 'name' => $this->translate('_offline_methods'), 'sub' => $offlineMethods);
     }
     return new ActionResponse('nodes', $nodes);
 }
示例#4
0
 public function setOfflineHandler($method)
 {
     $this->setData('handler', OfflineTransactionHandler::getMethodName($method));
     $this->setData('handlerID', $method);
 }
示例#5
0
 /**
  *  Creates an array representation of the shopping cart
  */
 public function toArray($options = array())
 {
     $currency = $this->getCurrency();
     $id = $currency->getID();
     if (is_array($this->orderedItems)) {
         foreach ($this->orderedItems as $item) {
             if (!$item->getProduct()->isPricingLoaded()) {
                 if (!isset($products)) {
                     $products = new ARSet();
                 }
                 $products->unshift($item->getProduct());
             }
         }
     }
     $array = parent::toArray();
     $array['cartItems'] = array();
     $array['wishListItems'] = array();
     if (is_array($this->orderedItems)) {
         foreach ($this->orderedItems as $item) {
             if ($item->isSavedForLater->get()) {
                 $array['wishListItems'][] = $item->toArray();
             } else {
                 $array['cartItems'][] = $item->toArray();
             }
         }
     }
     $array['basketCount'] = $this->getShoppingCartItemCount();
     $array['wishListCount'] = $this->getWishListItemCount();
     // shipments
     $array['shipments'] = array();
     if ($this->shipments) {
         foreach ($this->shipments as $shipment) {
             if (count($shipment->getItems())) {
                 $array['shipments'][] = $shipment->toArray();
             }
         }
     }
     // total for all currencies
     $total = array();
     $total[$id] = $this->getTotal();
     // taxes
     $array['taxes'] = $taxAmount = array();
     $taxAmount[$id] = 0;
     $array['taxes'][$id] = array();
     foreach ($this->taxes as $taxId => $amount) {
         if ($amount > 0) {
             $taxAmount[$id] += $amount;
             $tax = Tax::getInstanceById($taxId)->toArray();
             $tax['amount'] = $amount;
             $tax['formattedAmount'] = $currency->getFormattedPrice($amount);
             $array['taxes'][$id][] = $tax;
         }
     }
     $array['taxAmount'] = $taxAmount[$id];
     foreach ($this->taxDetails as &$taxRate) {
         $taxRate['formattedAmount'] = $currency->getFormattedPrice($taxRate['amount']);
     }
     $array['taxDetails'] = $this->taxDetails;
     $array['total'] = $total;
     $array['formattedTotal'] = $array['formattedTotalBeforeTax'] = array();
     if (is_array($array['total'])) {
         foreach ($array['total'] as $id => $amount) {
             if (!isset($taxAmount[$id])) {
                 $taxAmount[$id] = 0;
             }
             $array['formattedTotalBeforeTax'][$id] = $currency->getFormattedPrice($amount - $taxAmount[$id]);
             $array['formattedTotal'][$id] = $currency->getFormattedPrice($amount);
         }
     }
     // order type
     $array['isShippingRequired'] = (int) $this->isShippingRequired();
     // status
     $array['isReturned'] = (int) $this->isReturned();
     $array['isShipped'] = (int) $this->isShipped();
     $array['isAwaitingShipment'] = (int) $this->isAwaitingShipment();
     $array['isProcessing'] = (int) $this->isProcessing();
     // payments
     if (isset($options['payments'])) {
         $array['amountPaid'] = $this->getPaidAmount();
         $array['amountNotCaptured'] = $array['amountPaid'] - $array['capturedAmount'];
         if ($array['amountNotCaptured'] < 0) {
             $array['amountNotCaptured'] = 0;
         }
         $array['amountDue'] = $array['totalAmount'] - $array['amountPaid'];
         if ($array['amountDue'] < 0) {
             $array['amountDue'] = 0;
         }
     }
     // items subtotal
     $array['itemSubtotal'] = $array['itemDisplayPriceTotal'] = $array['itemSubtotalWithoutTax'] = 0;
     foreach ($this->getOrderedItems() as $item) {
         $array['itemSubtotal'] += $item->getSubtotal(true);
         $array['itemSubtotalWithoutTax'] += $item->getSubtotal(false);
         $array['itemDisplayPriceTotal'] += $item->getDisplayPrice($currency) * $item->count->get();
     }
     $array['itemDiscount'] = $array['itemDisplayPriceTotal'] - $array['itemSubtotal'];
     $array['itemDiscountReverse'] = $array['itemDiscount'] * -1;
     // shipping subtotal
     $array['shippingSubtotal'] = null;
     $array['shippingSubtotalWithoutTax'] = null;
     if ($this->shipments) {
         foreach ($this->shipments as $shipment) {
             $shipmentShipping = $shipment->getShippingTotalWithTax();
             if (!is_null($shipmentShipping)) {
                 $array['shippingSubtotal'] += $shipment->getShippingTotalWithTax();
                 $array['shippingSubtotalWithoutTax'] += $shipment->getShippingTotalBeforeTax();
             }
         }
     }
     $array['subtotalBeforeTaxes'] = $array['itemSubtotalWithoutTax'] + $array['shippingSubtotalWithoutTax'];
     foreach (array('amountPaid', 'amountNotCaptured', 'amountDue', 'itemSubtotal', 'shippingSubtotal', 'shippingSubtotalWithoutTax', 'subtotalBeforeTaxes', 'totalAmount', 'itemDiscountReverse', 'itemDiscount', 'itemSubtotalWithoutTax') as $key) {
         if (isset($array[$key])) {
             $array['formatted_' . $key] = $currency->getFormattedPrice($array[$key]);
         }
     }
     // discounts
     $array['discountAmount'] = 0;
     foreach (array_merge($this->fixedDiscounts, $this->orderDiscounts) as $key => $discount) {
         $array['discounts'][$discount->getID() ? $discount->getID() : $key] = $discount->toArray();
         $array['discountAmount'] -= $discount->amount->get();
     }
     // percentage discount applied to finalized order
     if (!$array['discountAmount'] && $array['isFinalized'] && $array['subtotalBeforeTaxes'] > $array['totalAmount']) {
         $array['discountAmount'] = $array['totalAmount'] - $array['subtotalBeforeTaxes'] - $array['taxAmount'];
     }
     $array['formatted_discountAmount'] = $this->getCurrency()->getFormattedPrice($array['discountAmount']);
     // coupons
     if (!is_null($this->coupons)) {
         $array['coupons'] = $this->coupons->toArray();
     }
     if (!$array['isFinalized']) {
         //$this->isRulesProcessed = false;
         $isOrderable = $this->isOrderable();
         if ($isOrderable instanceof OrderException) {
             $array['error'] = $isOrderable->toArray();
         }
         $array['isOrderable'] = !$isOrderable instanceof OrderException && $isOrderable;
         $array['isShippingSelected'] = $this->isShippingSelected();
         $array['isAddressSelected'] = $this->shippingAddress->get() && $this->billingAddress->get();
     }
     // otherwise left empty on payment page for some reason...
     if ($this->billingAddress->get()) {
         $array['BillingAddress'] = $this->billingAddress->get()->toArray();
     }
     $array['paymentMethod'] = $this->paymentMethod;
     if ($array['paymentMethod']) {
         $array['paymentMethodName'] = substr($array['paymentMethod'], 0, 7) == 'OFFLINE' ? OfflineTransactionHandler::getMethodName($array['paymentMethod']) : ActiveRecordModel::getApplication()->translate($array['paymentMethod']);
     }
     $this->setArrayData($array);
     return $array;
 }
示例#6
0
 /**
  *	@role login
  */
 public function payOffline()
 {
     ActiveRecordModel::beginTransaction();
     $method = $this->request->get('id');
     if (!OfflineTransactionHandler::isMethodEnabled($method) || !$this->getOfflinePaymentValidator($method)->isValid()) {
         return new ActionRedirectResponse('checkout', 'pay');
     }
     $order = $this->order;
     $this->order->setPaymentMethod($method);
     $response = $this->finalizeOrder();
     $transaction = Transaction::getNewOfflineTransactionInstance($order, 0);
     $transaction->setOfflineHandler($method);
     $transaction->save();
     $eavObject = EavObject::getInstance($transaction);
     $eavObject->setStringIdentifier($method);
     $eavObject->save();
     $transaction->getSpecification()->loadRequestData($this->request);
     $transaction->save();
     ActiveRecordModel::commit();
     return $response;
 }
示例#7
0
 private function appendOfflineTransactionData($transactions)
 {
     foreach ($transactions as &$transaction) {
         if ($transaction['methodType'] == Transaction::METHOD_OFFLINE) {
             if ($this->availableOfflinePaymentMethods === null) {
                 $this->availableOfflinePaymentMethods = array();
                 foreach (OfflineTransactionHandler::getEnabledMethods() as $methodID) {
                     $this->availableOfflinePaymentMethods[] = array('ID' => $methodID, 'name' => OfflineTransactionHandler::getMethodName($methodID));
                 }
             }
             if (isset($transaction['serializedData'], $transaction['serializedData']['handlerID'])) {
                 $transaction['handlerID'] = $transaction['serializedData']['handlerID'];
             }
             $transaction['availableOfflinePaymentMethods'] = $this->availableOfflinePaymentMethods;
         }
     }
     return $transactions;
 }