public function beforesummary() { $this->loadLibConfig(); $result = OpenPayU_OAuth::accessTokenByCode($this->request->get['code'], $this->url->link('payment/payu/beforesummary', '', 'SSL')); echo "Redirecting.."; echo '<form method="GET" action="' . OpenPayu_Configuration::getSummaryUrl() . '" id="payu_checkout" lang="' . $this->session->data['language'] . '">'; echo '<input type="hidden" name="lang" value="' . $this->session->data['language'] . '">'; echo '<input type="hidden" name="sessionId" value="' . $_SESSION['sessionId'] . '">'; echo '<input type="hidden" name="oauth_token" value="' . $result->getAccessToken() . '">'; echo '</form>'; echo '<script type="text/javascript">document.getElementById("payu_checkout").submit();</script>'; }
/** * Initializes the payment. * @param Mage_Sales_Model_Order * @param Mage_Shipping_Model_Shipping * @return array */ public function orderCreateRequest(Mage_Sales_Model_Order $order, $allShippingRates) { $this->_order = $order; $orderCurrencyCode = $this->_order->getOrderCurrencyCode(); $orderCountryCode = $this->_order->getBillingAddress()->getCountry(); $shippingCostList = array(); if (empty($allShippingRates) || Mage::getSingleton('customer/session')->isLoggedIn()) { if ($order->getShippingInclTax() > 0) { $shippingCostList['shippingMethods'][] = array('name' => $order->getShippingDescription(), 'country' => $orderCountryCode, 'price' => $this->toAmount($order->getShippingInclTax())); } $grandTotal = $this->_order->getGrandTotal() - $order->getShippingInclTax(); } else { $firstPrice = 0; foreach ($allShippingRates as $key => $rate) { $gross = $this->toAmount($rate->getPrice()); if ($key == 0) { $firstPrice = $rate->getPrice(); } $shippingCostList['shippingMethods'][] = array('name' => $rate->getMethodTitle(), 'country' => $orderCountryCode, 'price' => $gross); } $grandTotal = $this->_order->getGrandTotal() - $firstPrice; } $shippingCost = array('countryCode' => $orderCountryCode, 'shipToOtherCountry' => 'true', 'shippingCostList' => $shippingCostList); $orderItems = $this->_order->getAllVisibleItems(); $items = array(); $productsTotal = 0; $is_discount = false; foreach ($orderItems as $key => $item) { $itemInfo = $item->getData(); if ($itemInfo['discount_amount'] > 0) { $itemInfo['price_incl_tax'] = $itemInfo['price_incl_tax'] - $itemInfo['discount_amount']; $is_discount = true; } else { if ($itemInfo['discount_percent'] > 0) { $itemInfo['price_incl_tax'] = $itemInfo['price_incl_tax'] * (100 - $itemInfo['discount_percent']) / 100; } } // Check if the item is countable one if ($this->toAmount($itemInfo['price_incl_tax']) > 0) { $items['products'][] = array('quantity' => (int) $itemInfo['qty_ordered'], 'name' => $itemInfo['name'], 'unitPrice' => $this->toAmount($itemInfo['price_incl_tax'])); $productsTotal += $itemInfo['price_incl_tax'] * $itemInfo['qty_ordered']; } } //if($this->_order->getShippingAmount () > 0 && !empty ( $shippingCostList['shippingMethods'][0] ) ){ // $items ['products'] ['products'] [] = array ( // 'quantity' => 1 ,'name' => Mage::helper ( 'payu_account' )->__('Shipping costs') . " - " . $shippingCostList['shippingMethods'][0]['name'] ,'unitPrice' => $this->toAmount ( $this->_order->getShippingAmount () )); //} // assigning the shopping cart $shoppingCart = array('grandTotal' => $this->toAmount($grandTotal), 'CurrencyCode' => $orderCurrencyCode, 'ShoppingCartItems' => $items); $orderInfo = array('merchantPosId' => OpenPayU_Configuration::getMerchantPosId(), 'orderUrl' => Mage::getBaseUrl() . 'sales/order/view/order_id/' . $this->_order->getId() . '/', 'description' => 'Order no ' . $this->_order->getRealOrderId(), 'validityTime' => $this->_config->getOrderValidityTime()); if ($is_discount) { $items['products'] = array(); $items['products'][] = array('quantity' => 1, 'name' => Mage::helper('payu_account')->__('Order # ') . $this->_order->getId(), 'unitPrice' => $this->toAmount($grandTotal)); } $OCReq = $orderInfo; $OCReq['products'] = $items['products']; $OCReq['customerIp'] = Mage::app()->getFrontController()->getRequest()->getClientIp(); $OCReq['notifyUrl'] = $this->_myUrl . 'orderNotifyRequest'; $OCReq['cancelUrl'] = $this->_myUrl . 'cancelPayment'; $OCReq['continueUrl'] = $this->_myUrl . 'continuePayment'; $OCReq['currencyCode'] = $orderCurrencyCode; $OCReq['totalAmount'] = $shoppingCart['grandTotal']; $OCReq['extOrderId'] = $this->_order->getId() . '-' . microtime(); if (!empty($shippingCostList)) { $OCReq['shippingMethods'] = $shippingCostList['shippingMethods']; } unset($OCReq['shoppingCart']); $customer_sheet = array(); $billingAddressId = $this->_order->getBillingAddressId(); if (!empty($billingAddressId)) { $billingAddress = $this->_order->getBillingAddress(); $customer_mail = $billingAddress->getEmail(); if (!empty($customer_mail)) { $customer_sheet = array('email' => $billingAddress->getEmail(), 'phone' => $billingAddress->getTelephone(), 'firstName' => $billingAddress->getFirstname(), 'lastName' => $billingAddress->getLastname()); $shippingAddressId = $this->_order->getShippingAddressId(); if (!empty($shippingAddressId)) { $shippingAddress = $this->_order->getShippingAddress(); } if (!$this->_order->getIsVirtual()) { $customer_sheet['delivery'] = array('street' => trim(implode(' ', $shippingAddress->getStreet())), 'postalCode' => $shippingAddress->getPostcode(), 'city' => $shippingAddress->getCity(), 'countryCode' => $shippingAddress->getCountry(), 'recipientName' => trim($shippingAddress->getFirstname() . ' ' . $shippingAddress->getLastname()), 'recipientPhone' => $shippingAddress->getTelephone(), 'recipientEmail' => $shippingAddress->getEmail()); } $OCReq['buyer'] = $customer_sheet; } } $result = OpenPayU_Order::create($OCReq); if ($result->getStatus() == 'SUCCESS') { // store session identifier in session info Mage::getSingleton('core/session')->setPayUSessionId($result->getResponse()->orderId); // assign current transaction id $this->_transactionId = $result->getResponse()->orderId; $order->getPayment()->setLastTransId($this->_transactionId); $locale = Mage::getStoreConfig('general/locale/code', Mage::app()->getStore()->getId()); $lang_code = explode('_', $locale, 2); $ret = array('redirectUri' => $result->getResponse()->redirectUri, 'url' => OpenPayu_Configuration::getSummaryUrl(), 'sessionId' => $result->getResponse()->orderId, 'lang' => strtolower($lang_code[1])); $customer = Mage::getModel('customer/customer'); if ($this->_order->getCustomerIsGuest()) { $email = $billingAddress->getEmail(); $customer->setWebsiteId(Mage::app()->getWebsite()->getId()); $customer->loadByEmail($email); } else { $customer->load($this->_order->getCustomerId()); } if (!$customer->getId()) { $this->_order->setCustomerEmail($email); } $this->_order->sendNewOrderEmail(); $this->_order->save(); } else { Mage::throwException(Mage::helper('payu_account')->__('There was a problem with initializing the payment, please contact the store administrator. ' . $result->getError())); } return $ret; }