@Livingstondd92

Почему нет скидки?

Пытаюсь разобраться в чужом коде. Подскажите, почему на банковской странице оплаты за товар в значении AMOUNT выводится сумма без скидки?
<?php
/**
* Оплата
*/
class Psb_paymentController extends App
{
	public function defaultAction($in)
	{
		require(INCLUDES_PATH . DS . 'default.settings.php');
		if(empty($in['url_data'][1]))
		{
			self::setTemplate($this->data);
			return;
		}

		$order_id = intval($in['url_data'][1]);
		$db = new DB;
		$products = new Products;
		$order = $db->getObjectSql('orders',array('order_details','pay_coins','id','user_details','delivery_id','express','payment_price','payment_dpd','date','cupon_title','cupon'),array('status = 1','id = ' . $order_id));
		$config = self::getConfig();

		if(empty($order))
		{
			self::setTemplate($this->data);
			return;
		}
		$today_error_link = date('Y-m-d H:i:s');
		$date_error_link1 = new DateTime($order->date);
		$date_error_link2 = new DateTime($today_error_link);
		$diff_error_link = $date_error_link2->diff($date_error_link1);
		$days_error_link =  $diff_error_link->format('%a');
		$days_error_link = (int) $days_error_link;
		if ($days_error_link > 5) 
		{
			self::setTemplate($this->data);
			return;
		}
		$actual_cupon = $db->getObjectSql('codes',array('*'), array('title="'.$order->cupon_title.'"'));			
		$order->order_details = json_decode($order->order_details);
		$user_info = json_decode($order->user_details);
		$summ = 0;
		foreach ($order->order_details as $key => $detail) 
		{
			$product = $products->viewArticle($detail->id);
			
			//###############//
			if (!empty($actual_cupon) and !empty($order->cupon)) 
			{
				if (empty($actual_cupon->all_products)) 
				{
					$coefficient = $product->priceInt/100;
					$coefficient = $coefficient*(int)$order->cupon;
					$product->priceInt = ($product->priceInt-$coefficient);
				}
				else
				{
					$iden_products = json_decode($actual_cupon->products);
					$iden_key = array_search($product->id, $iden_products);
					if ($iden_key !== false) 
					{
						$coefficient = $product->priceInt/100;
						$coefficient = $coefficient*(int)$order->cupon;
						$product->priceInt = ($product->priceInt-$coefficient);
					}
				}
			}
			//#######Условие для вывода скидки########//
		//	$summ = $summ + ($detail->count * $product->priceInt); 

		if ($product->discount_summ > 0)
			$summ = $summ + ($detail->count * $product->discount_summ);
		else
			$summ = $summ + ($detail->count * $product->priceInt);

		}

		$summ = number_format($summ, 2, '.', '');

		if($summ == 0)
		{
			self::setTemplate($this->data);
			return;
		}
		
		if ($order->pay_coins != 0) 
		{
			$summ = $summ-$order->pay_coins;
		}

		if ($order->delivery_id == 2) 
		{
			if ($order->express == 1) 
			{
				$summ = $summ+200;
			}
			else
			{
				
				if ($summ < (int)$config['site_pricedelivery']) 
				{
					$summ = $summ+100;
				}
			}
		}

		if ($order->delivery_id == 3) 
		{
			if ($order->payment_dpd == 1) 
			{
				$summ = $summ+$order->payment_price;
			}
			if ($order->payment_dpd == 2) 
			{
				$summ = $summ+$order->payment_price;
			}
		}

		$date = new \DateTime('-9 hours');
		$qq = $date->format('YmdHis');
		$this->data['AMOUNT'] = $summ;
		$this->data['CURRENCY'] = 'RUB';
		$this->data['ORDER'] = 100000+$order_id;
		$this->data['DESC'] = 'Оплата заказа на сайте medexpress.pro';
		$this->data['TERMINAL'] = $config['psb_terminal'];
		$this->data['TRTYPE'] = 1;
		$this->data['MERCH_NAME'] = 'MEDEXPRESS';
		$this->data['MERCHANT'] = $config['psb_merchant'];
		$this->data['EMAIL'] = $user_info->email;
		$this->data['CARDHOLDER_NOTIFY'] = 'EMAIL';
		$this->data['TIMESTAMP'] = $qq;
		$this->data['NONCE'] = substr(md5(rand(1,9999).microtime()), 0, 16);
		$this->data['BACKREF'] = 'https://medexpress.pro';

		$string_h = iconv_strlen($this->data['AMOUNT']) .''.$this->data['AMOUNT'].''.iconv_strlen($this->data['CURRENCY']).''.$this->data['CURRENCY'].''.iconv_strlen($this->data['ORDER']).''.$this->data['ORDER'].''.iconv_strlen($this->data['MERCH_NAME']).''.$this->data['MERCH_NAME'].''.iconv_strlen($this->data['MERCHANT']).''.$this->data['MERCHANT'].''.iconv_strlen($this->data['TERMINAL']).''.$this->data['TERMINAL'].''.iconv_strlen($this->data['EMAIL']).''.$this->data['EMAIL'] . '' . iconv_strlen($this->data['TRTYPE']) .''.$this->data['TRTYPE'].''.iconv_strlen($this->data['TIMESTAMP']).''.$this->data['TIMESTAMP'].''.iconv_strlen($this->data['NONCE']).''.$this->data['NONCE'].''.iconv_strlen($this->data['BACKREF']).''.$this->data['BACKREF'];
		$hmac = hash_hmac('sha1',$string_h,pack('H*', $config['psb_key']));
		$this->data['P_SIGN'] = $hmac;
		self::setTemplate($this->data,'psb_payment');
	}
}
?>
  • Вопрос задан
  • 106 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы