Example #1
0
 /**
  * @param Mage_Sales_Model_Quote $quote
  * @return Mage_Sales_Model_Order
  * @throws Exception
  */
 public function createNewOrder($quote)
 {
     $convert = Mage::getModel('sales/convert_quote');
     if ($quote->isVirtual()) {
         $this->setOrder($convert->addressToOrder($quote->getBillingAddress()));
     } else {
         $this->setOrder($convert->addressToOrder($quote->getShippingAddress()));
     }
     $this->getOrder()->setBillingAddress($convert->addressToOrderAddress($quote->getBillingAddress()));
     if ($quote->getBillingAddress()->getCustomerAddress()) {
         $this->getOrder()->getBillingAddress()->setCustomerAddress($quote->getBillingAddress()->getCustomerAddress());
     }
     if (!$quote->isVirtual()) {
         $this->getOrder()->setShippingAddress($convert->addressToOrderAddress($quote->getShippingAddress()));
         if ($quote->getShippingAddress()->getCustomerAddress()) {
             $this->getOrder()->getShippingAddress()->setCustomerAddress($quote->getShippingAddress()->getCustomerAddress());
         }
     }
     $this->getOrder()->setPayment($convert->paymentToOrderPayment($quote->getPayment()));
     $this->getOrder()->getPayment()->setTransactionId($quote->getPayment()->getTransactionId());
     foreach ($quote->getAllItems() as $item) {
         /** @var Mage_Sales_Model_Order_Item $item */
         $orderItem = $convert->itemToOrderItem($item);
         if ($item->getParentItem()) {
             $orderItem->setParentItem($this->getOrder()->getItemByQuoteItemId($item->getParentItem()->getId()));
         }
         $this->getOrder()->addItem($orderItem);
     }
     $this->getOrder()->setQuote($quote);
     $this->getOrder()->setExtOrderId($quote->getPayment()->getTransactionId());
     $this->getOrder()->setCanSendNewEmailFlag(false);
     $this->_initTransaction($quote);
     return $this->getOrder();
 }
 /**
  * Retrieve payment method and assign additional template values
  *
  * @return EbayEnterprise_Paypal_Block_Express_Review
  */
 protected function _beforeToHtml()
 {
     $methodInstance = $this->_quote->getPayment()->getMethodInstance();
     $this->setPaymentMethodTitle($methodInstance->getTitle());
     $this->setShippingRateRequired(true);
     if ($this->_quote->getIsVirtual()) {
         $this->setShippingRateRequired(false);
     } else {
         // prepare shipping rates
         $this->_address = $this->_quote->getShippingAddress();
         $groups = $this->_address->getGroupedAllShippingRates();
         if ($groups && $this->_address) {
             $this->setShippingRateGroups($groups);
             // determine current selected code & name
             foreach ($groups as $rates) {
                 foreach ($rates as $rate) {
                     if ($this->_address->getShippingMethod() == $rate->getCode()) {
                         $this->_currentShippingRate = $rate;
                         break 2;
                     }
                 }
             }
         }
         $canEditShippingAddress = $this->_quote->getMayEditShippingAddress() && $this->_quote->getPayment()->getAdditionalInformation(EbayEnterprise_PayPal_Model_Express_Checkout::PAYMENT_INFO_BUTTON) == 1;
         // misc shipping parameters
         $this->setShippingMethodSubmitUrl($this->getUrl("{$this->_paypalActionPrefix}/checkout/saveShippingMethod"))->setCanEditShippingAddress($canEditShippingAddress)->setCanEditShippingMethod($this->_quote->getMayEditShippingMethod());
     }
     $this->setEditUrl($this->getUrl("{$this->_paypalActionPrefix}/checkout/edit"))->setPlaceOrderUrl($this->getUrl("{$this->_paypalActionPrefix}/checkout/placeOrder"));
     return parent::_beforeToHtml();
 }
 /**
  * Retrieve payment method and assign additional template values
  *
  * @return Mage_Paypal_Block_Express_Review
  */
 protected function _beforeToHtml()
 {
     $methodInstance = $this->_quote->getPayment()->getMethodInstance();
     $this->setPaymentMethodTitle($methodInstance->getTitle());
     $this->setShippingRateRequired(true);
     if ($this->_quote->getIsVirtual()) {
         $this->setShippingRateRequired(false);
     } else {
         // prepare shipping rates
         $this->_address = $this->_quote->getShippingAddress();
         $groups = $this->_address->getGroupedAllShippingRates();
         if ($groups && $this->_address) {
             $this->setShippingRateGroups($groups);
             // determine current selected code & name
             foreach ($groups as $code => $rates) {
                 foreach ($rates as $rate) {
                     if ($this->_address->getShippingMethod() == $rate->getCode()) {
                         $this->_currentShippingRate = $rate;
                         break 2;
                     }
                 }
             }
         }
     }
     return parent::_beforeToHtml();
 }
