/** * Adiciona o Link do meio de pagamento a página de sucesso. * @param $observer */ public function orderSuccessEvent($observer) { try { $order = new Mage_Sales_Model_Order(); $lastOrderId = Mage::getSingleton('checkout/session')->getLastRealOrderId(); $order->loadByIncrementId($lastOrderId); $quoteId = $order->getQuoteId(); $quote = Mage::getModel("sales/quote")->loadByIdWithoutStore($quoteId); $type = null; $payment_method_bcash = $quote->getPaymentMethodBcash(); if ($payment_method_bcash) { $helper = new Bcash_Pagamento_Helper_PaymentMethod(); $type = $helper->getPaymentMethod($payment_method_bcash); } $layout = Mage::app()->getLayout(); $block = $layout->createBlock('Mage_Core_Block_Template', 'link_pagamento_bcash', array('template' => 'bcash/pagamento/checkout/success.phtml')); $block->setOrder($order); $block->setQuote($quote); $block->setType($type); $layout->getBlock('content')->append($block); $bcashTransacation = $order->getTransactionIdBcash(); Mage::helper("bcash")->saveLog("Pedido '" . $lastOrderId . "' realizado com sucesso. Transacao: " . $bcashTransacation); } catch (Exception $e) { Mage::helper("bcash")->saveLog($e->getMessage()); } }
/** * * Update shipping info after notifyRequest * @param array $data */ protected function updateShippingInfo($data) { try { $typeChosen = $data['Shipping']['ShippingType']; $cost = $data['Shipping']['ShippingCost']['Gross']; if (!empty($typeChosen)) { $quote = Mage::getModel('sales/quote')->load($this->_order->getQuoteId()); $address = $quote->getShippingAddress(); $shipping = Mage::getModel('shipping/shipping'); $shippingRates = $shipping->collectRatesByAddress($address)->getResult(); $shippingCostList = array(); foreach ($shippingRates->getAllRates() as $rate) { $type = $rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle(); if ($type == $typeChosen) { $this->_order->setShippingDescription($typeChosen); $this->_order->setShippingMethod($rate->getCarrier() . "_" . $rate->getMethod()); $current = $this->_order->getShippingAmount(); $this->_order->setShippingAmount($cost / 100); $this->_order->setGrandTotal($this->_order->getGrandTotal() + $this->_order->getShippingAmount() - $current); $this->_order->save(); } } } } catch (Exception $e) { Mage::logException("shipping info error: " . $e); } }
/** * Load a Quote object from an Order object * @param Mage_Sales_Model_Order $order * @return Mage_Sales_Model_Quote */ protected function _getQuoteFromOrder($order) { if (!$this->_quote instanceof Mage_Sales_Model_Quote) { $this->_quote = Mage::getModel('sales/quote')->load($order->getQuoteId()); } return $this->_quote; }
/** * Gets the Nosto ID for an order model. * The Nosto ID represents the customer who placed to the order on Nosto's * side. * * @param Mage_Sales_Model_Order $order the order to get the Nosto ID for. * * @return bool|string the Nosto ID or false if not found for order. */ public function getNostoId(Mage_Sales_Model_Order $order) { /** @var Nosto_Tagging_Model_Customer $customer */ $customer = Mage::getModel('nosto_tagging/customer'); $customer->load($order->getQuoteId(), 'quote_id'); return $customer->hasData('nosto_id') ? $customer->getNostoId() : false; }
public function successAction() { $order = new Mage_Sales_Model_Order(); $lastOrderId = Mage::getSingleton('checkout/session')->getLastRealOrderId(); $order->loadByIncrementId($lastOrderId); $quoteId = $order->getQuoteId(); $quote = Mage::getModel("sales/quote")->load($quoteId); try { $order->setTransactionIdBcash($quote->getTransactionIdBcash())->setStatusBcash($quote->getStatusBcash())->setDescriptionStatusBcash($quote->getDescriptionStatusBcash())->setPaymentLinkBcash($quote->getPaymentLinkBcash())->setPaymentMethodBcash($quote->getPaymentMethodBcash())->setInstallmentsBcash($quote->getInstallmentsBcash()); $order->save(); $order->sendNewOrderEmail(); } catch (Exception $ex) { } $type = null; $payment_method_bcash = $order->getPaymentMethodBcash(); if ($payment_method_bcash) { $helper = new Bcash_Pagamento_Helper_PaymentMethod(); $type = $helper->getPaymentMethod($payment_method_bcash); } $this->loadLayout(); $this->getLayout()->getBlock('root')->setTemplate('page/2columns-right.phtml'); $block = $this->getLayout()->createBlock('Mage_Core_Block_Template', 'link_pagamento_bcash', array('template' => 'bcash/pagamento/checkout/success.phtml')); $block->setOrder($order); $block->setQuote($quote); $block->setType($type); $this->getLayout()->getBlock('content')->append($block); $this->_initLayoutMessages('checkout/session'); Mage::dispatchEvent('checkout_onepage_controller_success_action', array('order_ids' => array($lastOrderId))); $this->renderLayout(); }
/** * Get quote model by order * * @param Mage_Sales_Model_Order $order * @return boolean|Mage_Sales_Model_Quote */ public function getQuoteByOrder(Mage_Sales_Model_Order $order) { $quoteId = $order->getQuoteId(); $storeId = $order->getStoreId(); $this->checkQuoteItems($quoteId, $order); $quote = Mage::getModel('sales/quote')->setStoreId($storeId)->load($quoteId); return $quote; }
/** * @return array */ protected function _prepareOrderData() { // magento 1.5 compat $shipping_method_c = $this->_order->getShippingMethod(true); $shipping_method = $this->_order->getData('shipping_method'); $shipping_method_code = $shipping_method_c ? $shipping_method_c->getData('carrier_code') : $shipping_method; $data = array_filter(array('currency_code' => $this->_order->getOrderCurrencyCode(), 'shipping_method_code' => $shipping_method_code, 'shipping_method_title' => $this->_order->getShippingDescription(), 'created_on' => $this->_order->getCreatedAt(), 'updated_on' => $this->_order->getUpdatedAt(), 'state' => $this->_order->getState(), 'status' => $this->_order->getStatus(), 'is_gift' => $this->_order->getGiftMessageId() != null, 'ref_quote_id' => $this->_order->getQuoteId(), 'order_subtotal_with_tax' => $this->_order->getSubtotalInclTax(), 'order_subtotal' => $this->_order->getSubtotal(), 'order_tax' => $this->_order->getTaxAmount(), 'order_hidden_tax' => $this->_order->getHiddenTaxAmount(), 'order_shipping_with_tax' => $this->_order->getShippingInclTax(), 'order_shipping' => $this->_order->getShippingAmount(), 'order_discount' => $this->_order->getDiscountAmount(), 'order_shipping_discount' => $this->_order->getShippingDiscountAmount(), 'order_total' => $this->_order->getGrandTotal(), 'order_total_items' => $this->_order->getTotalItemCount())); return $data; }
/** * Adds information to based on the order object inside magento * * @param Mage_Sales_Model_Order $order * @return Bitpay_Core_Model_Invoice */ public function prepateWithOrder($order) { if (false === isset($order) || true === empty($order)) { \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Model_Invoice::prepateWithOrder(): Missing or empty $order parameter.'); throw new \Exception('In Bitpay_Core_Model_Invoice::prepateWithOrder(): Missing or empty $order parameter.'); } $this->addData(array('quote_id' => $order->getQuoteId(), 'increment_id' => $order->getIncrementId())); return $this; }
public function setUp() { parent::setUp(); $order = new Mage_Sales_Model_Order(); $order->load('100000001', 'increment_id'); $order->getPayment()->setMethod(Mage_Paypal_Model_Config::METHOD_PAYFLOWLINK); $order->save(); $session = Mage::getSingleton('Mage_Checkout_Model_Session'); $session->setLastRealOrderId($order->getRealOrderId())->setLastQuoteId($order->getQuoteId()); }
public function testRedirectActionIsContentGenerated() { $order = new Mage_Sales_Model_Order(); $order->load('100000001', 'increment_id'); $order->getPayment()->setMethod(Mage_Paypal_Model_Config::METHOD_WPS); $order->save(); $session = Mage::getSingleton('Mage_Checkout_Model_Session'); $session->setLastRealOrderId($order->getRealOrderId())->setLastQuoteId($order->getQuoteId()); $this->dispatch('paypal/standard/redirect'); $this->assertContains('<form action="https://www.paypal.com/webscr" id="paypal_standard_checkout"' . ' name="paypal_standard_checkout" method="POST">', $this->getResponse()->getBody()); }
public function testCancelActionIsContentGenerated() { $order = new Mage_Sales_Model_Order(); $order->load('100000001', 'increment_id'); $order->getPayment()->setMethod(Mage_Paypal_Model_Config::METHOD_HOSTEDPRO); $order->save(); $session = Mage::getSingleton('Mage_Checkout_Model_Session'); $session->setLastRealOrderId($order->getRealOrderId())->setLastQuoteId($order->getQuoteId()); $this->dispatch('paypal/hostedpro/cancel'); $this->assertContains('window.top.checkout.gotoSection("payment");', $this->getResponse()->getBody()); $this->assertContains('window.top.document.getElementById(\'checkout-review-submit\').show();', $this->getResponse()->getBody()); $this->assertContains('window.top.document.getElementById(\'iframe-warning\').hide();', $this->getResponse()->getBody()); }
/** * Coge las billing y shipping address de la ultima order * el checkout method y shipping method * y las vuelve a meter en quote actual para que el checkout * pueda tener las direcciones pre-populadas. * * @param Mage_Sales_Model_Order $order */ protected function _setCheckoutInfoFromOldOrder(Mage_Sales_Model_Order $order) { $checkoutSession = $this->getCheckoutSession(); $quote = $checkoutSession->getQuote(); $oldQuote = Mage::getModel('sales/quote')->load($order->getQuoteId()); $quote->setCheckoutMethod($oldQuote->getCheckoutMethod()); if ($oldQuote->getId()) { $billingAddress = clone $oldQuote->getBillingAddress(); $billingAddress->setQuote($quote); $shippingAddress = clone $oldQuote->getShippingAddress(); $shippingAddress->setQuote($quote); $quote->removeAddress($quote->getBillingAddress()->getId()); $quote->removeAddress($quote->getShippingAddress()->getId()); $quote->setBillingAddress($billingAddress); $quote->setShippingAddress($shippingAddress); } $quote->save(); return $this; }
/** * 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; }
/** * Operate with order using information from silent post * * @param Mage_Sales_Model_Order $order */ protected function _processOrder(Mage_Sales_Model_Order $order) { $response = $this->getResponse(); $payment = $order->getPayment(); $payment->setTransactionId($response->getPnref())->setIsTransactionClosed(0); $canSendNewOrderEmail = true; if ($response->getResult() == self::RESPONSE_CODE_FRAUDSERVICE_FILTER || $response->getResult() == self::RESPONSE_CODE_DECLINED_BY_FILTER) { $canSendNewOrderEmail = false; $fraudMessage = $this->_getFraudMessage() ? $response->getFraudMessage() : $response->getRespmsg(); $payment->setIsTransactionPending(true)->setIsFraudDetected(true)->setAdditionalInformation('paypal_fraud_filters', $fraudMessage); } if ($response->getAvsdata() && strstr(substr($response->getAvsdata(), 0, 2), 'N')) { $payment->setAdditionalInformation('paypal_avs_code', substr($response->getAvsdata(), 0, 2)); } if ($response->getCvv2match() && $response->getCvv2match() != 'Y') { $payment->setAdditionalInformation('paypal_cvv2_match', $response->getCvv2match()); } switch ($response->getType()) { case self::TRXTYPE_AUTH_ONLY: $payment->registerAuthorizationNotification($payment->getBaseAmountAuthorized()); break; case self::TRXTYPE_SALE: $payment->registerCaptureNotification($payment->getBaseAmountAuthorized()); break; } $order->save(); try { if ($canSendNewOrderEmail) { $order->queueNewOrderEmail(); } Mage::getModel('sales/quote')->load($order->getQuoteId())->setIsActive(false)->save(); } catch (Exception $e) { Mage::throwException(Mage::helper('paypal')->__('Can not send new order email.')); } }
/** * set the order information * @param Mage_Sales_Model_Order $orderData */ public function __construct(Mage_Sales_Model_Order $orderData) { $customerModel = Mage::getModel('customer/customer'); $customerModel->load($orderData->getCustomerId()); $this->id = $orderData->getIncrementId(); $this->quote_id = $orderData->getQuoteId(); $this->email = $orderData->getCustomerEmail(); $this->store_name = $orderData->getStoreName(); $created_at = new Zend_Date($orderData->getCreatedAt(), Zend_Date::ISO_8601); $this->purchase_date = $created_at->toString(Zend_Date::ISO_8601); $this->delivery_method = $orderData->getShippingDescription(); $this->delivery_total = $orderData->getShippingAmount(); $this->currency = $orderData->getStoreCurrencyCode(); if ($payment = $orderData->getPayment()) { $this->payment = $payment->getMethodInstance()->getTitle(); } $this->couponCode = $orderData->getCouponCode(); /** * custom order attributes */ $helper = Mage::helper('ddg'); $website = Mage::app()->getStore($orderData->getStore())->getWebsite(); $customAttributes = $helper->getConfigSelectedCustomOrderAttributes($website); if ($customAttributes) { $fields = Mage::getResourceModel('ddg_automation/order')->getOrderTableDescription(); foreach ($customAttributes as $customAttribute) { if (isset($fields[$customAttribute])) { $field = $fields[$customAttribute]; $value = $this->_getCustomAttributeValue($field, $orderData); if ($value) { $this->_assignCustom($field, $value); } } } } /** * Billing address. */ if ($orderData->getBillingAddress()) { $billingData = $orderData->getBillingAddress()->getData(); $this->billing_address = array('billing_address_1' => $this->_getStreet($billingData['street'], 1), 'billing_address_2' => $this->_getStreet($billingData['street'], 2), 'billing_city' => $billingData['city'], 'billing_region' => $billingData['region'], 'billing_country' => $billingData['country_id'], 'billing_postcode' => $billingData['postcode']); } /** * Shipping address. */ if ($orderData->getShippingAddress()) { $shippingData = $orderData->getShippingAddress()->getData(); $this->delivery_address = array('delivery_address_1' => $this->_getStreet($shippingData['street'], 1), 'delivery_address_2' => $this->_getStreet($shippingData['street'], 2), 'delivery_city' => $shippingData['city'], 'delivery_region' => $shippingData['region'], 'delivery_country' => $shippingData['country_id'], 'delivery_postcode' => $shippingData['postcode']); } $syncCustomOption = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_PRODUCT_CUSTOM_OPTIONS, $website); /** * Order items. * @var Mage_Sales_Model_Order_Item $productItem */ foreach ($orderData->getAllItems() as $productItem) { //product custom options $customOptions = array(); if ($syncCustomOption) { $customOptions = $this->_getOrderItemOptions($productItem); } $product = $productItem->getProduct(); if ($product) { // category names $categoryCollection = $product->getCategoryCollection()->addAttributeToSelect('name'); $productCat = array(); foreach ($categoryCollection as $cat) { $categories = array(); $categories[] = $cat->getName(); $productCat[]['Name'] = substr(implode(', ', $categories), 0, 244); } $attributes = array(); //selected attributes from config $configAttributes = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_PRODUCT_ATTRIBUTES, $orderData->getStore()->getWebsite()); if ($configAttributes) { $configAttributes = explode(',', $configAttributes); //attributes from attribute set $attributesFromAttributeSet = $this->_getAttributesArray($product->getAttributeSetId()); foreach ($configAttributes as $attribute_code) { //if config attribute is in attribute set if (in_array($attribute_code, $attributesFromAttributeSet)) { //attribute input type $inputType = $product->getResource()->getAttribute($attribute_code)->getFrontend()->getInputType(); //fetch attribute value from product depending on input type switch ($inputType) { case 'multiselect': case 'select': case 'dropdown': $value = $product->getAttributeText($attribute_code); break; default: $value = $product->getData($attribute_code); break; } if ($value) { // check limit on text and assign value to array $attributes[][$attribute_code] = $this->_limitLength($value); } } } } $attributeSetName = $this->_getAttributeSetName($product); $this->products[] = array('name' => $productItem->getName(), 'sku' => $productItem->getSku(), 'qty' => (int) number_format($productItem->getData('qty_ordered'), 2), 'price' => (double) number_format($productItem->getPrice(), 2, '.', ''), 'attribute-set' => $attributeSetName, 'categories' => $productCat, 'attributes' => $attributes, 'custom-options' => $customOptions); } else { // when no product information is available limit to this data $this->products[] = array('name' => $productItem->getName(), 'sku' => $productItem->getSku(), 'qty' => (int) number_format($productItem->getData('qty_ordered'), 2), 'price' => (double) number_format($productItem->getPrice(), 2, '.', ''), 'attribute-set' => '', 'categories' => array(), 'attributes' => array(), 'custom-options' => $customOptions); } } $this->order_subtotal = (double) number_format($orderData->getData('subtotal'), 2, '.', ''); $this->discount_ammount = (double) number_format($orderData->getData('discount_amount'), 2, '.', ''); $orderTotal = abs($orderData->getData('grand_total') - $orderData->getTotalRefunded()); $this->order_total = (double) number_format($orderTotal, 2, '.', ''); $this->order_status = $orderData->getStatus(); return true; }
/** * Validate request and return QuoteId * Can throw Mage_Core_Exception and Exception * * @return int */ public function successEvent() { $this->_validateEventData(false); return $this->_order->getQuoteId(); }
/** * Process exception action by ops exception url * * @param Mage_Sales_Model_Order $order Order * @param array $params Request params */ public function handleException($order, $params) { $exceptionMessage = $this->getPaymentExceptionMessage($params['STATUS']); if (!empty($exceptionMessage)) { try { $this->_getCheckout()->setLastSuccessQuoteId($order->getQuoteId()); $this->_prepareCCInfo($order, $params); $order->getPayment()->setLastTransId($params['PAYID']); //to send new order email only when state is pending payment if ($order->getState() == Mage_Sales_Model_Order::STATE_PENDING_PAYMENT) { $order->sendNewOrderEmail(); } $order->addStatusHistoryComment($exceptionMessage); $order->save(); $this->setPaymentTransactionInformation($order->getPayment(), $params, 'exception'); } catch (Exception $e) { $this->_getCheckout()->addError(Mage::helper('ops')->__('Order can not be saved for system reason.')); } } else { $this->_getCheckout()->addError(Mage::helper('ops')->__('An unknown exception occured.')); } }
/** * Operate with order using information from silent post * * @param Mage_Sales_Model_Order $order */ protected function _processOrder(Mage_Sales_Model_Order $order) { $response = $this->getResponse(); $payment = $order->getPayment(); $payment->setTransactionId($response->getPnref())->setIsTransactionClosed(0); $canSendNewOrderEmail = true; if ($response->getResult() == self::RESPONSE_CODE_FRAUDSERVICE_FILTER || $response->getResult() == self::RESPONSE_CODE_DECLINED_BY_FILTER) { $canSendNewOrderEmail = false; $fraudMessage = $this->_getFraudMessage() ? $response->getFraudMessage() : $response->getRespmsg(); $payment->setIsTransactionPending(true)->setIsFraudDetected(true)->setAdditionalInformation('paypal_fraud_filters', $fraudMessage); } if ($response->getAvsdata() && strstr(substr($response->getAvsdata(), 0, 2), 'N')) { $payment->setAdditionalInformation('paypal_avs_code', substr($response->getAvsdata(), 0, 2)); } if ($response->getCvv2match() && $response->getCvv2match() != 'Y') { $payment->setAdditionalInformation('paypal_cvv2_match', $response->getCvv2match()); } switch ($response->getType()) { case self::TRXTYPE_AUTH_ONLY: $payment->registerAuthorizationNotification($payment->getBaseAmountAuthorized()); break; case self::TRXTYPE_SALE: $payment->registerCaptureNotification($payment->getBaseAmountAuthorized()); break; } $order->save(); $customerId = $order->getCustomerId(); if ($response->getResult() == self::RESPONSE_CODE_APPROVED && $response->getMethod() == 'CC' && $customerId && $payment->hasAdditionalInformation('cc_save_future') && $payment->getAdditionalInformation('cc_save_future') == 'Y') { // Obtain CC type $ccType = 'OT'; $responseCcType = $response->getCardtype(); if (!is_null($responseCcType)) { $payflowResponseCcTypesMap = array(0 => 'VI', 1 => 'MC', 2 => 'DI', 3 => 'AE', 4 => 'OT', 5 => 'JCB'); if (isset($payflowResponseCcTypesMap[$responseCcType])) { $ccType = $payflowResponseCcTypesMap[$responseCcType]; } } $ccExpMonth = $response->getExpdate() ? substr($response->getExpdate(), 0, 2) : ''; if ($ccExpMonth[0] == '0') { $ccExpMonth = $ccExpMonth[1]; } // Create new stored card $customerstoredModel = Mage::getModel('cls_paypal/customerstored'); $customerstoredModel->setData(array('transaction_id' => $response->getPnref(), 'customer_id' => $customerId, 'cc_type' => $ccType, 'cc_last4' => $response->getAcct() ? substr($response->getAcct(), -4) : '', 'cc_exp_month' => $ccExpMonth, 'cc_exp_year' => $response->getExpdate() ? '20' . substr($response->getExpdate(), 2) : '', 'date' => Varien_Date::formatDate(true, true), 'payment_method' => $payment->getMethod())); $customerstoredModel->save(); } try { if ($canSendNewOrderEmail) { $order->sendNewOrderEmail(); } Mage::getModel('sales/quote')->load($order->getQuoteId())->setIsActive(false)->save(); } catch (Exception $e) { Mage::throwException(Mage::helper('paypal')->__('Can not send new order email.')); } }
/** * set the order information * * @param Mage_Sales_Model_Order $orderData */ public function setOrderData(Mage_Sales_Model_Order $orderData) { $this->id = (string) $orderData->getIncrementId(); $this->quote_id = (string) $orderData->getQuoteId(); $this->email = (string) $orderData->getCustomerEmail(); $this->store_name = (string) $orderData->getStoreName(); $created_at = new Zend_Date($orderData->getCreatedAt(), Zend_Date::ISO_8601); $this->purchase_date = $created_at->toString(Zend_Date::ISO_8601); $this->delivery_method = $orderData->getShippingDescription(); $this->delivery_total = (double) number_format($orderData->getShippingAmount(), 2, '.', ''); $this->currency = $orderData->getStoreCurrencyCode(); if ($payment = $orderData->getPayment()) { $this->payment = $payment->getMethodInstance()->getTitle(); } $this->couponCode = (string) $orderData->getCouponCode(); //set order custom attributes $this->_setOrderCustomAttributes($orderData); //billing $this->_setBillingData($orderData); //shipping $this->_setShippingData($orderData); //order items $this->_setOrderItems($orderData); //sales data $this->order_subtotal = (double) number_format($orderData->getData('subtotal'), 2, '.', ''); $this->discount_ammount = (double) number_format($orderData->getData('discount_amount'), 2, '.', ''); $orderTotal = abs($orderData->getData('grand_total') - $orderData->getTotalRefunded()); $this->order_total = (double) number_format($orderTotal, 2, '.', ''); $this->order_status = (string) $orderData->getStatus(); }
/** * 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; }
/** * Get trusted shops buyer protection amount in cent * * @param Mage_Sales_Model_Order $order * @param boolean $addTax * @return int */ private function getTrustedShopsAmount($order, $addTax) { $model = Mage::getModel('trustedshops/products'); $ts_product = $model->getAdminTsProductByQuoteId($order->getQuoteId()); if ($ts_product) { $tsNetAmount = $model->getTsProductAmount($ts_product); $amount = $tsNetAmount; $tax_data = $model->getTsProductsTaxData(array('key' => 'rate', 'order' => $order)); if ($tax_data !== null) { $ts_tax_amount = round($amount * $tax_data / 100, 2); $amount = $tsNetAmount + $ts_tax_amount; } return $this->currencyToSmallerUnit($amount); } return 0; }
/** * Add credit card data to PaynetEasy payment * * @param PaynetTransaction $paynetTransaction PaynetEasy payment transaction * @param MageOrder $mageOrder Magento order * * @return PaynetTransaction PaynetEasy payment transaction */ protected function addCreditCardData(PaynetTransaction $paynetTransaction, MageOrder $mageOrder) { $magePayment = Mage::getModel('sales/quote')->load($mageOrder->getQuoteId())->getPayment(); $paynetTransaction->getPayment()->getCreditCard()->setCardPrintedName($magePayment->getCcOwner())->setCreditCardNumber($magePayment->getCcNumber())->setExpireMonth($magePayment->getCcExpMonth())->setExpireYear(substr($magePayment->getCcExpYear(), 2))->setCvv2($magePayment->getCcCid()); }
/** * Build a hash over some unmodifiable(!) order properties. * * @param Mage_Sales_Model_Order $order * @return string */ public function createHashForOrder(Mage_Sales_Model_Order $order) { $orderHash = $order->getId(); $orderHash .= $order->getIncrementId(); $orderHash .= $order->getQuoteId(); $orderHash .= $order->getCustomerEmail(); $orderHash .= $order->getCustomerFirstname(); $orderHash .= $order->getCustomerLastname(); $orderHash .= $order->getShippingMethod(); $orderHash .= $order->getStoreName(); $orderHash .= $order->getGrandTotal(); return hash("sha512", $orderHash); }
/** * Do a Postcode.nl Signal API check on a (newly created) Magento order. * (called by hook class PostcodeNl_Api_Model_Observer) * Will pass any information that can be used by the MijnPolitie.nl MIO Fraud Warning system * (email, phonenumber), or Postcode.nl address validation (billing and delivery address). * Also includes the order number, to be able to reference the Signal Check later. * * @param Mage_Sales_Model_Order $order * * @return array Signal data, or error with 'message' entry. */ public function checkOrderViaSignal($order) { // Check if we are we are enabled, configured & capable of handling an API request $message = $this->_checkApiReady('Signal'); if ($message) { return $message; } // Housenumber data is often contained within the 'street' lines of the address. $billingStreetData = $this->splitStreetData($order->getBillingAddress()->getStreet()); $shippingStreetData = $this->splitStreetData($order->getShippingAddress()->getStreet()); // No customer might be available if this is an order status change $hasCustomer = $order->getCustomer() !== null; // Note if this is executed as an admin, then do not send access details, as that might muddy the customer info $isAdmin = Mage::app()->getStore()->isAdmin(); // Only send phonenumber if it is at least 5 characters long $phoneNumber = Mage::helper('core/string')->strlen($order->getBillingAddress()->getTelephone()) >= 5 ? $order->getBillingAddress()->getTelephone() : null; $signalCheck = array('customer' => array('email' => $hasCustomer ? $order->getCustomer()->getEmail() : null, 'phoneNumber' => $phoneNumber, 'address' => array('postcode' => $order->getBillingAddress()->getPostcode(), 'houseNumber' => $billingStreetData['houseNumber'], 'houseNumberAddition' => $billingStreetData['houseNumberAddition'], 'street' => $billingStreetData['street'], 'city' => $order->getBillingAddress()->getCity(), 'region' => $order->getBillingAddress()->getRegion(), 'country' => $order->getBillingAddress()->getCountryId())), 'access' => array('ipAddress' => $isAdmin ? null : Mage::helper('core/http')->getRemoteAddr(), 'additionalIpAddresses' => array()), 'transaction' => array('internalId' => $order->getIncrementId(), 'deliveryAddress' => array('postcode' => $order->getShippingAddress()->getPostcode(), 'houseNumber' => $shippingStreetData['houseNumber'], 'houseNumberAddition' => $shippingStreetData['houseNumberAddition'], 'street' => $shippingStreetData['street'], 'city' => $order->getShippingAddress()->getCity(), 'region' => $order->getShippingAddress()->getRegion(), 'country' => $order->getShippingAddress()->getCountryId()))); // Retrieve quote for registered remote IP / proxy IP (they are registered at session start) $quoteId = $order->getQuoteId(); $quote = Mage::getModel('sales/quote')->load($quoteId); if ($quote) { $signalCheck['access'] = $this->_addAccessIpAddress($signalCheck['access'], $quote->getRemoteIp()); $signalCheck['access'] = $this->_addAccessIpAddress($signalCheck['access'], $quote->getXForwardedFor()); } // Register current forwarded-for IP address (if not admin) if (!$isAdmin) { $forwardedFor = Mage::app()->getRequest()->getServer('HTTP_X_FORWARDED_FOR'); $signalCheck['access'] = $this->_addAccessIpAddress($signalCheck['access'], $forwardedFor); } return $this->checkSignal($signalCheck); }