예제 #1
0
 public function buildorder()
 {
     $OCRV2 = array();
     $this->language->load('payment/payu');
     $this->load->model('payment/payu');
     $this->loadLibConfig();
     $this->load->model('checkout/order');
     $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     $this->load->model('localisation/country');
     $this->tax->setShippingAddress($order_info['shipping_country_id'], $order_info['shipping_zone_id']);
     $this->tax->setPaymentAddress($order_info['payment_country_id'], $order_info['payment_zone_id']);
     $this->tax->setStoreAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
     $grandTotal = 0;
     $cartItems = array();
     $orderType = 'VIRTUAL';
     $shippingCostAmount = 0.0;
     $decimalPlace = $this->currency->getDecimalPlace();
     if (!empty($this->session->data['vouchers'])) {
         foreach ($this->session->data['vouchers'] as $voucher) {
             $this->vouchersAmount += $this->currency->format($voucher['amount']);
             $OCRV2['products'][] = array('quantity' => 1, 'name' => $voucher['description'], 'unitPrice' => $this->toAmount($voucher['amount']));
         }
     }
     foreach ($this->cart->getProducts() as $item) {
         list($orderType, $OCRV2, $grandTotal) = $this->prepareProductsSection($decimalPlace, $item, $order_info, $OCRV2, $grandTotal);
     }
     $shoppingCart = array('GrandTotal' => $grandTotal, 'CurrencyCode' => $order_info['currency_code'], 'ShoppingCartItems' => $cartItems);
     //$this->session->data['sessionId'] = md5(rand() . rand() . rand() . rand()) . $this->session->data['order_id'];
     $order = array('MerchantPosId' => OpenPayU_Configuration::getMerchantPosId(), 'SessionId' => '', 'OrderUrl' => $this->url->link('payment/payu/callback') . '?order=' . $this->session->data['order_id'], 'OrderCreateDate' => date("c"), 'OrderDescription' => 'Order ' . $this->session->data['order_id'], 'MerchantAuthorizationKey' => OpenPayU_Configuration::getPosAuthKey(), 'OrderType' => $orderType, 'ShoppingCart' => $shoppingCart);
     $OCReq = array('ReqId' => md5(rand()), 'CustomerIp' => $order_info['ip'] == "::1" || $order_info['ip'] == "::" || !preg_match("/^((?:25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9]).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\$/m", $order_info['ip']) ? '127.0.0.1' : $order_info['ip'], 'NotifyUrl' => $this->url->link('payment/payu/ordernotify'), 'OrderCancelUrl' => $this->url->link('payment/payu/paymentcancel'), 'OrderCompleteUrl' => $this->url->link('payment/payu/paymentsuccess'), 'Order' => $order);
     $customer = array();
     if (!empty($order_info['email'])) {
         $customer = array('email' => $order_info['email'], 'firstName' => $order_info['firstname'], 'lastName' => $order_info['lastname'], 'phone' => $order_info['telephone']);
     } elseif (!empty($this->session->data['customer_id'])) {
         $this->load->model('account\\customer');
         $custdata = $this->model_account_customer->getCustomer($this->session['customer_id']);
         if (!empty($custdata['email'])) {
             $customer = array('email' => $order_info['email'], 'firstName' => $order_info['firstname'], 'lastName' => $order_info['lastname'], 'phone' => $order_info['telephone']);
         }
     }
     if ($orderType == 'MATERIAL') {
         if (!empty($customer) && !empty($order_info['shipping_city']) && !empty($order_info['shipping_postcode']) && !empty($order_info['payment_iso_code_2'])) {
             $customer['delivery'] = array('street' => $order_info['shipping_address_1'] . " " . ($order_info['shipping_address_2'] ? $order_info['shipping_address_2'] : ''), 'postalCode' => $order_info['shipping_postcode'], 'city' => $order_info['shipping_city'], 'countryCode' => $order_info['payment_iso_code_2'], 'recipientName' => $order_info['shipping_firstname'] . " " . $order_info['shipping_lastname'], 'recipientPhone' => $order_info['telephone'], 'recipientEmail' => $order_info['email']);
         }
         if (!empty($order_info['shipping_method'])) {
             list($shippingCostList, $shippingCostAmount) = $this->prepareShippingMethodsSection($decimalPlace, $order_info);
         } else {
             $shippingCostList = array();
             $shipping_methods = $this->getShippings($this->session->data['order_id'], $order_info['shipping_country_id']);
             $country = $this->model_localisation_country->getCountry($order_info['shipping_country_id']);
             foreach ($shipping_methods as $onemethod) {
                 if (empty($decimalPlace)) {
                     $onemethod['cost'] *= 100;
                     $shippingCostAmount = $shippingCost;
                 }
                 $price = $this->currency->format($this->tax->calculate($onemethod['cost'], $onemethod['tax_class_id']), $order_info['currency_code'], false, false);
                 $price = preg_replace("/[^0-9]/", "", $price);
                 $shippingCostList['shippingMethods'][] = array('name' => $onemethod['title'], 'country' => $country['iso_code_2'], 'price' => $price);
             }
         }
     }
     if (isset($this->session->data['coupon']) || !empty($this->session->data['coupon'])) {
         $OCRV2 = $this->prepareCumulatedProductsArray($OCRV2, $order_info, $shippingCostAmount);
     }
     $OCRV2['merchantPosId'] = OpenPayU_Configuration::getMerchantPosId();
     $OCRV2['orderUrl'] = $this->url->link('payment/payu/callback') . '?order=' . $this->session->data['order_id'];
     $OCRV2['description'] = "Zamówienie #" . $this->session->data['order_id'];
     $OCRV2['customerIp'] = $OCReq['CustomerIp'];
     $OCRV2['notifyUrl'] = $OCReq['NotifyUrl'];
     $OCRV2['cancelUrl'] = $OCReq['OrderCancelUrl'];
     $OCRV2['continueUrl'] = $OCReq['OrderCompleteUrl'];
     $OCRV2['currencyCode'] = $order_info['currency_code'];
     $total = $order_info['total'];
     if (empty($decimalPlace)) {
         $total = $this->toAmount($total);
     }
     $total = str_ireplace(array('.', ' '), array('', ''), $this->currency->format($total - $shippingCostAmount, $order_info['currency_code'], false, false));
     $OCRV2['totalAmount'] = $total;
     $OCRV2['extOrderId'] = $this->session->data['order_id'] . '-' . microtime();
     if (isset($shippingCostList)) {
         $OCRV2['shippingMethods'] = $shippingCostList['shippingMethods'];
     }
     $OCRV2['buyer'] = $customer;
     return $OCRV2;
 }
 public function testPosAuthKey()
 {
     OpenPayU_Configuration::setPosAuthKey('PosAuthKey');
     $this->assertEquals('PosAuthKey', OpenPayU_Configuration::getPosAuthKey());
 }