Example #4
0
 /**
  * Retrieve payment method and assign additional template values
  *
  * @return Mage_Paypal_Block_Express_Review
  */
 protected function _beforeToHtml()
 {
     $methodInstance = $this->_quote->getPayment()->getMethodInstance();
     $this->setPaymentMethodTitle($methodInstance->getTitle());
     $this->setUpdateOrderSubmitUrl($this->getUrl("{$this->_paypalActionPrefix}/express/updateOrder"));
     $this->setUpdateShippingMethodsUrl($this->getUrl("{$this->_paypalActionPrefix}/express/updateShippingMethods"));
     $this->setShippingRateRequired(true);
     if ($this->_quote->getIsVirtual()) {
         $this->setShippingRateRequired(false);
     } else {
         // prepare shipping rates
         $this->_address = $this->_quote->getShippingAddress();
         $groups = $this->_address->getGroupedAllShippingRates();
         if ($groups && $this->_address) {
             $this->setShippingRateGroups($groups);
             // determine current selected code & name
             foreach ($groups as $code => $rates) {
                 foreach ($rates as $rate) {
                     if ($this->_address->getShippingMethod() == $rate->getCode()) {
                         $this->_currentShippingRate = $rate;
                         break 2;
                     }
                 }
             }
         }
         // misc shipping parameters
         $this->setShippingMethodSubmitUrl($this->getUrl("{$this->_paypalActionPrefix}/express/saveShippingMethod"))->setCanEditShippingAddress($this->_quote->getMayEditShippingAddress())->setCanEditShippingMethod($this->_quote->getMayEditShippingMethod());
     }
     $this->setEditUrl($this->getUrl("{$this->_paypalActionPrefix}/express/edit"))->setPlaceOrderUrl($this->getUrl("{$this->_paypalActionPrefix}/express/placeOrder"));
     return parent::_beforeToHtml();
 }
Example #5
0
 protected function _placeOrder($checkoutMessage, $orderStatus = 'pending', $notifyCreateOrder = false)
 {
     $this->_quote->collectTotals();
     $this->_quote->reserveOrderId();
     error_reporting(E_ERROR);
     $service = Mage::getModel('sales/service_quote', $this->_quote);
     // If file not exist may catch warring
     error_reporting(E_ALL);
     if ($service != false && method_exists($service, 'submitAll')) {
         // Magento version 1.4.1.x
         //  $service = Mage::getModel('sales/service_quote', $quote);
         $service->submitAll();
         $orderObj = $service->getOrder();
     } else {
         // Magento version 1.4.0.x , 1.3.x
         $convertQuoteObj = Mage::getSingleton('sales/convert_quote');
         $orderObj = $convertQuoteObj->addressToOrder($this->_quote->getShippingAddress());
         $orderObj->setBillingAddress($convertQuoteObj->addressToOrderAddress($this->_quote->getBillingAddress()));
         $orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($this->_quote->getShippingAddress()));
         $orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($this->_quote->getPayment()));
         $items = $this->_quote->getShippingAddress()->getAllItems();
         foreach ($items as $item) {
             //@var $item Mage_Sales_Model_Quote_Item
             $orderItem = $convertQuoteObj->itemToOrderItem($item);
             if ($item->getParentItem()) {
                 $orderItem->setParentItem($orderObj->getItemByQuoteItemId($item->getParentItem()->getId()));
             }
             $orderObj->addItem($orderItem);
         }
         $orderObj->setCanShipPartiallyItem(false);
         $orderObj->place();
     }
     $orderMessages = '';
     $notifyMessages = $this->_processNotifyMessage();
     if ($checkoutMessage || $notifyMessages) {
         $orderMessages .= '<br /><b><u>' . Mage::helper('M2ePro')->__('M2E Pro Notes') . ':</u></b><br /><br />';
         if ($checkoutMessage) {
             $orderMessages .= '<b>' . Mage::helper('M2ePro')->__('Checkout Message From Buyer') . ':</b>';
             $orderMessages .= $checkoutMessage . '<br />';
         }
         if ($notifyMessages) {
             $orderMessages .= $notifyMessages;
         }
     }
     // Adding notification to order
     $orderObj->addStatusToHistory($orderStatus, $orderMessages, false);
     $orderObj->save();
     // --------------------
     Mage::helper('M2ePro/Module')->getConfig()->setGroupValue('/synchronization/orders/', 'current_magento_order_id', $orderObj->getId());
     $this->setFatalErrorHandler();
     // --------------------
     // Send Notification to customer after create order
     if ($notifyCreateOrder) {
         // Send new order E-mail only if select such mode
         $orderObj->sendNewOrderEmail();
     }
     return $orderObj;
 }
Example #6
0
 /**
  * Check whether order review has enough data to initialize
  *
  * @param $token
  * @throws Mage_Core_Exception
  */
 public function prepareOrderReview()
 {
     $payment = $this->_quote->getPayment();
     if (!$payment || !$this->_quote->getCustomerEmail()) {
         Mage::throwException(Mage::helper('sagepaysuite')->__('Payer is not identified.'));
     }
     $this->_ignoreAddressValidation();
     $this->_quote->collectTotals()->save();
 }
