/** * 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; }
/** * Return success page url * * @return string */ public function getOrderPlaceRedirectUrl() { $url = $this->_helperData->getSuccessUrl(); return $this->_urlBuilder->getUrl($url, ['_secure' => true]); }