/** * Converting order object to quote object * * @param Mage_Sales_Model_Order $order * @return Mage_Sales_Model_Quote */ public function toQuote(Mage_Sales_Model_Order $order, $quote = null) { if (!$quote instanceof Mage_Sales_Model_Quote) { $quote = Mage::getModel('sales/quote'); } $quote->setStoreId($order->getStoreId())->setOrderId($order->getId())->setCustomerId($order->getCustomerId())->setCustomerEmail($order->getCustomerEmail())->setCustomerGroupId($order->getCustomerGroupId())->setCustomerTaxClassId($order->getCustomerTaxClassId())->setCustomerIsGuest($order->getCustomerIsGuest())->setBaseCurrencyCode($order->getBaseCurrencyCode())->setStoreCurrencyCode($order->getStoreCurrencyCode())->setQuoteCurrencyCode($order->getOrderCurrencyCode())->setStoreToBaseRate($order->getStoreToBaseRate())->setStoreToQuoteRate($order->getStoreToOrderRate())->setGrandTotal($order->getGrandTotal())->setBaseGrandTotal($order->getBaseGrandTotal())->setCouponCode($order->getCouponCode())->setGiftcertCode($order->getGiftcertCode())->setAppliedRuleIds($order->getAppliedRuleIds())->collectTotals(); Mage::dispatchEvent('sales_convert_order_to_quote', array('order' => $order, 'quote' => $quote)); return $quote; }
/** * 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; }
/** * Get the amount of the order in cents, make sure that we return the right value even if the locale is set to * something different than the default (e.g. nl_NL). * * @param Mage_Sales_Model_Order $order * @return int */ protected function getAmount(Mage_Sales_Model_Order $order) { if ($order->getBaseCurrencyCode() === 'EUR') { $grand_total = $order->getBaseGrandTotal(); } elseif ($order->getOrderCurrencyCode() === 'EUR') { $grand_total = $order->getGrandTotal(); } else { Mage::log(__METHOD__ . ' said: Neither Base nor Order currency is in Euros.'); Mage::throwException(__METHOD__ . ' said: Neither Base nor Order currency is in Euros.'); } if (is_string($grand_total)) { $locale_info = localeconv(); if ($locale_info['decimal_point'] !== '.') { $grand_total = strtr($grand_total, array($locale_info['thousands_sep'] => '', $locale_info['decimal_point'] => '.')); } $grand_total = floatval($grand_total); // Why U NO work with locales? } return floatval(round($grand_total, 2)); }
/** * Processes an order for which an incorrect amount has been paid (can only happen with Transfer) * * @param $newStates * @return bool */ protected function _processIncorrectPayment($newStates) { //determine whether too much or not enough has been paid and determine the status history copmment accordingly $amount = round($this->_order->getBaseGrandTotal() * 100, 0); $setStatus = $newStates[1]; if ($this->_postArray['brq_currency'] == $this->_order->getBaseCurrencyCode()) { $currencyCode = $this->_order->getBaseCurrencyCode(); $orderAmount = $this->_order->getBaseGrandTotal(); } else { $currencyCode = $this->_order->getOrderCurrencyCode(); $orderAmount = $this->_order->getGrandTotal(); } if ($amount > $this->_postArray['brq_amount']) { $description = Mage::helper('buckaroo3extended')->__('Not enough paid: %s has been transfered. Order grand total was: %s.', Mage::app()->getLocale()->currency($currencyCode)->toCurrency($this->_postArray['brq_amount']), Mage::app()->getLocale()->currency($currencyCode)->toCurrency($orderAmount)); } elseif ($amount < $this->_postArray['brq_amount']) { $description = Mage::helper('buckaroo3extended')->__('Too much paid: %s has been transfered. Order grand total was: %s.', Mage::app()->getLocale()->currency($currencyCode)->toCurrency($this->_postArray['brq_amount']), Mage::app()->getLocale()->currency($currencyCode)->toCurrency($orderAmount)); } else { //the correct amount was actually paid, so return false return false; } //hold the order $this->_order->hold()->save()->setStatus($setStatus)->save()->addStatusHistoryComment(Mage::helper('buckaroo3extended')->__($description), $setStatus)->save(); return true; }
/** * Set entity data to request * * @param Mage_Sales_Model_Order $order * @param Mage_Authorizenet_Model_Directpost $paymentMethod * @return Mage_Authorizenet_Model_Directpost_Request */ public function setDataFromOrder(Mage_Sales_Model_Order $order, Mage_Authorizenet_Model_Directpost $paymentMethod) { $payment = $order->getPayment(); $this->setXFpSequence($order->getQuoteId()); $this->setXInvoiceNum($order->getIncrementId()); $this->setXAmount($payment->getBaseAmountAuthorized()); $this->setXCurrencyCode($order->getBaseCurrencyCode()); $this->setXTax(sprintf('%.2F', $order->getBaseTaxAmount()))->setXFreight(sprintf('%.2F', $order->getBaseShippingAmount())); //need to use strval() because NULL values IE6-8 decodes as "null" in JSON in JavaScript, but we need "" for null values. $billing = $order->getBillingAddress(); if (!empty($billing)) { $this->setXFirstName(strval($billing->getFirstname()))->setXLastName(strval($billing->getLastname()))->setXCompany(strval($billing->getCompany()))->setXAddress(strval($billing->getStreet(1)))->setXCity(strval($billing->getCity()))->setXState(strval($billing->getRegion()))->setXZip(strval($billing->getPostcode()))->setXCountry(strval($billing->getCountry()))->setXPhone(strval($billing->getTelephone()))->setXFax(strval($billing->getFax()))->setXCustId(strval($billing->getCustomerId()))->setXCustomerIp(strval($order->getRemoteIp()))->setXCustomerTaxId(strval($billing->getTaxId()))->setXEmail(strval($order->getCustomerEmail()))->setXEmailCustomer(strval($paymentMethod->getConfigData('email_customer')))->setXMerchantEmail(strval($paymentMethod->getConfigData('merchant_email'))); } $shipping = $order->getShippingAddress(); if (!empty($shipping)) { $this->setXShipToFirstName(strval($shipping->getFirstname()))->setXShipToLastName(strval($shipping->getLastname()))->setXShipToCompany(strval($shipping->getCompany()))->setXShipToAddress(strval($shipping->getStreet(1)))->setXShipToCity(strval($shipping->getCity()))->setXShipToState(strval($shipping->getRegion()))->setXShipToZip(strval($shipping->getPostcode()))->setXShipToCountry(strval($shipping->getCountry())); } $this->setXPoNum(strval($payment->getPoNumber())); return $this; }
/** * Get order request data as array * * @param Mage_Sales_Model_Order $order * @return array */ protected function _getOrderData(Mage_Sales_Model_Order $order) { $request = array('subtotal' => $this->_formatPrice($this->_formatPrice($order->getPayment()->getBaseAmountAuthorized()) - $this->_formatPrice($order->getBaseTaxAmount()) - $this->_formatPrice($order->getBaseShippingAmount())), 'tax' => $this->_formatPrice($order->getBaseTaxAmount()), 'shipping' => $this->_formatPrice($order->getBaseShippingAmount()), 'invoice' => $order->getIncrementId(), 'address_override' => 'false', 'currency_code' => $order->getBaseCurrencyCode(), 'buyer_email' => $order->getCustomerEmail()); // append to request billing address data if ($billingAddress = $order->getBillingAddress()) { $request = array_merge($request, $this->_getBillingAddress($billingAddress)); } // append to request shipping address data if ($shippingAddress = $order->getShippingAddress()) { $request = array_merge($request, $this->_getShippingAddress($shippingAddress)); } return $request; }
/** * Adds currency information to the invoice * * @param Bitpay\Invoice $invoice * @param Mage_Sales_Model_Order $order * @return Bitpay\Invoice */ private function addCurrencyInfo($invoice, $order) { if (false === isset($invoice) || true === empty($invoice) || false === isset($order) || true === empty($order)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::addCurrencyInfo(): missing or invalid invoice or order parameter.'); throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::addCurrencyInfo(): missing or invalid invoice or order parameter.'); } else { $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::addCurrencyInfo(): function called with good invoice and order parameters.'); } $currency = new Bitpay\Currency(); if (false === isset($currency) || true === empty($currency)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::addCurrencyInfo(): could not construct new BitPay currency object.'); throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::addCurrencyInfo(): could not construct new BitPay currency object.'); } $currency->setCode($order->getBaseCurrencyCode()); $invoice->setCurrency($currency); return $invoice; }
/** * Process the seamless Payment after Order is complete * * @param Varien_Event_Observer $observer * * @throws Exception * @return Phoenix_WirecardCheckoutPage_Model_Observer */ public function salesOrderPaymentPlaceEnd(Varien_Event_Observer $observer) { /** * @var Phoenix_WirecardCheckoutPage_Model_Abstract */ $payment = $observer->getPayment(); $this->_order = $payment->getOrder(); $storeId = $this->_order->getStoreId(); $paymentInstance = $payment->getMethodInstance(); if (Mage::getStoreConfigFlag('payment/' . $payment->getMethod() . '/useSeamless', $storeId)) { $storageId = $payment->getAdditionalData(); $orderIdent = $this->_order->getQuoteId(); $customerId = Mage::getStoreConfig('payment/' . $payment->getMethod() . '/customer_id', $storeId); $shopId = Mage::getStoreConfig('payment/' . $payment->getMethod() . '/shop_id', $storeId); $secretKey = Mage::getStoreConfig('payment/' . $payment->getMethod() . '/secret_key', $storeId); $serviceUrl = Mage::getUrl(Mage::getStoreConfig('payment/' . $payment->getMethod() . '/service_url', $storeId)); $paymentType = $this->_getMappedPaymentCode($payment->getMethod()); $returnurl = Mage::getUrl('wirecard_checkout_page/processing/checkresponse', array('_secure' => true, '_nosid' => true)); $pluginVersion = WirecardCEE_Client_QPay_Request_Initiation::generatePluginVersion('Magento', Mage::getVersion(), $paymentInstance->getPluginName(), $paymentInstance->getPluginVersion()); $initiation = new WirecardCEE_Client_QPay_Request_Initiation($customerId, $shopId, $secretKey, substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2), $pluginVersion); $consumerData = new WirecardCEE_Client_QPay_Request_Initiation_ConsumerData(); if (Mage::getStoreConfigFlag('payment/' . $payment->getMethod() . '/send_additional_data', $storeId)) { $consumerData->setEmail($this->_order->getCustomerEmail()); $dob = $payment->getMethodInstance()->getCustomerDob(); if ($dob) { $consumerData->setBirthDate($dob); } $consumerData->addAddressInformation($this->_getBillingObject()); if ($this->_order->hasShipments()) { $consumerData->addAddressInformation($this->_getShippingObject()); } } if ($payment->getMethod() == 'wirecard_checkout_page_invoice' || $payment->getMethod() == 'wirecard_checkout_page_installment') { $consumerData->setEmail($this->_order->getCustomerEmail()); $dob = $payment->getMethodInstance()->getCustomerDob(); if ($dob) { $consumerData->setBirthDate($dob); } else { throw new Exception('Invalid dob'); } $consumerData->addAddressInformation($this->_getBillingObject('invoice')); } $consumerData->setIpAddress($this->_order->getRemoteIp()); $consumerData->setUserAgent(Mage::app()->getRequest()->getServer('HTTP_USER_AGENT')); $initiation->setConfirmUrl(Mage::getUrl('wirecard_checkout_page/processing/seamlessConfirm', array('_secure' => true, '_nosid' => true))); $initiation->setWindowName('paymentIframe'); $initiation->orderId = $this->_order->getIncrementId(); $initiation->companyTradeRegistryNumber = $payment->getMethodInstance()->getCompanyTradeRegistrationNumber(); if ($orderIdent && $storageId) { $initiation->setStorageReference($orderIdent, $storageId); } if (Mage::getStoreConfigFlag('payment/' . $payment->getMethod() . '/auto_deposit', $storeId)) { $initiation->setAutoDeposit(true); } $initiation->setOrderReference($this->_order->getIncrementId()); $financialInstitution = $payment->getMethodInstance()->getFinancialInstitution(); if ($financialInstitution) { $initiation->setFinancialInstitution($financialInstitution); } Phoenix_WirecardCheckoutPage_Helper_Configuration::configureWcsLibrary(); $response = $initiation->initiate(round($this->_order->getBaseGrandTotal(), 2), $this->_order->getBaseCurrencyCode(), $paymentType, $this->_order->getIncrementId(), $returnurl, $returnurl, $returnurl, $returnurl, $serviceUrl, $consumerData); if (isset($response) && $response->getStatus() == WirecardCEE_Client_QPay_Response_Initiation::STATE_SUCCESS) { $payment->setAdditionalData(serialize($payment->getAdditionalData()))->save(); Mage::getSingleton('core/session')->unsetData('wirecard_checkout_page_payment_info'); Mage::getSingleton('core/session')->setWirecardCheckoutPageRedirectUrl(urldecode($response->getRedirectUrl())); } elseif (isset($response)) { $errorMessage = ''; foreach ($response->getErrors() as $error) { $errorMessage .= ' ' . $error->getMessage(); } throw new Exception(trim($errorMessage)); } else { $payment->setAdditionalData(serialize($payment->getAdditionalData()))->save(); Mage::getSingleton('core/session')->unsetData('wirecard_checkout_page_payment_info'); } } return $this; }
/** * Convert an order to a LinkShare refund row. * * @param Mage_Sales_Model_Order $order * @return array */ public function orderToFeed(Mage_Sales_Model_Order $order) { $orderDate = new Zend_Date($order->getCreatedAt(), Varien_Date::DATETIME_INTERNAL_FORMAT); $orderDate = $orderDate->toString('yyyy-MM-dd'); $transDate = Mage::getModel('core/date')->date('Y-m-d'); $rows = array(); foreach ($order->getAllVisibleItems() as $item) { /* @var $item Mage_Sales_Model_OrderItem */ if ($item->getQtyCanceled() > 0) { $rows[] = array('order_id' => $order->getIncrementId(), 'site_id' => '', 'order_date' => $orderDate, 'transaction_date' => $transDate, 'sku' => $item->getSku(), 'quantity' => round($item->getQtyCanceled()), 'amount' => ($item->getBaseRowTotal() - $item->getBaseDiscountAmount()) * -100, 'currency' => $order->getBaseCurrencyCode(), 'blank' => '', 'blank' => '', 'blank' => '', 'product_name' => ''); } } return $rows; }
/** * Import order information to the subscription. * * @param Mage_Sales_Model_Order $order * @return Customweb_Subscription_Model_Subscription */ public function importOrder(Mage_Sales_Model_Order $order) { $this->getSubscription()->setInitialOrderId($order->getId()); if ($order->getPayment() && $order->getPayment()->getMethod()) { $this->getSubscription()->setMethodInstance($order->getPayment()->getMethodInstance()); if (!$this->getSubscription()->isMethodSuspendOnPendingPayment()) { $this->getSubscription()->activate(); } } $orderInfo = $order->getData(); $this->_cleanupArray($orderInfo); $this->getSubscription()->setOrderInfo($orderInfo); $addressInfo = $order->getBillingAddress()->getData(); $this->_cleanupArray($addressInfo); $this->getSubscription()->setBillingAddressInfo($addressInfo); if (!$order->getIsVirtual()) { $addressInfo = $order->getShippingAddress()->getData(); $this->_cleanupArray($addressInfo); $this->getSubscription()->setShippingAddressInfo($addressInfo); } $this->getSubscription()->setCurrencyCode($order->getBaseCurrencyCode()); $this->getSubscription()->setCustomerId($order->getCustomerId()); if ($order->getCustomerId() != null) { $customer = Mage::getModel('customer/customer')->load($order->getCustomerId()); $this->getSubscription()->setSubscriberName($customer->getName()); } else { $this->getSubscription()->setSubscriberName($order->getBillingAddress()->getName()); } $this->getSubscription()->setStoreId($order->getStoreId()); $this->getSubscription()->setLastDatetime(Mage::helper('customweb_subscription')->toDateString(Zend_Date::now())); if ($order->getPayment()) { $this->getSubscription()->setPaymentId($order->getPayment()->getId()); } if ($this->getSubscription()->getData('shipping_amount_type') == 'fixed') { $this->getSubscription()->setShippingAmount($this->getSubscription()->getData('shipping_amount')); } else { $this->getSubscription()->setShippingAmount($order->getShippingAmount() + $order->getShippingTaxAmount()); } $this->getSubscription()->setInitAmount($order->getSubscriptionInitAmount()); $this->getSubscription()->setLastOrderId($order->getId()); return $this->getSubscription(); }
function CreateMagentoShopRequestOrder(Mage_Sales_Model_Order $order, $paymentmethod) { $request = new Byjuno_Cdp_Helper_Api_Classes_ByjunoRequest(); $request->setClientId(Mage::getStoreConfig('payment/cdp/clientid', Mage::app()->getStore())); $request->setUserID(Mage::getStoreConfig('payment/cdp/userid', Mage::app()->getStore())); $request->setPassword(Mage::getStoreConfig('payment/cdp/password', Mage::app()->getStore())); $request->setVersion("1.00"); try { $request->setRequestEmail(Mage::getStoreConfig('payment/cdp/mail', Mage::app()->getStore())); } catch (Exception $e) { } $b = $order->getCustomerDob(); if (!empty($b)) { $request->setDateOfBirth(Mage::getModel('core/date')->date('Y-m-d', strtotime($b))); } $g = $order->getCustomerGender(); if (!empty($g)) { if ($g == '1') { $request->setGender('1'); } else { if ($g == '2') { $request->setGender('2'); } } } $requestId = uniqid((string) $order->getBillingAddress()->getId() . "_"); $request->setRequestId($requestId); $reference = $order->getCustomerId(); if (empty($reference)) { $request->setCustomerReference("guest_" . $order->getBillingAddress()->getId()); } else { $request->setCustomerReference($order->getCustomerId()); } $request->setFirstName((string) $order->getBillingAddress()->getFirstname()); $request->setLastName((string) $order->getBillingAddress()->getLastname()); $request->setFirstLine(trim((string) $order->getBillingAddress()->getStreetFull())); $request->setCountryCode(strtoupper((string) $order->getBillingAddress()->getCountry())); $request->setPostCode((string) $order->getBillingAddress()->getPostcode()); $request->setTown((string) $order->getBillingAddress()->getCity()); $request->setFax((string) trim($order->getBillingAddress()->getFax(), '-')); $request->setLanguage((string) substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2)); if ($order->getBillingAddress()->getCompany()) { $request->setCompanyName1($order->getBillingAddress()->getCompany()); } $request->setTelephonePrivate((string) trim($order->getBillingAddress()->getTelephone(), '-')); $request->setEmail((string) $order->getBillingAddress()->getEmail()); $extraInfo["Name"] = 'ORDERCLOSED'; $extraInfo["Value"] = 'NO'; $request->setExtraInfo($extraInfo); $extraInfo["Name"] = 'ORDERAMOUNT'; $extraInfo["Value"] = number_format($order->getGrandTotal(), 2, '.', ''); $request->setExtraInfo($extraInfo); $extraInfo["Name"] = 'ORDERCURRENCY'; $extraInfo["Value"] = $order->getBaseCurrencyCode(); $request->setExtraInfo($extraInfo); /* shipping information */ if ($order->canShip()) { $extraInfo["Name"] = 'DELIVERY_FIRSTNAME'; $extraInfo["Value"] = $order->getShippingAddress()->getFirstname(); $request->setExtraInfo($extraInfo); $extraInfo["Name"] = 'DELIVERY_LASTNAME'; $extraInfo["Value"] = $order->getShippingAddress()->getLastname(); $request->setExtraInfo($extraInfo); $extraInfo["Name"] = 'DELIVERY_FIRSTLINE'; $extraInfo["Value"] = trim($order->getShippingAddress()->getStreetFull()); $request->setExtraInfo($extraInfo); $extraInfo["Name"] = 'DELIVERY_HOUSENUMBER'; $extraInfo["Value"] = ''; $request->setExtraInfo($extraInfo); $extraInfo["Name"] = 'DELIVERY_COUNTRYCODE'; $extraInfo["Value"] = strtoupper($order->getShippingAddress()->getCountry()); $request->setExtraInfo($extraInfo); $extraInfo["Name"] = 'DELIVERY_POSTCODE'; $extraInfo["Value"] = $order->getShippingAddress()->getPostcode(); $request->setExtraInfo($extraInfo); $extraInfo["Name"] = 'DELIVERY_TOWN'; $extraInfo["Value"] = $order->getShippingAddress()->getCity(); $request->setExtraInfo($extraInfo); if ($order->getShippingAddress()->getCompany() != '' && Mage::getStoreConfig('payment/api/businesstobusiness', Mage::app()->getStore()) == 'enable') { $extraInfo["Name"] = 'DELIVERY_COMPANYNAME'; $extraInfo["Value"] = $order->getShippingAddress()->getCompany(); $request->setExtraInfo($extraInfo); } } $extraInfo["Name"] = 'PP_TRANSACTION_NUMBER'; $extraInfo["Value"] = $requestId; $request->setExtraInfo($extraInfo); $extraInfo["Name"] = 'ORDERID'; $extraInfo["Value"] = $order->getIncrementId(); $request->setExtraInfo($extraInfo); $extraInfo["Name"] = 'PAYMENTMETHOD'; $extraInfo["Value"] = 'BYJUNO-INVOICE'; $request->setExtraInfo($extraInfo); $extraInfo["Name"] = 'CONNECTIVTY_MODULE'; $extraInfo["Value"] = 'Byjuno Magento module 1.0.0'; $request->setExtraInfo($extraInfo); return $request; }
/** * Retrieve Basket data * * @param Mage_Sales_Model_Order $order * @return array */ public function getBasketData(Mage_Sales_Model_Order $order) { if ($order instanceof Mage_Sales_Model_Order) { $basket = array('amount' => $order->getGrandTotal(), 'currency' => $order->getOrderCurrencyCode(), 'baseCurrency' => $order->getBaseCurrencyCode(), 'baseAmount' => $order->getBaseGrandTotal()); } else { if ($order instanceof Mage_Sales_Model_Quote) { $basket = array('amount' => $order->getGrandTotal(), 'currency' => $order->getQuoteCurrencyCode(), 'baseCurrency' => $order->getBaseCurrencyCode(), 'baseAmount' => $order->getBaseGrandTotal()); } } return $basket; }