Example #7
0
 /**
  * check is new token when checkout
  *
  * @return bool
  */
 protected function _isNewToken()
 {
     $info = $this->_quote->getPayment();
     Mage::helper('ewayrapid')->unserializeInfoInstace($info);
     if ($token = Mage::getSingleton('core/session')->getData('newToken')) {
         Mage::getSingleton('core/session')->unsetData('newToken');
         return true;
     }
     return false;
 }
 /**
  * Preparing order review
  */
 public function prepareOrderReview()
 {
     $payment = $this->_quote->getPayment();
     if (!$payment || !$payment->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_PAYER_ID)) {
         Mage::throwException(Mage::helper('paypal')->__('Payer is not identified.'));
     }
     $this->_quote->setMayEditShippingAddress(1 != $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDEN));
     $this->_quote->setMayEditShippingMethod('' == $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD));
     $this->_ignoreAddressValidation();
     $this->_quote->collectTotals()->save();
 }
Example #9
0
 /**
  * Get the payment fee amount of the payment method that is selected
  *
  * @param Mage_Sales_Model_Quote
  * @return float
  */
 public function getPaymentFeeAmount(Mage_Sales_Model_Quote $quote, $store = null)
 {
     $paymentMethod = $quote->getPayment()->getMethod();
     if ($paymentMethod == 'adyen_openinvoice') {
         return Mage::getStoreConfig('payment/adyen_openinvoice/fee');
     } elseif ($paymentMethod == 'adyen_ideal') {
         return Mage::getStoreConfig('payment/adyen_ideal/fee');
     } elseif (substr($paymentMethod, 0, 10) == 'adyen_hpp_') {
         return $this->getHppPaymentMethodFee($paymentMethod);
     }
     return 0;
 }
 /**
  * Covers app/code/core/Mage/Checkout/Block/Multishipping/Payment/Info.php
  * and app/code/core/Mage/Checkout/Block/Multishipping/Overview.php
  *
  * @magentoDataFixture Mage/Sales/_files/quote.php
  * @magentoDataFixture Mage/Customer/_files/customer.php
  */
 public function testOverviewAction()
 {
     $quote = new Mage_Sales_Model_Quote();
     $quote->load('test01', 'reserved_order_id');
     Mage::getSingleton('Mage_Checkout_Model_Session')->setQuoteId($quote->getId());
     $session = new Mage_Customer_Model_Session();
     $session->login('*****@*****.**', 'password');
     $this->getRequest()->setPost('payment', array('method' => 'checkmo'));
     $this->dispatch('checkout/multishipping/overview');
     $html = $this->getResponse()->getBody();
     $this->assertContains('<p>' . $quote->getPayment()->getMethodInstance()->getTitle() . '</p>', $html);
     $this->assertContains('<span class="price">$10.00</span>', $html);
 }
 /**
  * Place the order and recurring payment profiles when customer returned from paypal
  * Until this moment all quote data must be valid
  *
  * @param string $token
  * @param string $shippingMethodCode
  */
 public function place($token, $shippingMethodCode = null)
 {
     $this->updateShippingMethod($shippingMethodCode);
     $isNewCustomer = $this->_prepareQuote();
     $this->_ignoreAddressValidation();
     $this->_quote->collectTotals();
     $this->_getApi();
     $payerId = $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_PAYER_ID);
     $doExpressReply = $this->_api->doExpressCheckout($this->_quote, $token, $payerId);
     $doAuthorizationReply = $this->_api->doAuthorization($this->_quote);
     $this->_quote->getPayment()->importData(array_merge($doExpressReply, $doAuthorizationReply));
     $service = Mage::getModel('sales/service_quote', $this->_quote);
     try {
         $service->submitAll();
         // Any exceptions thrown from submitAll indicate an order that failed
         // to be created. In any such cases, the payment auth needs to be voided.
     } catch (Exception $e) {
         $this->_api->doVoidQuote($this->_quote);
         // Throw an exception for the controller to handle. Needs to indicate
         // the failure to complete the PayPal payment as the PayPal process
         // needs to be restarted once the auth was performed.
         throw Mage::exception('EbayEnterprise_PayPal', $this->_helper->__(EbayEnterprise_Paypal_Model_Express_Api::EBAYENTERPRISE_PAYPAL_API_FAILED));
     }
     $this->_quote->save();
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (Exception $e) {
             $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e));
         }
     }
     $order = $service->getOrder();
     if (!$order) {
         return;
     }
     switch ($order->getState()) {
         // Even after placement, paypal can disallow authorize/capture
         case Mage_Sales_Model_Order::STATE_PENDING_PAYMENT:
             break;
             // regular placement, when everything is ok
         // regular placement, when everything is ok
         case Mage_Sales_Model_Order::STATE_PROCESSING:
         case Mage_Sales_Model_Order::STATE_COMPLETE:
         case Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW:
             $order->sendNewOrderEmail();
             break;
     }
     $this->_order = $order;
     Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $this->_quote));
 }
Example #12
0
 /**
  * Set create billing agreement flag to api call
  *
  * @return Mage_Paypal_Model_Express_Checkout
  */
 protected function _setBillingAgreementRequest()
 {
     if (!$this->_customerId || $this->_quote->hasNominalItems()) {
         return $this;
     }
     $isRequested = $this->_isBARequested || $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT);
     if (!($this->_config->allow_ba_signup == Mage_Paypal_Model_Config::EC_BA_SIGNUP_AUTO || $isRequested && $this->_config->shouldAskToCreateBillingAgreement())) {
         return $this;
     }
     if (!Mage::getModel('sales/billing_agreement')->needToCreateForCustomer($this->_customerId)) {
         return $this;
     }
     $this->_api->setBillingType($this->_api->getBillingAgreementType());
     return $this;
 }
