public function getPostData()
 {
     $orderId = $this->_checkoutSession->getLastOrderId();
     if ($orderId) {
         $incrementId = $this->_checkoutSession->getLastRealOrderId();
         return $this->Config->getPostData($incrementId);
     }
 }
Example #2
0
 /**
  * Record order shipping information after order is placed
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     if ($this->shipperDataHelper->getConfigValue('carriers/shipper/active')) {
         $order = $this->orderFactory->create()->loadByIncrementId($this->checkoutSession->getLastRealOrderId());
         if ($order->getIncrementId()) {
             $this->recordOrder($order);
         }
     }
 }
Example #3
0
 /**
  * Return order instance with loaded information by increment id
  *
  * @return \Magento\Sales\Model\Order
  */
 protected function _getOrder()
 {
     if ($this->getOrder()) {
         $order = $this->getOrder();
     } elseif ($this->_checkoutSession->getLastRealOrderId()) {
         $order = $this->_salesOrderFactory->create()->loadByIncrementId($this->_checkoutSession->getLastRealOrderId());
     } else {
         return null;
     }
     return $order;
 }
Example #4
0
 /**
  * Return array with data to send to MP api
  *
  * @return array
  */
 public function makePreference()
 {
     $orderIncrementId = $this->_checkoutSession->getLastRealOrderId();
     $order = $this->_orderFactory->create()->loadByIncrementId($orderIncrementId);
     $customer = $this->_customerSession->getCustomer();
     $payment = $order->getPayment();
     $paramsShipment = new \Magento\Framework\DataObject();
     $paramsShipment->setParams([]);
     $this->_eventManager->dispatch('mercadopago_standard_make_preference_before', ['params' => $paramsShipment, 'order' => $order]);
     $arr = [];
     $arr['external_reference'] = $orderIncrementId;
     $arr['items'] = $this->getItems($order);
     $this->_calculateDiscountAmount($arr['items'], $order);
     $this->_calculateBaseTaxAmount($arr['items'], $order);
     $total_item = $this->getTotalItems($arr['items']);
     $total_item += (double) $order->getBaseShippingAmount();
     $order_amount = (double) $order->getBaseGrandTotal();
     if (!$order_amount) {
         $order_amount = (double) $order->getBasePrice() + $order->getBaseShippingAmount();
     }
     if ($total_item > $order_amount || $total_item < $order_amount) {
         $diff_price = $order_amount - $total_item;
         $arr['items'][] = ["title" => "Difference amount of the items with a total", "description" => "Difference amount of the items with a total", "category_id" => $this->_scopeConfig->getValue('payment/mercadopago/category_id', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), "quantity" => 1, "unit_price" => (double) $diff_price];
         $this->_helperData->log("Total itens: " . $total_item, 'mercadopago-standard.log');
         $this->_helperData->log("Total order: " . $order_amount, 'mercadopago-standard.log');
         $this->_helperData->log("Difference add itens: " . $diff_price, 'mercadopago-standard.log');
     }
     if ($order->canShip()) {
         $shippingAddress = $order->getShippingAddress();
         $shipping = $shippingAddress->getData();
         $arr['payer']['phone'] = ["area_code" => "-", "number" => $shipping['telephone']];
         $arr['shipments'] = $this->_getParamShipment($paramsShipment, $order, $shippingAddress);
     }
     $billing_address = $order->getBillingAddress()->getData();
     $arr['payer']['date_created'] = date('Y-m-d', $customer->getCreatedAtTimestamp()) . "T" . date('H:i:s', $customer->getCreatedAtTimestamp());
     $arr['payer']['email'] = htmlentities($customer->getEmail());
     $arr['payer']['first_name'] = htmlentities($customer->getFirstname());
     $arr['payer']['last_name'] = htmlentities($customer->getLastname());
     if (isset($payment['additional_information']['doc_number']) && $payment['additional_information']['doc_number'] != "") {
         $arr['payer']['identification'] = ["type" => "CPF", "number" => $payment['additional_information']['doc_number']];
     }
     $arr['payer']['address'] = ["zip_code" => $billing_address['postcode'], "street_name" => $billing_address['street'] . " - " . $billing_address['city'] . " - " . $billing_address['country_id'], "street_number" => ""];
     $url = $this->_helperData->getSuccessUrl();
     $arr['back_urls'] = ['success' => $this->_urlBuilder->getUrl($url), 'pending' => $this->_urlBuilder->getUrl($url), 'failure' => $this->_urlBuilder->getUrl('checkout/onepage/failure')];
     $arr['notification_url'] = $this->_urlBuilder->getUrl("mercadopago/notifications/standard");
     $arr['payment_methods']['excluded_payment_methods'] = $this->getExcludedPaymentsMethods();
     $installments = $this->getConfigData('installments');
     $arr['payment_methods']['installments'] = (int) $installments;
     $auto_return = $this->getConfigData('auto_return');
     if ($auto_return == 1) {
         $arr['auto_return'] = "approved";
     }
     $sponsor_id = $this->_scopeConfig->getValue('payment/mercadopago/sponsor_id', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $this->_helperData->log("Sponsor_id", 'mercadopago-standard.log', $sponsor_id);
     if (!empty($sponsor_id)) {
         $this->_helperData->log("Sponsor_id identificado", 'mercadopago-standard.log', $sponsor_id);
         $arr['sponsor_id'] = (int) $sponsor_id;
     }
     return $arr;
 }
Example #5
0
 /**
  * Get last order ID from session, fetch it and check whether it can be viewed, printed etc
  *
  * @return void
  */
 protected function _prepareLastOrder()
 {
     $orderId = $this->_checkoutSession->getLastOrderId();
     if ($orderId) {
         $incrementId = $this->_checkoutSession->getLastRealOrderId();
         $status = $this->_checkoutSession->getLastOrderStatus();
         if ($status && $incrementId) {
             $isVisible = !in_array($status, $this->_orderConfig->getInvisibleOnFrontStatuses());
             $canView = $this->httpContext->getValue(Context::CONTEXT_AUTH) && $isVisible;
             $this->addData(['is_order_visible' => $isVisible, 'view_order_url' => $this->getUrl('sales/order/view/', ['order_id' => $orderId]), 'print_url' => $this->getUrl('sales/order/print', ['order_id' => $orderId]), 'can_print_order' => $isVisible, 'can_view_order' => $canView, 'order_id' => $incrementId]);
         }
     }
 }
 /**
  * Instantiate
  *
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _initCheckout()
 {
     $pre = __METHOD__ . " : ";
     $this->_logger->debug($pre . 'bof');
     $this->_order = $this->_checkoutSession->getLastRealOrder();
     if (!$this->_order->getId()) {
         $this->getResponse()->setStatusHeader(404, '1.1', 'Not found');
         throw new \Magento\Framework\Exception\LocalizedException(__('We could not find "Order" for processing'));
     }
     if ($this->_order->getState() != \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT) {
         $this->_order->setState(\Magento\Sales\Model\Order::STATE_PENDING_PAYMENT)->save();
     }
     if ($this->_order->getQuoteId()) {
         $this->_checkoutSession->setPayfastQuoteId($this->_checkoutSession->getQuoteId());
         $this->_checkoutSession->setPayfastSuccessQuoteId($this->_checkoutSession->getLastSuccessQuoteId());
         $this->_checkoutSession->setPayfastRealOrderId($this->_checkoutSession->getLastRealOrderId());
         $this->_checkoutSession->getQuote()->setIsActive(false)->save();
         //$this->_checkoutSession->clear();
     }
     $this->_logger->debug($pre . 'eof');
     //$this->_checkout = $this->_checkoutTypes[$this->_checkoutType];
 }
Example #7
0
 /**
  * @return mixed
  */
 public function getRealOrderId()
 {
     return $this->_checkoutSession->getLastRealOrderId();
 }
 /**
  * Get order object
  *
  * @return \Magento\Sales\Model\Order
  */
 protected function getOrder()
 {
     return $this->_orderFactory->create()->loadByIncrementId($this->_checkoutSession->getLastRealOrderId());
 }
Example #9
0
 /**
  * @return \Magento\Sales\Model\Order
  */
 protected function _getOrder()
 {
     $orderIncrementId = $this->_checkoutSession->getLastRealOrderId();
     $order = $this->_orderFactory->create()->loadByIncrementId($orderIncrementId);
     return $order;
 }
 /**
  * @return array
  */
 public function getInfoPayment()
 {
     $order_id = $this->_checkoutSession->getLastRealOrderId();
     $info_payments = $this->_coreFactory->create()->getInfoPaymentByOrder($order_id);
     return $info_payments;
 }