/**
  * @param Mage_Sales_Model_Quote $quote
  * @param $bankcountry
  * @param $bankaccount
  * @param $bankcode
  * @param $bic
  * @param $iban
  * @return \Payone_Api_Request_ManageMandate
  */
 public function mapByQuote(Mage_Sales_Model_Quote $quote, $bankcountry, $bankaccount, $bankcode, $bic, $iban)
 {
     $paymentConfig = $this->getPaymentConfig();
     $helper = $this->helper();
     $request = $this->getFactory()->getRequestManagementManageMandate();
     // common parameters
     $request->setMid($paymentConfig->getMid());
     $request->setPortalid($paymentConfig->getPortalid());
     $request->setKey($paymentConfig->getKey());
     $request->setMode($paymentConfig->getMode());
     $request->setRequest(Payone_Api_Enum_RequestType::MANAGEMANDATE);
     $request->setEncoding('UTF-8');
     $request->setIntegratorName('Magento');
     $request->setIntegratorVersion($helper->getMagentoVersion());
     $request->setSolutionName('votum');
     $request->setSolutionVersion($helper->getPayoneVersion());
     // special parameters
     $request->setAid($paymentConfig->getAid());
     $request->setClearingtype(Payone_Enum_ClearingType::DEBITPAYMENT);
     // only allowed for debit_payment
     $request->setCurrency($quote->getQuoteCurrencyCode());
     $request->setPersonalData($this->mapPersonalData($quote));
     $request->setPayment($this->mapBankData($bankcountry, $bankaccount, $bankcode, $bic, $iban));
     if ($paymentConfig->getCurrencyConvert()) {
         $request->setCurrency($quote->getBaseCurrencyCode());
     }
     return $request;
 }
示例#2
0
 /**
  * Convert quote model to order model
  *
  * @param   Mage_Sales_Model_Quote $quote
  * @return  Mage_Sales_Model_Order
  */
 public function toOrder(Mage_Sales_Model_Quote $quote, $order = null)
 {
     if (!$order instanceof Mage_Sales_Model_Order) {
         $order = Mage::getModel('sales/order');
     }
     /* @var $order Mage_Sales_Model_Order */
     $order->setStoreId($quote->getStoreId())->setQuoteId($quote->getId())->setRemoteIp($quote->getRemoteIp())->setCustomerId($quote->getCustomerId())->setCustomerEmail($quote->getCustomerEmail())->setCustomerFirstname($quote->getCustomerFirstname())->setCustomerLastname($quote->getCustomerLastname())->setCustomerGroupId($quote->getCustomerGroupId())->setCustomerTaxClassId($quote->getCustomerTaxClassId())->setCustomerNote($quote->getCustomerNote())->setCustomerNoteNotify($quote->getCustomerNoteNotify())->setCustomerIsGuest($quote->getCustomerIsGuest())->setBaseCurrencyCode($quote->getBaseCurrencyCode())->setStoreCurrencyCode($quote->getStoreCurrencyCode())->setOrderCurrencyCode($quote->getQuoteCurrencyCode())->setStoreToBaseRate($quote->getStoreToBaseRate())->setStoreToOrderRate($quote->getStoreToQuoteRate())->setCouponCode($quote->getCouponCode())->setGiftcertCode($quote->getGiftcertCode())->setIsVirtual($quote->getIsVirtual())->setIsMultiPayment($quote->getIsMultiPayment())->setAppliedRuleIds($quote->getAppliedRuleIds());
     Mage::dispatchEvent('sales_convert_quote_to_order', array('order' => $order, 'quote' => $quote));
     return $order;
 }
 /**
  * Returns the currency compliant to ISO 4217 (3 char code)
  * @return string 3 Character long currency code
  *
  * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order|Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $object
  * @return string
  */
 public function getCurrency($object)
 {
     $currency = $object->getBaseCurrencyCode();
     if (!Mage::helper('paymill/optionHelper')->isBaseCurrency()) {
         if ($object instanceof Mage_Sales_Model_Quote) {
             $currency = $object->getQuoteCurrencyCode();
         } else {
             $currency = $object->getOrderCurrencyCode();
         }
     }
     return $currency;
 }
 /**
  * @param Mage_Sales_Model_Quote $quote
  */
 public function mapExpressCheckoutParameters($quote, $workOrderId = null)
 {
     $request = $this->getRequest();
     $this->mapDefaultParameters($request);
     $paydata = new Payone_Api_Request_Parameter_Paydata_Paydata();
     if (null === $workOrderId) {
         $paydata->addItem(new Payone_Api_Request_Parameter_Paydata_DataItem(array('key' => 'action', 'data' => Payone_Api_Enum_GenericpaymentAction::PAYPAL_ECS_SET_EXPRESSCHECKOUT)));
     } else {
         $paydata->addItem(new Payone_Api_Request_Parameter_Paydata_DataItem(array('key' => 'action', 'data' => Payone_Api_Enum_GenericpaymentAction::PAYPAL_ECS_GET_EXPRESSCHECKOUTDETAILS)));
         $request->setWorkorderId($workOrderId);
     }
     $request->setPaydata($paydata);
     $request->setAid($this->getConfigPayment()->getAid());
     $request->setClearingtype(Payone_Enum_ClearingType::WALLET);
     $request->setAmount($quote->getGrandTotal());
     $request->setCurrency($quote->getQuoteCurrencyCode());
     $request->setWallet(new Payone_Api_Request_Parameter_Authorization_PaymentMethod_Wallet(array('wallettype' => Payone_Api_Enum_WalletType::PAYPAL_EXPRESS, 'successurl' => Mage::helper('payone_core/url')->getMagentoUrl('*/*/return'), 'errorurl' => Mage::helper('payone_core/url')->getMagentoUrl('*/*/error'), 'backurl' => Mage::helper('payone_core/url')->getMagentoUrl('*/*/cancel'))));
     return $request;
 }
