Пример #1
0
 public function createRequest(array $data)
 {
     $shoppingCart = array('GrandTotal' => $data['grand_total'], 'CurrencyCode' => $data['currency_code'], 'ShoppingCartItems' => $data['items']);
     $order = array('MerchantPosId' => $this->merchantPosId, 'SessionId' => $this->sessionId, 'OrderUrl' => '/payment/order/id', 'OrderCreateDate' => date("c"), 'OrderDescription' => 'MASP Payment', 'MerchantAuthorizationKey' => $this->posAuthKey, 'OrderType' => $data['order_type'], 'ShoppingCart' => $shoppingCart);
     $OCReq = array('ReqId' => md5(rand()), 'CustomerIp' => $_SERVER['REMOTE_ADDR'], 'NotifyUrl' => $this->notifyUrl, 'OrderCancelUrl' => $this->cancelUrl, 'OrderCompleteUrl' => $this->completeUrl, 'Order' => $order, 'RefOrderId' => $data['order_id']);
     $result = \OpenPayU_Order::create($OCReq);
     return $result;
 }
 /**
  * @param array      $orderDetails
  * @param array|null $options
  *
  * @return RedirectResponse
  */
 public function createOrder(array $orderDetails = [], array $options = [])
 {
     $resolver = new OptionsResolver();
     $this->configureOrder($resolver);
     $this->orderDetails = $resolver->resolve($orderDetails);
     $response = \OpenPayU_Order::create($this->orderDetails);
     /** @var Payment $payment */
     $payment = new $this->class();
     $payment->setId($response->getResponse()->orderId)->setOrderId($response->getResponse()->extOrderId);
     if (!empty($options)) {
         $accessor = PropertyAccess::createPropertyAccessor();
         foreach ($options as $key => $value) {
             $accessor->setValue($payment, $key, $value);
         }
     }
     $this->em->persist($payment);
     $this->em->flush();
     return $this->redirectToUrl($response->getResponse()->redirectUri);
 }
Пример #3
0
 /**
  * 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;
 }
Пример #4
0
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title>Create Order - OpenPayU v2</title>
    <link rel="stylesheet" href="../../layout/css/bootstrap.min.css">
    <link rel="stylesheet" href="../../layout/css/style.css">
</head>

<body>
<div class="container">
    <div class="page-header">
        <h1>Create Order - OpenPayU v2</h1>
    </div>
    <?php 
try {
    $response = OpenPayU_Order::create($order);
    $status_desc = OpenPayU_Util::statusDesc($response->getStatus());
    if ($response->getStatus() == 'SUCCESS') {
        echo '<div class="alert alert-success">SUCCESS: ' . $status_desc;
        echo '</div>';
    } else {
        echo '<div class="alert alert-warning">' . $response->getStatus() . ': ' . $status_desc;
        echo '</div>';
    }
} catch (OpenPayU_Exception $e) {
    echo '<pre>';
    var_dump((string) $e);
    echo '</pre>';
}
?>
Пример #5
0
 public function expresscheckout()
 {
     ob_start();
     $this->load->model('checkout/order');
     $this->loadLibConfig();
     $cart = $this->cart->getProducts();
     if (empty($cart)) {
         $this->redirect($this->url->link('checkout/cart'));
     }
     $this->session->data['order_id'] = $this->collectData();
     $order = $this->buildorder();
     $result = OpenPayU_Order::create($order);
     ob_end_flush();
     if ($result->getStatus() == 'SUCCESS') {
         $this->session->data['sessionId'] = $result->getResponse()->orderId;
         $this->model_payment_payu->addOrder($this->session->data['order_id'], $this->session->data['sessionId']);
         $this->data['actionUrl'] = $result->getResponse()->redirectUri;
         header('Location:' . $this->data['actionUrl']);
     } else {
         $this->logger->write($result->getError() . ' [' . serialize($result->getResponse()) . ']');
         $this->redirect($this->url->link('checkout/cart'));
     }
 }
Пример #6
0
 /**
  * @param array $data
  * @return \OpenPayU_Result
  * @throws \OpenPayU_Exception
  */
 public function orderCreate(array $data)
 {
     return \OpenPayU_Order::create($data);
 }
Пример #7
0
 public function create($order)
 {
     return \OpenPayU_Order::create($order);
 }