Example #13
0
 /**
  * Restore
  *
  * @param $quote  Mage_Sales_Model_Quote
  * @param $status string
  * @return bool
  */
 public function restoreCart(Mage_Sales_Model_Quote $quote, $status)
 {
     $storeId = $quote->getStoreId();
     $gatewayMethod = $quote->getPayment()->getMethod();
     $needRestore = false;
     $statuses = array('canceled', 'expired', 'declined', 'void');
     if (Mage::getStoreConfig('payment/msp/keep_cart', $storeId) || Mage::getStoreConfig('msp/settings/keep_cart', $storeId) || $gatewayMethod == 'msp_payafter') {
         $needRestore = true;
     }
     if ($needRestore && in_array($status, $statuses)) {
         $quote->setIsActive(true)->setReservedOrderId(null)->save();
         return true;
     }
     return false;
 }
Example #14
0
 protected function getPaymentSpecificParams(Mage_Sales_Model_Quote $quote)
 {
     $alias = $quote->getPayment()->getAdditionalInformation('alias');
     if (is_null($alias) && $this->getDataHelper()->isAdminSession()) {
         $alias = $this->getAliasHelper()->getAlias($quote);
     }
     $params = array('ALIAS' => $alias);
     if (is_numeric($quote->getPayment()->getAdditionalInformation('cvc'))) {
         $params['CVC'] = $quote->getPayment()->getAdditionalInformation('cvc');
     }
     $requestParams3ds = array();
     if ($this->getConfig()->get3dSecureIsActive() && false == $this->getDataHelper()->isAdminSession()) {
         $requestParams3ds = array('FLAG3D' => 'Y', 'WIN3DS' => Netresearch_OPS_Model_Payment_Abstract::OPS_DIRECTLINK_WIN3DS, 'LANGUAGE' => Mage::app()->getLocale()->getLocaleCode(), 'HTTP_ACCEPT' => '*/*', 'HTTP_USER_AGENT' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)', 'ACCEPTURL' => $this->getConfig()->getAcceptUrl(), 'DECLINEURL' => $this->getConfig()->getDeclineUrl(), 'EXCEPTIONURL' => $this->getConfig()->getExceptionUrl());
     }
     $params = array_merge($params, $requestParams3ds);
     return $params;
 }
Example #15
0
 /**
  * Specify quote payment method
  *
  * @param array $data
  * @return array
  */
 public function savePayment($data)
 {
     if ($this->_quote->isVirtual()) {
         $this->_quote->getBillingAddress()->setPaymentMethod($this->_methodType);
     } else {
         $this->_quote->getShippingAddress()->setPaymentMethod($this->_methodType);
     }
     $payment = $this->_quote->getPayment();
     $data['method'] = $this->_methodType;
     $payment->importData($data);
     $email = isset($data['payer']) ? $data['payer'] : null;
     $payment->setAdditionalInformation(self::PAYMENT_INFO_PAYER_EMAIL, $email);
     $payment->setAdditionalInformation(self::PAYMENT_INFO_TRANSACTION_ID, isset($data['transaction_id']) ? $data['transaction_id'] : null);
     $this->_quote->setCustomerEmail($email);
     $this->_quote->collectTotals()->save();
     return array();
 }
 /**
  * Place the order and recurring payment profiles when customer returned from paypal
  * Until this moment all quote data must be valid
  *
  * @param string $token
  * @param string $shippingMethodCode
  */
 public function place($token, $shippingMethodCode = null)
 {
     $this->updateShippingMethod($shippingMethodCode);
     $isNewCustomer = $this->_prepareQuote();
     $this->_ignoreAddressValidation();
     $this->_quote->collectTotals();
     $this->_getApi();
     $payerId = $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_PAYER_ID);
     $doExpressReply = $this->_api->doExpressCheckout($this->_quote, $token, $payerId);
     $doAuthorizationReply = $this->_api->doAuthorization($this->_quote);
     $this->_quote->getPayment()->importData(array_merge($doExpressReply, $doAuthorizationReply));
     $service = Mage::getModel('sales/service_quote', $this->_quote);
     $service->submitAll();
     $this->_quote->save();
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (Exception $e) {
             $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e));
         }
     }
     $order = $service->getOrder();
     if (!$order) {
         return;
     }
     switch ($order->getState()) {
         // Even after placement, paypal can disallow authorize/capture
         case Mage_Sales_Model_Order::STATE_PENDING_PAYMENT:
             break;
             // regular placement, when everything is ok
         // regular placement, when everything is ok
         case Mage_Sales_Model_Order::STATE_PROCESSING:
         case Mage_Sales_Model_Order::STATE_COMPLETE:
         case Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW:
             $order->sendNewOrderEmail();
             break;
     }
     $this->_order = $order;
     Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $this->_quote));
 }