示例#5
0
 /**
  * Get Shopping Cart XML
  * @param Mage_Sales_Model_Quote $quote
  * @return string
  */
 public function getShoppingCartXML($quote)
 {
     $dom = new DOMDocument('1.0', 'utf-8');
     $ShoppingCart = $dom->createElement('ShoppingCart');
     $dom->appendChild($ShoppingCart);
     $ShoppingCart->appendChild($dom->createElement('CurrencyCode', $quote->getQuoteCurrencyCode()));
     $ShoppingCart->appendChild($dom->createElement('Subtotal', (int) (100 * $quote->getGrandTotal())));
     // Add Order Lines
     $items = $quote->getAllVisibleItems();
     /** @var $item Mage_Sales_Model_Quote_Item */
     foreach ($items as $item) {
         $product = $item->getProduct();
         $ShoppingCartItem = $dom->createElement('ShoppingCartItem');
         $ShoppingCartItem->appendChild($dom->createElement('Description', $item->getName()));
         $ShoppingCartItem->appendChild($dom->createElement('Quantity', (int) $item->getQty()));
         $ShoppingCartItem->appendChild($dom->createElement('Value', (int) bcmul($product->getFinalPrice(), 100)));
         $ShoppingCartItem->appendChild($dom->createElement('ImageURL', $product->getThumbnailUrl()));
         // NOTE: getThumbnailUrl is DEPRECATED!
         $ShoppingCart->appendChild($ShoppingCartItem);
     }
     return str_replace("\n", '', $dom->saveXML());
 }