Пример #8
0
 /**
  * @return array
  */
 public function orderCreateRequest()
 {
     SimplePayuLogger::addLog('order', __FUNCTION__, $this->l('Entrance'), $this->payu_order_id);
     $currency = Currency::getCurrency($this->cart->id_currency);
     $return_array = array();
     $items = array();
     $cart_products = $this->cart->getProducts();
     //discounts and cart rules
     list($items, $total) = $this->getDiscountsAndCartRules($items, $cart_products);
     // Wrapping fees
     list($wrapping_fees_tax_inc, $items, $total) = $this->getWrappingFees($items, $total);
     $carriers_list = $this->getCarriersListForCart($this->cart);
     $grand_total = $this->getGrandTotal($wrapping_fees_tax_inc, $total);
     list($order_complete_link, $order_notify_link, $order_cancel_link) = $this->getLinks();
     if (!empty($this->cart->id_customer)) {
         $customer = new Customer((int) $this->cart->id_customer);
         if ($customer->email) {
             $customer_sheet = $this->getCustomer($customer);
         }
     }
     //prepare data for OrderCreateRequest
     $ocreq = $this->prepareOrder($items, $customer_sheet, $order_notify_link, $order_cancel_link, $order_complete_link, $currency, $grand_total, $carriers_list);
     try {
         SimplePayuLogger::addLog('order', __FUNCTION__, print_r($ocreq, true), $this->payu_order_id, 'OrderCreateRequest: ');
         $result = OpenPayU_Order::create($ocreq);
         SimplePayuLogger::addLog('order', __FUNCTION__, print_r($result, true), $this->payu_order_id, 'OrderCreateResponse: ');
         if ($result->getStatus() == 'SUCCESS') {
             $context = Context::getContext();
             $context->cookie->__set('payu_order_id', $result->getResponse()->orderId);
             $return_array = array('redirectUri' => urldecode($result->getResponse()->redirectUri), 'orderId' => $result->getResponse()->orderId);
         } else {
             SimplePayuLogger::addLog('order', __FUNCTION__, 'OpenPayU_Order::create($ocreq) NOT success!! ' . $this->displayName . ' ' . trim($result->getError() . ' ' . $result->getMessage(), $this->payu_order_id));
             Logger::addLog($this->displayName . ' ' . trim($result->getError() . ' ' . $result->getMessage()), 1);
         }
     } catch (Exception $e) {
         SimplePayuLogger::addLog('order', __FUNCTION__, 'Exception catched! ' . $this->displayName . ' ' . trim($e->getCode() . ' ' . $e->getMessage()));
         Logger::addLog($this->displayName . ' ' . trim($e->getCode() . ' ' . $e->getMessage()), 1);
     }
     return $return_array;
 }
Пример #9
0
 function process($order_id)
 {
     if (!$this->isLoggedIn) {
         redirect('/login', 'refresh');
     }
     $this->load->model('Ordermodel');
     $_order = $this->Ordermodel->get_order($this->session->userdata['user']->id, $order_id, 'W');
     if ($_order == null) {
         $this->http404();
     }
     $_order = $_order[0];
     $this->config->load('payu', true);
     OpenPayU_Configuration::setEnvironment('secure');
     OpenPayU_Configuration::setMerchantPosId($this->config->item('PosId', 'payu'));
     OpenPayU_Configuration::setSignatureKey($this->config->item('SignatureKey', 'payu'));
     $order = array();
     $order['notifyUrl'] = base_url() . 'index.php/order/notify';
     //$order['notifyUrl'] = "http://t01.pl/payu/index.php";
     $order['continueUrl'] = base_url() . 'index.php/user_panel/history';
     $order['customerIp'] = $this->input->ip_address();
     $order['merchantPosId'] = OpenPayU_Configuration::getMerchantPosId();
     $order['description'] = $this->config->item('title', 'payu');
     $order['currencyCode'] = 'PLN';
     //$order['extOrderId'] = "think01-".time().'-'.$order_id;
     $order['products'] = array();
     $cost = 0;
     if (count($_order->cart) == 0) {
         return false;
     }
     foreach ($_order->cart as $v) {
         array_push($order['products'], array('name' => $v->diet, 'unitPrice' => $v->price, 'quantity' => $v->quantity));
         $cost += $v->price * $v->quantity;
     }
     $order['totalAmount'] = $cost;
     $order['buyer']['email'] = $v->email;
     $order['buyer']['phone'] = preg_replace('/[^0-9\\+]/', '', $v->phone);
     $order['buyer']['firstName'] = $v->name;
     $order['buyer']['lastName'] = $v->surname;
     try {
         //echo '<pre>'; print_r($order); die('');
         $response = OpenPayU_Order::create($order);
         $status_desc = OpenPayU_Util::statusDesc($response->getStatus());
         if ($response->getStatus() == 'SUCCESS') {
             $this->Ordermodel->set_payment_id($order_id, $response->getResponse()->orderId);
             redirect($response->getResponse()->redirectUri, 'refresh');
         } else {
             $this->show("alert", array('msg' => '<pre>' . print_r($order, true) . '</pre><br>' . $response->getStatus() . ': ' . $status_desc));
         }
         return;
     } catch (OpenPayU_Exception $e) {
         $this->show("alert", array('msg' => '<pre>' . print_r($order, true) . '</pre><br>' . (string) $e));
     }
 }