Example #17
0
 public function render()
 {
     $customer = $this->_getCustomer();
     $this->_quote->setStore($this->_getStore())->setCustomer($customer);
     $this->_quote->getBillingAddress()->importCustomerAddress($customer->getDefaultBillingAddress());
     $this->_quote->getShippingAddress()->importCustomerAddress($customer->getDefaultShippingAddress());
     $productCount = rand(3, 10);
     for ($i = 0; $i < $productCount; $i++) {
         $product = $this->_getRandomProduct();
         if ($product) {
             $product->setQuoteQty(1);
             $this->_quote->addCatalogProduct($product);
         }
     }
     $this->_quote->getPayment()->setMethod('checkmo');
     $this->_quote->getShippingAddress()->setShippingMethod('freeshipping_freeshipping');
     //->collectTotals()->save();
     $this->_quote->getShippingAddress()->setCollectShippingRates(true);
     $this->_quote->collectTotals()->save();
     $this->_quote->save();
     return $this;
 }
Example #18
0
 public function setAliasToActiveAfterUserRegisters(Mage_Sales_Model_Order $order, Mage_Sales_Model_Quote $quote)
 {
     if (true === $quote->getPayment()->getAdditionalInformation('userIsRegistering')) {
         $customerId = $order->getCustomerId();
         $billingAddressHash = $this->generateAddressHash($quote->getBillingAddress());
         $shippingAddressHash = $this->generateAddressHash($quote->getShippingAddress());
         $aliasId = $quote->getPayment()->getAdditionalInformation('opsAliasId');
         if (is_numeric($aliasId) && 0 < $aliasId) {
             $alias = Mage::getModel('ops/alias')->getCollection()->addFieldToFilter('alias', $quote->getPayment()->getAdditionalInformation('alias'))->addFieldToFilter('billing_address_hash', $billingAddressHash)->addFieldToFilter('shipping_address_hash', $shippingAddressHash)->addFieldToFilter('store_id', array('eq' => $quote->getStoreId()))->getFirstItem();
             if ($alias->getState() === Netresearch_OPS_Model_Alias_State::PENDING) {
                 $alias->setState(Netresearch_OPS_Model_Alias_State::ACTIVE);
                 $alias->setCustomerId($customerId);
                 $alias->save();
             }
         }
     }
 }