示例#6
0
 /**
  * Recalculate amount to store currency
  *
  * @param float $amount
  * @param Mage_Sales_Model_Quote $quote
  * @return float
  */
 protected function _reCalculateToStoreCurrency($amount, $quote)
 {
     if ($quote->getQuoteCurrencyCode() != $quote->getBaseCurrencyCode()) {
         $amount = $amount * $quote->getStoreToQuoteRate();
         $amount = Mage::app()->getStore()->roundPrice($amount);
     }
     return $amount;
 }
 /**
  * process specific amount types into negative-value line item
  * payloads
  *
  * @param Mage_Sales_Model_Quote
  * @param ILineItemIterable
  * @return self
  */
 protected function processNegativeLineItems(Mage_Sales_Model_Quote $quote, ILineItemIterable $lineItems)
 {
     $negativeAmountTypes = array('discount', 'giftcardaccount', 'ebayenterprise_giftcard');
     $currencyCode = $quote->getQuoteCurrencyCode();
     foreach ($negativeAmountTypes as $totalType) {
         $totalAmount = $this->getTotal($totalType, $quote);
         if ($totalAmount) {
             // ensure all amounts are negative
             $totalAmount = -abs($totalAmount);
             $lineItem = $lineItems->getEmptyLineItem();
             $lineItem->setName($this->helper->__($totalType))->setSequenceNumber($totalType)->setQuantity(1)->setUnitAmount($totalAmount)->setCurrencyCode($currencyCode);
             $lineItems->offsetSet($lineItem, null);
         }
     }
     return $this;
 }
示例#8
0
 /**
  * @param Mage_Sales_Model_Quote $quote
  *
  * @return bool
  */
 protected function _isAvailableRatePay($quote)
 {
     $currencies = explode(',', $this->getConfigData('currencies'));
     if (!in_array($quote->getQuoteCurrencyCode(), $currencies)) {
         return false;
     }
     $dob = $quote->getCustomerDob();
     $minAge = (int) $this->getConfigData('min_age');
     //we only need to check the dob if it's set. Else we ask for dob on payment selection page.
     if ($dob) {
         $dobObject = new DateTime($dob);
         $currentYear = date('Y');
         $currentMonth = date('m');
         $currentDay = date('d');
         $ageCheckDate = $currentYear - $minAge . '-' . $currentMonth . '-' . $currentDay;
         $ageCheckObject = new DateTime($ageCheckDate);
         if ($ageCheckObject < $dobObject) {
             return false;
         }
     }
     if ($quote->hasVirtualItems()) {
         return false;
     }
     if (!$this->compareAddresses($quote)) {
         return false;
     }
     return parent::isAvailable($quote);
 }
 /**
  * Set data from the quote into the request payload. This should only be
  * data that comes only from the quote, such as quote currency.
  *
  * @return self
  */
 protected function _injectQuoteData()
 {
     $this->_payload->setCurrency($this->_quote->getQuoteCurrencyCode())->setVatInclusivePricingFlag($this->_taxConfig->vatInclusivePricingFlag)->setCustomerTaxId($this->_quote->getCustomerTaxvat());
     return $this;
 }
示例#10
0
 /**
  * @param Mage_Sales_Model_Quote $quote
  *
  * @return Bronto_Common_Model_Email_Template_Filter
  */
 protected function _filterQuote(Mage_Sales_Model_Quote $quote)
 {
     if (!in_array('quote', $this->_filteredObjects)) {
         $this->setStoreId($quote->getStoreId());
         $currencyCode = $quote->getQuoteCurrencyCode();
         if (Mage::helper('bronto_common')->displayPriceIncTax($quote->getStoreId())) {
             $totals = $quote->getTotals();
             $this->setField('subtotal', $this->formatPrice($totals['subtotal']->getValue(), $currencyCode));
             $this->setField('grandTotal', $this->formatPrice($totals['grand_total']->getValue(), $currencyCode));
         } else {
             $this->setField('subtotal', $this->formatPrice($quote->getSubtotal(), $currencyCode));
             $this->setField('grandTotal', $this->formatPrice($quote->getGrandTotal(), $currencyCode));
         }
         $index = 1;
         foreach ($quote->getAllItems() as $item) {
             if (!$item->getParentItem()) {
                 $this->_filterQuoteItem($item, $index);
                 $index++;
             }
         }
         // Add Related Content
         $this->_items = $quote->getAllItems();
         $queryParams = $this->getQueryParams();
         $queryParams['id'] = urlencode(base64_encode(Mage::helper('core')->encrypt($quote->getId())));
         if ($store = $this->getStore()) {
             $this->setField('quoteURL', $store->getUrl('reminder/load/index', $queryParams));
         } else {
             $this->setField('quoteURL', Mage::getUrl('reminder/load/index', $queryParams));
         }
         // Setup quote items as a template
         if (class_exists('Bronto_Reminder_Block_Cart_Items', false)) {
             $layout = Mage::getSingleton('core/layout');
             /* @var $items Mage_Sales_Block_Items_Abstract */
             $items = $layout->createBlock('bronto/bronto_reminder_cart_items', 'items');
             $items->setTemplate('bronto/reminder/items.phtml');
             $items->setQuote($item->getQuote());
             $this->_respectDesignTheme();
             $this->setField("cartItems", $items->toHtml());
         }
         $this->_filteredObjects[] = 'quote';
     }
     return $this;
 }