Example #19
0
 /**
  * Send email id payment was failed
  *
  * @param Mage_Sales_Model_Quote $checkout
  * @param string $message
  * @param string $checkoutType
  * @return Mage_Checkout_Helper_Data
  */
 public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'onepage')
 {
     $translate = Mage::getSingleton('Mage_Core_Model_Translate');
     /* @var $translate Mage_Core_Model_Translate */
     $translate->setTranslateInline(false);
     $mailTemplate = Mage::getModel('Mage_Core_Model_Email_Template');
     /* @var $mailTemplate Mage_Core_Model_Email_Template */
     $template = Mage::getStoreConfig('checkout/payment_failed/template', $checkout->getStoreId());
     $copyTo = $this->_getEmails('checkout/payment_failed/copy_to', $checkout->getStoreId());
     $copyMethod = Mage::getStoreConfig('checkout/payment_failed/copy_method', $checkout->getStoreId());
     if ($copyTo && $copyMethod == 'bcc') {
         $mailTemplate->addBcc($copyTo);
     }
     $_reciever = Mage::getStoreConfig('checkout/payment_failed/reciever', $checkout->getStoreId());
     $sendTo = array(array('email' => Mage::getStoreConfig('trans_email/ident_' . $_reciever . '/email', $checkout->getStoreId()), 'name' => Mage::getStoreConfig('trans_email/ident_' . $_reciever . '/name', $checkout->getStoreId())));
     if ($copyTo && $copyMethod == 'copy') {
         foreach ($copyTo as $email) {
             $sendTo[] = array('email' => $email, 'name' => null);
         }
     }
     $shippingMethod = '';
     if ($shippingInfo = $checkout->getShippingAddress()->getShippingMethod()) {
         $data = explode('_', $shippingInfo);
         $shippingMethod = $data[0];
     }
     $paymentMethod = '';
     if ($paymentInfo = $checkout->getPayment()) {
         $paymentMethod = $paymentInfo->getMethod();
     }
     $items = '';
     foreach ($checkout->getAllVisibleItems() as $_item) {
         /* @var $_item Mage_Sales_Model_Quote_Item */
         $items .= $_item->getProduct()->getName() . '  x ' . $_item->getQty() . '  ' . $checkout->getStoreCurrencyCode() . ' ' . $_item->getProduct()->getFinalPrice($_item->getQty()) . "\n";
     }
     $total = $checkout->getStoreCurrencyCode() . ' ' . $checkout->getGrandTotal();
     foreach ($sendTo as $recipient) {
         $mailTemplate->setDesignConfig(array('area' => Mage_Core_Model_App_Area::AREA_FRONTEND, 'store' => $checkout->getStoreId()))->sendTransactional($template, Mage::getStoreConfig('checkout/payment_failed/identity', $checkout->getStoreId()), $recipient['email'], $recipient['name'], array('reason' => $message, 'checkoutType' => $checkoutType, 'dateAndTime' => Mage::app()->getLocale()->date(), 'customer' => $checkout->getCustomerFirstname() . ' ' . $checkout->getCustomerLastname(), 'customerEmail' => $checkout->getCustomerEmail(), 'billingAddress' => $checkout->getBillingAddress(), 'shippingAddress' => $checkout->getShippingAddress(), 'shippingMethod' => Mage::getStoreConfig('carriers/' . $shippingMethod . '/title'), 'paymentMethod' => Mage::getStoreConfig('payment/' . $paymentMethod . '/title'), 'items' => nl2br($items), 'total' => $total));
     }
     $translate->setTranslateInline(true);
     return $this;
 }
 /**
  * Retrieve the paymentMethod configuration that is used in a quote
  *
  * @param Mage_Sales_Model_Quote $quote
  * @return Payone_Core_Model_Config_Payment_Method_Interface
  * @throws Payone_Core_Exception_PaymentMethodConfigNotFound
  */
 public function getConfigPaymentMethodByQuote(Mage_Sales_Model_Quote $quote)
 {
     $configId = $quote->getPayment()->getData('payone_config_payment_method_id');
     if (!$configId) {
         $message = 'Payment method configuration with id "' . $configId . '" not found.';
         throw new Payone_Core_Exception_PaymentMethodConfigNotFound($message);
     }
     $config = $this->getConfigPaymentMethodById($configId, $quote->getStoreId());
     return $config;
 }
 /**
  * Whether customer is allowed to edit shipping address on order review
  *
  * @return bool
  */
 public function mayEditShippingAddress()
 {
     return 1 != $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDEN);
 }
 public function updateQuotePayment(Adyen_Subscription_Model_Subscription $subscription, Mage_Sales_Model_Quote $quote)
 {
     Mage::dispatchEvent('adyen_subscription_service_updatequotepayment_before', array('subscription' => $subscription, 'quote' => $quote));
     // Set payment method
     $methodInstance = $subscription->getBillingAgreement()->getPaymentMethodInstance();
     if (!method_exists($methodInstance, 'initBillingAgreementPaymentInfo')) {
         Mage::helper('adyen_subscription')->logQuoteCron(sprintf('Payment method %s does not support Adyen_Subscription', $methodInstance->getCode()));
         Adyen_Subscription_Exception::throwException(Mage::helper('adyen_subscription')->__('Payment method %s does not support Adyen_Subscription', $methodInstance->getCode()));
     }
     // Set billing agreement data
     /* @noinspection PhpUndefinedMethodInspection */
     try {
         /* @noinspection PhpUndefinedMethodInspection */
         $methodInstance->initBillingAgreementPaymentInfo($subscription->getBillingAgreement(), $quote->getPayment());
         // importan $quote->save() will not update payment object so use this:
         $quote->getPayment()->save();
         Mage::dispatchEvent('adyen_subscription_service_updatequotepayment_after', array('subscription' => $subscription, 'quote' => $quote));
     } catch (Mage_Core_Exception $e) {
         Mage::helper('adyen_subscription')->logQuoteCron(sprintf('Failed to set billing agreement data %s', $e->getMessage()));
         $subscription->setErrorMessage($e->getMessage());
         $subscription->setStatus($subscription::STATUS_QUOTE_ERROR);
         Mage::getModel('core/resource_transaction')->addObject($quote)->addObject($subscription)->save();
         Mage::dispatchEvent('adyen_subscription_service_updatequotepayment_fail', array('subscription' => $subscription, 'status' => $subscription::STATUS_QUOTE_ERROR, 'error' => $e->getMessage()));
     }
 }
 /**
  * updates the additional information from payment, thats needed for backend reOrders
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param array $params
  */
 public function updateAdditionalInformation(Mage_Sales_Model_Quote $quote, $params)
 {
     if (!is_null($quote->getId()) && $quote->getPayment() && !is_null($quote->getPayment()->getId())) {
         $payment = $quote->getPayment();
         if (array_key_exists('Alias', $params)) {
             $payment->setAdditionalInformation('alias', $params['Alias']);
         }
         if (array_key_exists('Brand', $params)) {
             $payment->setAdditionalInformation('CC_BRAND', $params['Brand']);
         }
         if (array_key_exists('CN', $params)) {
             $payment->setAdditionalInformation('CC_CN', $params['CN']);
         }
         $quote->setPayment($payment)->save();
     }
 }
Example #24
0
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Magento
 * @package     Mage_Paypal
 * @subpackage  integration_tests
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
$quote = new Mage_Sales_Model_Quote();
$quote->load('test01', 'reserved_order_id');
$payment = $quote->getPayment();
$payment->setMethod(Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS);
$payment->setAdditionalInformation(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_PAYER_ID, 123);
$quote->collectTotals()->save();
Example #25
0
 /**
  * Apply all the changes to order and save it
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param Mage_Sales_Model_Order $order
  * @param                        $changes
  * @return $this
  * @throws Exception
  */
 public function saveOrder(Mage_Sales_Model_Quote $quote, Mage_Sales_Model_Order $order, $changes)
 {
     if (isset($changes['billing_address'])) {
         $this->saveAddress($quote->getBillingAddress(), $order->getBillingAddress());
         unset($changes['billing_address']);
     }
     if (isset($changes['shipping_address'])) {
         $this->saveAddress($quote->getShippingAddress(), $order->getShippingAddress());
         unset($changes['shipping_address']);
     }
     if (isset($changes['payment'])) {
         $this->savePayment($quote->getPayment(), $order->getPayment());
         unset($changes['payment']);
     }
     $this->_savedOrderItems = array();
     if (isset($changes['quote_items'])) {
         $this->saveOldOrderItems($quote, $order, $changes['quote_items']);
     }
     if (isset($changes['product_to_add'])) {
         $this->saveNewOrderItems($quote, $order, $changes['product_to_add']);
     }
     $address = $quote->getIsVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
     Mage::helper('core')->copyFieldset('sales_convert_quote_address', 'to_order', $address, $order);
     $address->save();
     foreach ($quote->getAllVisibleItems() as $quoteItem) {
         $orderItem = $order->getItemByQuoteItemId($quoteItem->getItemId());
         if (in_array($orderItem->getItemId(), $this->_savedOrderItems)) {
             continue;
         }
         $orderItem = $this->getConvertor()->itemToOrderItem($quoteItem, $orderItem);
         $orderItem->save();
     }
     if (empty($changes['customer_id'])) {
         $changes['customer_id'] = $order->getCustomerId();
     }
     // Collect order all items qty
     $changes['total_qty_ordered'] = 0;
     foreach ($order->getAllItems() as $orderItem) {
         $changes['total_qty_ordered'] += $orderItem['qty_ordered'] - $orderItem['qty_canceled'];
     }
     $order->addData($changes);
     $this->getLogModel()->commitOrderChanges($order);
     $quote->save();
     $order->save();
     return $this;
 }
 /**
  * process token if customer create and edit token when checkout with recurring profile
  *
  * @param Mage_Sales_Model_Quote $quote
  * @return string
  * @throws Exception
  */
 public function processToken(Mage_Sales_Model_Quote $quote)
 {
     try {
         $billing = $quote->getBillingAddress();
         $payment = $quote->getPayment();
         /** @var Eway_Rapid31_Model_Method_Saved $ewaySave */
         $ewaySave = Mage::getModel('ewayrapid/method_saved');
         $ewaySave->setData('info_instance', $payment);
         /** @var Mage_Sales_Model_Order $order */
         $order = Mage::getModel('sales/order');
         /*$order->setBillingAddress($billing);*/
         /** @var Mage_Sales_Model_Order_Payment $paymentObj */
         $paymentObj = Mage::getModel('sales/order_payment');
         $paymentObj->setOrder($order);
         $request = Mage::getModel('ewayrapid/request_token');
         $ewaySave->_setBilling($billing);
         $ewaySave->_shouldCreateOrUpdateToken($paymentObj, $request);
         return $payment->getAdditionalData();
     } catch (Exception $e) {
         throw $e;
     }
 }
Example #27
0
 /**
  * Place the order and recurring payment profiles when customer returned from paypal
  * Until this moment all quote data must be valid
  */
 public function place()
 {
     $isNewCustomer = false;
     if ($this->_quote->getCheckoutMethod() == 'register') {
         $isNewCustomer = $this->_prepareNewCustomerQuote();
     } elseif (!$this->_quote->getCustomerId()) {
         $this->_quote->setCustomerIsGuest(true)->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)->setCustomerEmail($this->_quote->getBillingAddress()->getEmail());
     } elseif ($this->_quote->getCustomerId()) {
         if (!$this->_quote->getBillingAddress()->getCustomerAddressId()) {
             $billingAddress = Mage::getModel('customer/address');
             $billingAddress->setData($this->_quote->getBillingAddress()->getData())->setCustomerId($this->_quote->getCustomerId())->setSaveInAddressBook('0');
             //->setIsDefaultBilling('1');
             if ($this->_quote->getShippingAddress()->getData('same_as_billing')) {
                 $billingAddress->setIsDefaultShipping('0');
             } else {
                 $shippingAddress = Mage::getModel('customer/address');
                 $shippingAddress->setData($this->_quote->getShippingAddress()->getData())->setCustomerId($this->_quote->getCustomerId())->setSaveInAddressBook('0')->setIsDefaultShipping('0');
                 $shippingAddress->save();
             }
             $billingAddress->save();
         } else {
             if ($this->_quote->getBillingAddress()->getSaveInAddressBook()) {
                 $newAddress = Mage::getModel('customer/address');
                 $newAddress->setData($this->_quote->getBillingAddress()->getData())->setCustomerId($this->_quote->getCustomerId())->setSaveInAddressBook('1')->save();
             }
             if ($this->_quote->getShippingAddress()->getSaveInAddressBook() && !$this->_quote->getShippingAddress()->getData('same_as_billing')) {
                 $newAddress = Mage::getModel('customer/address');
                 $newAddress->setData($this->_quote->getShippingAddress()->getData())->setCustomerId($this->_quote->getCustomerId())->setSaveInAddressBook('1')->save();
             }
         }
     }
     $this->_ignoreAddressValidation();
     $this->_quote->collectTotals();
     //set payment method as paypal
     $this->_quote->getPayment()->setMethod("sagepaypaypal");
     // commence redirecting to finish payment
     $rs = Mage::getModel('sagepaysuite/sagePayDirectPro')->completePayPalTransaction(Mage::getSingleton('sagepaysuite/session')->getSagepaypaypalRqpost(), $this->_quote);
     $service = Mage::getModel('sales/service_quote', $this->_quote);
     $service->submitAll();
     $this->_quote->save();
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (Exception $e) {
             Mage::logException($e);
         }
     }
     $order = $service->getOrder();
     if (!$order) {
         $dbtrn = Mage::getModel('sagepaysuite2/sagepaysuite_paypaltransaction')->loadByVendorTxCode(Mage::getSingleton('sagepaysuite/session')->getLastVendorTxCode());
         if ($dbtrn->getId()) {
             $dbtrn->setStatus('MAGE_ERROR')->setStatusDetail("Could not save order. " . $dbtrn->getStatusDetail())->save();
         }
         Mage::throwException('Could not save order. Please try again.');
         return;
     }
     //Dispatching event, some modules need this to complete processing.
     Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order' => $order, 'quote' => $this->_quote));
     try {
         $order->sendNewOrderEmail();
     } catch (Exception $ex) {
         Mage::logException($ex);
     }
     $this->_order = $order;
 }