示例#11
0
 /**
  * Gets all needed Informations for payment Block of the Request
  *
  * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $object
  * @param float amount
  * @param string $request
  * @return array
  */
 public function getRequestPayment($object, $amount = '', $request = '')
 {
     $paymentMethod = $object->getPayment()->getMethod();
     $payment = array();
     switch ($paymentMethod) {
         case 'ratepay_rechnung':
             $payment['method'] = 'INVOICE';
             break;
         case 'ratepay_rate0':
         case 'ratepay_rate':
             if ($request == 'PAYMENT_REQUEST') {
                 $payment['installmentNumber'] = Mage::getSingleton('ratepaypayment/session')->{'get' . Mage::helper('ratepaypayment')->convertUnderlineToCamelCase($paymentMethod) . 'NumberOfRatesFull'}();
                 $payment['installmentAmount'] = Mage::getSingleton('ratepaypayment/session')->{'get' . Mage::helper('ratepaypayment')->convertUnderlineToCamelCase($paymentMethod) . 'Rate'}();
                 $payment['lastInstallmentAmount'] = Mage::getSingleton('ratepaypayment/session')->{'get' . Mage::helper('ratepaypayment')->convertUnderlineToCamelCase($paymentMethod) . 'LastRate'}();
                 $payment['interestRate'] = Mage::getSingleton('ratepaypayment/session')->{'get' . Mage::helper('ratepaypayment')->convertUnderlineToCamelCase($paymentMethod) . 'InterestRate'}();
                 if ($this->isDynamicDue()) {
                     $payment['paymentFirstDay'] = Mage::getSingleton('ratepaypayment/session')->getRatepayPaymentFirstDay();
                 } else {
                     $payment['paymentFirstDay'] = '28';
                 }
             }
             $payment['method'] = 'INSTALLMENT';
             if (Mage::getSingleton('ratepaypayment/session')->getDirectDebitFlag()) {
                 $payment['debitType'] = 'DIRECT-DEBIT';
             } else {
                 $payment['debitType'] = 'BANK-TRANSFER';
             }
             break;
         case 'ratepay_directdebit':
             $payment['method'] = 'ELV';
             break;
     }
     if ($object instanceof Mage_Sales_Model_Order) {
         $payment['currency'] = $object->getOrderCurrencyCode();
     } else {
         $payment['currency'] = $object->getQuoteCurrencyCode();
     }
     if (is_numeric($amount)) {
         $payment['amount'] = $amount;
     } else {
         $payment['amount'] = $object->getGrandTotal();
     }
     // Ensure that the basket amout is never less than zero
     // In certain cases (i.e. in case of maloperation) the amount can become < 0
     if ($payment['amount'] < 0) {
         $payment['amount'] = 0;
     }
     return $payment;
 }
 /**
  * Place the order
  *
  * @return bool
  */
 protected function _processOrder()
 {
     if (!$this->_auth()) {
         return false;
     }
     if (!$this->_validateQuote()) {
         return false;
     }
     // Push address to the quote, set totals,
     // Convert quote to the order,
     // Set rakuten_order attribute to "1"
     try {
         // To avoid duplicates look for order with the same Rakuten order no
         $orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('ext_order_id', (string) $this->_request->order_no);
         if (count($orders)) {
             $this->_debugData['reason'] = 'The same order already placed';
             return false;
         }
         // Import addresses and other data to quote
         $this->_quote->setIsActive(true)->reserveOrderId();
         $storeId = $this->_quote->getStoreId();
         Mage::app()->setCurrentStore(Mage::app()->getStore($storeId));
         if ($this->_quote->getQuoteCurrencyCode() != $this->_quote->getBaseCurrencyCode()) {
             Mage::app()->getStore()->setCurrentCurrencyCode($this->_quote->getQuoteCurrencyCode());
         }
         $billing = $this->_convertAddress('client');
         $this->_quote->setBillingAddress($billing);
         $shipping = $this->_convertAddress('delivery_address');
         $this->_quote->setShippingAddress($shipping);
         $this->_convertTotals($this->_quote->getShippingAddress());
         $this->_quote->getPayment()->importData(array('method' => 'rakuten'));
         /**
          * Convert quote to order
          *
          * @var $convertQuote Mage_Sales_Model_Convert_Quote
          */
         $convertQuote = Mage::getSingleton('sales/convert_quote');
         /* @var $order Mage_Sales_Model_Order */
         $order = $convertQuote->toOrder($this->_quote);
         if ($this->_quote->isVirtual()) {
             $convertQuote->addressToOrder($this->_quote->getBillingAddress(), $order);
         } else {
             $convertQuote->addressToOrder($this->_quote->getShippingAddress(), $order);
         }
         $order->setExtOrderId((string) $this->_request->order_no);
         $order->setExtCustomerId((string) $this->_request->client->client_id);
         if (!$order->getCustomerEmail()) {
             $order->setCustomerEmail($billing->getEmail())->setCustomerPrefix($billing->getPrefix())->setCustomerFirstname($billing->getFirstname())->setCustomerMiddlename($billing->getMiddlename())->setCustomerLastname($billing->getLastname())->setCustomerSuffix($billing->getSuffix())->setCustomerIsGuest(1);
         }
         $order->setBillingAddress($convertQuote->addressToOrderAddress($this->_quote->getBillingAddress()));
         if (!$this->_quote->isVirtual()) {
             $order->setShippingAddress($convertQuote->addressToOrderAddress($this->_quote->getShippingAddress()));
         }
         /** @var $item Mage_Sales_Model_Quote_Item */
         foreach ($this->_quote->getAllItems() as $item) {
             $orderItem = $convertQuote->itemToOrderItem($item);
             if ($item->getParentItem()) {
                 $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
             }
             $order->addItem($orderItem);
         }
         /**
          * Adding transaction for correct transaction information displaying on the order view in the admin.
          * It has no influence on the API interaction logic.
          *
          * @var $payment Mage_Sales_Model_Order_Payment
          */
         $payment = Mage::getModel('sales/order_payment');
         $payment->setMethod('rakuten')->setTransactionId((string) $this->_request->order_no)->setIsTransactionClosed(false);
         $order->setPayment($payment);
         $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
         $order->setCanShipPartiallyItem(false);
         $message = '';
         if (trim((string) $this->_request->comment_client) != '') {
             $message .= $this->__('Customer\'s Comment: %s', '<strong>' . trim((string) $this->_request->comment_client) . '</strong><br />');
         }
         $message .= $this->__('Rakuten Order No: %s', '<strong>' . (string) $this->_request->order_no . '</strong><br />') . $this->__('Rakuten Client ID: %s', '<strong>' . (string) $this->_request->client->client_id . '</strong><br />');
         $order->addStatusHistoryComment($message);
         $order->setRakutenOrder(1);
         // Custom attribute for fast filtering of orders placed via Rakuten Checkout
         $order->place();
         $order->save();
         //            $order->sendNewOrderEmail();
         $this->_quote->setIsActive(false)->save();
         Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $this->_quote));
     } catch (Exception $e) {
         $this->_debugData['exception'] = $e->getMessage();
         Mage::logException($e);
         return false;
     }
     return true;
 }