Example #28
0
 /**
  * Retrieve Total Title from Store Config
  * @param string $method
  * @param Mage_Sales_Model_Quote $quote
  * @return string
  */
 public function getTotalTitle($method = '', Mage_Sales_Model_Quote $quote = null)
 {
     $title = '';
     if (!$method) {
         $method = $quote->getPayment()->getMethod();
     }
     if ($method) {
         if (isset($this->methodFee[$method]) && $this->methodFee[$method]['description']) {
             $title = $this->methodFee[$method]['description'];
         }
     }
     if (!$title) {
         /* @var $helper Brander_PaymentFee_Helper_Data */
         $helper = Mage::helper('payment_fee');
         $title = $helper->__($helper->getConfig('default_description'));
     }
     return $title;
 }
Example #29
0
 private function initializePaymentMethodData()
 {
     $quotePayment = $this->quote->getPayment();
     $quotePayment->importData($this->proxyOrder->getPaymentData());
 }
Example #30
0
 /**
  * Gets the configured Buckaroo Payment fee excl. tax for a given quote.
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param string $paymentMethod
  *
  * @return float|int
  */
 protected function _getPaymentFee(Mage_Sales_Model_Quote $quote, $paymentMethod = '')
 {
     $storeId = $quote->getStoreId();
     /**
      * Get the fee as configured by the merchant.
      */
     if (empty($paymentMethod)) {
         $paymentMethod = $quote->getPayment()->getMethod();
     }
     if (!$paymentMethod) {
         return 0;
     }
     $fee = Mage::getStoreConfig(sprintf(self::XPATH_BUCKAROO_FEE, $paymentMethod), $storeId);
     /**
      * Determine if the configured fee is a percentage or a flat amount.
      */
     if (strpos($fee, '%') !== false) {
         $this->_feeIsPercentage = true;
         /**
          * If the fee is a percentage, get the configured percentage value and determine over which part of the
          * quote this percentage needs to be calculated.
          */
         $percentage = floatval(trim($fee));
         if (!$quote->isVirtual()) {
             $address = $quote->getShippingAddress();
         } else {
             $address = $quote->getBillingAddress();
         }
         $calculationAmount = false;
         $feePercentageMode = Mage::getStoreConfig(self::XPATH_BUCKAROO_FEE_PERCENTAGE_MODE, $storeId);
         switch ($feePercentageMode) {
             case 'subtotal':
                 $calculationAmount = $address->getBaseSubtotal() - $address->getBaseDiscountAmount();
                 $this->_feeIsInclTax = false;
                 break;
             case 'subtotal_incl_tax':
                 $calculationAmount = $address->getBaseSubtotalInclTax() - $address->getBaseDiscountAmount();
                 $this->_feeIsInclTax = true;
                 break;
             case 'grandtotal':
                 $calculationAmount = $address->getBaseSubtotalInclTax() + $address->getBaseShippingInclTax() - $address->getBaseDiscountAmount();
                 $this->_feeIsInclTax = true;
                 break;
                 //no default
         }
         /**
          * Calculate the flat fee.
          */
         if ($calculationAmount !== false && $calculationAmount > 0) {
             $fee = $calculationAmount * ($percentage / 100);
         } else {
             $fee = 0;
         }
     } else {
         $fee = (double) $fee;
     }
     if ($fee <= 0) {
         return 0;
     }
     /**
      * If the fee is entered without tax, return the fee amount. Otherwise, we need to calculate and remove the tax.
      */
     $feeIsIncludingTax = $this->getFeeIsInclTax($storeId);
     if (!$feeIsIncludingTax) {
         return $fee;
     }
     /**
      * Build a tax request to calculate the fee tax.
      */
     $taxRequest = $this->_getBuckarooFeeTaxRequest($quote);
     if (!$taxRequest) {
         return $fee;
     }
     /**
      * Get the tax rate for the request.
      */
     $taxRate = $this->_getBuckarooFeeTaxRate($taxRequest);
     if (!$taxRate || $taxRate <= 0) {
         return $fee;
     }
     /**
      * Remove the tax from the fee.
      */
     $feeTax = $this->_getBuckarooFeeTax($quote->getShippingAddress(), $taxRate, $fee, true);
     $fee -= $feeTax;
     return $fee;
 }