<?php
if( $aActions['a'] == 'return' ){
	if( isset( $_POST['status'] ) ) $status = $_POST['status'];
	if( isset( $status ) && $status == 'FAIL' ){
		$oTpl->assign( 'aMessage', Array( 'message' => $lang['There_are_no_money_to_pay'], 'bError' => true ) );
		$content.= $oTpl->parse( 'message.tpl' );
	} elseif( isset( $status ) && $status == 'OK' ){
		$oTpl->assign( 'aMessage', Array( 'message' => $lang['There_are_money_to_pay'] ) );
		$content.= $oTpl->parse( 'message.tpl' );
	} else{
		$oTpl->assign( 'aMessage', Array( 'message' => $lang['Authorization_error'], 'bError' => true ) );
		$content.= $oTpl->parse( 'message.tpl' );
	}
} elseif( $aActions['a'] == 'payu_verify' ){
	if( !empty( $_POST['pos_id'] ) && !empty( $_POST['session_id'] ) && !empty( $_POST['ts'] ) && !empty( $_POST['sig'] ) ){
		if( $_POST['pos_id'] != $config['platnosci_id'] ){
			echo( 'Błędny POS_ID' );
			exit;
		}
		if( $_POST['sig'] != md5( $config['platnosci_id'] . $_POST['session_id'] . $_POST['ts'] . $config['platnosci_key2'] ) ){
			echo( 'Błędny SIG' );
			exit;
		}
		$iOrder = 'SELECT `iOrder` FROM `' . $oDB->throwTableName( DB_ORDERS ) . '` WHERE `iOrder` = ' . intval( $_POST['session_id'] ) . ' AND `iPaymentSystem` = ' . PAYU_SYSTEM;
		$iOrder = $oDB->executeSQL( $iOrder, true, DataBase::SINGLE_VALUE );
		if( $iOrder != $_POST['session_id'] ){
			echo( 'Błędny Session_id' );
			exit;
		}
		$ts = time();
		$xmlData = http::httpPost( 'secure.payu.com', 443, '/paygw/UTF/Payment/get/xml', 'pos_id=' . $config['platnosci_id'] . '&session_id=' . $iOrder . '&ts=' . $ts . '&sig=' . md5( $config['platnosci_id'] . $iOrder . $ts . $config['platnosci_key1'] ), 'ssl://', false );
		function xPathVal( $xPath, $sPath, $oNode = null ){
			if( isset( $oNode ) ) $oTmp = $xPath->query( $sPath, $oNode );
			else $oTmp = $xPath->query( $sPath );
			if( empty( $oTmp->item( 0 )->value ) && isset( $oTmp->item( 0 )->childNodes ) ){
				return $oTmp->item( 0 )->childNodes->item( 0 )->wholeText;
			} else{
				return $oTmp->item( 0 )->value;
			}
		}
		$oXml = new DomDocument();
		$oXml->loadXML( $xmlData );
		$xPath = new DOMXPath( $oXml );
		$pos_id = xPathVal( $xPath, '/response/trans/pos_id' );
		$session_id = xPathVal( $xPath, '/response/trans/session_id' );
		$order_id = xPathVal( $xPath, '/response/trans/order_id' );
		$status = xPathVal( $xPath, '/response/trans/status' );
		$amount = xPathVal( $xPath, '/response/trans/amount' );
		$desc = xPathVal( $xPath, '/response/trans/desc' );
		$ts = xPathVal( $xPath, '/response/trans/ts' );
		$sig = xPathVal( $xPath, '/response/trans/sig' );

		if( $pos_id != $config['platnosci_id'] ){
			echo('Błędny POS_ID w odpowiedzi na zapytanie o transakcję');
			exit;
		}
		if( $sig != md5( $pos_id . $session_id . $order_id . $status . $amount . $desc . $ts . $config['platnosci_key2'] ) ){
			echo('Błędny SIG w odpowiedzi na zapytanie o transakcję');
			exit;
		}
		
		$fOrderAdvance = $oDB->executeSQL( 'SELECT `sOrderAdvance` FROM `' . $oDB->throwTableName( DB_ORDERS ) . '` WHERE `iOrder` = ' . intval( $session_id ) . ' AND `iPaymentSystem` = ' . PAYU_SYSTEM, true, DATABASE::SINGLE_VALUE );
		$fOrderAdvance = round( $fOrderAdvance * 100 );
		if( $fOrderAdvance > 0 && $amount == $fOrderAdvance ){
			$oDB->executeSQL( 'UPDATE `' . $oDB->throwTableName( DB_ORDERS ) . '` SET `iOrderAdvance` = 2 WHERE `iOrder` = ' . intval( $session_id ) . ' AND `iPaymentSystem` = ' . PAYU_SYSTEM );
			$oOrder->changeStatus( $iOrder, 24 );
		}else{
			$iOrder = $oDB->executeSQL( 'SELECT `iOrder` FROM `' . $oDB->throwTableName( DB_ORDERS ) . '` WHERE `iOrder` = ' . intval( $session_id ) . ' AND `iPaymentSystem` = ' . PAYU_SYSTEM, true, DataBase::SINGLE_VALUE );
			if( empty( $iOrder ) ){
				echo('Błędny SESSION_ID w odpowiedzi na zapytanie o transakcję');
				exit;
			} elseif( $status == 99 ){
				$oOrder->changeStatus( $iOrder, $config['PAYU_on_accepted'] );
			} elseif( $status == 2 || $status == 3 || $status == 7 ){
				$oOrder->changeStatus( $iOrder, $config['PAYU_on_canceled'] );
			}
			echo( 'OK' );
			exit;
		}
	} else{
		echo( 'Nie dostarczono wszystkich wymaganych danych' );
		exit;
	}
} elseif( $aActions['a'] == 'zagiel' ){
	if( isset( $_GET['result'] ) ){
		if( $_GET['result'] == 'ok' ){
			$oTpl->assign( 'aMessage', Array( 'message' => $lang['Zagiel_ok'] ) );
			$content.= $oTpl->parse( 'message.tpl' );
		} else{
			$oTpl->assign( 'aMessage', Array( 'message' => $lang['Zagiel_cancel'], 'bError' => true ) );
			$content.= $oTpl->parse( 'message.tpl' );
		}
	}
} elseif( $aActions['a'] == 'paypal' ){
	if( isset( $_POST['payment_status'] ) ){
		if( $_POST['payment_status'] != 'Completed' && $_POST['payment_status'] != 'Pending' ){
			$oTpl->assign( 'aMessage', Array( 'message' => $lang['There_are_no_money_to_pay'], 'bError' => true ) );
			$content.= $oTpl->parse( 'message.tpl' );
		} else{
			$oTpl->assign( 'aMessage', Array( 'message' => $lang['There_are_money_to_pay'] ) );
			$content.= $oTpl->parse( 'message.tpl' );
		}
	} else{
		$oTpl->assign( 'aMessage', Array( 'message' => $lang['Payment_return_info'] ) );
		$content.= $oTpl->parse( 'message.tpl' );
	}
} elseif( $aActions['a'] == 'paybynet_verify' ){
	ignore_user_abort( true );
	header( "Content-Length: 0" );
	flush( );
	if( ( ( isset( $config['paybynet_on_accepted'] ) && ( $config['paybynet_on_accepted'] > 0 ) ) || ( isset( $config['paybynet_on_cancel'] ) && ( $config['paybynet_on_cancel'] > 0 ) ) ) && !empty( $config['paybynet_id'] ) ){
		$sql = 'SELECT `iOrder` FROM `' . $oDB->throwTableName( DB_ORDERS ) . '` WHERE `iStatus` = 1 AND ( `iPaymentSystem` = ' . PAYBYNET_SYSTEM . ' OR `iOrderAdvance` IN( SELECT `iPayment` FROM `' . $oDB->throwTableName( DB_PAYMENTS ) . '` WHERE `iOuterSystem` = ' . PAYBYNET_SYSTEM . ' ) )';
		$aOrders = $oDB->executeSQL( $sql, true, DataBase::SINGLE_COLUMN );
		$oWebServiceClient = new SoapClient( $config['paybynet_test'] ? 'https://pbn.paybynet.com.pl/axist/services/PBNTransactionsGetStatus?wsdl' : 'https://pbn.paybynet.com.pl/axis/services/PBNTransactionsGetStatus?wsdl' );
		foreach( $aOrders as $iOrder ){
			$iStatus = $oWebServiceClient->getStatusByPaymentID( str_repeat( '0', 10 - strlen( $iOrder ) ) . $iOrder, $config['paybynet_id'] );
			switch( $iStatus ){
				case 1001:
				case 1002:
				case 1003:
				case 1004:
				case 1005:
				case 1006:
				case 2201:
				case 2202:
				case 2301:
				case 2302:
					if( isset( $config['paybynet_on_cancel'] ) && ( $config['paybynet_on_cancel'] > 0 ) ){
						$oOrder->changeStatus( $iOrder, $config['paybynet_on_cancel'] );
					}
				break;
				case 2203:
				case 2303:
					if( isset( $config['paybynet_on_accepted'] ) && ( $config['paybynet_on_accepted'] > 0 ) ){
						$oOrder->changeStatus( $iOrder, $config['paybynet_on_accepted'] );
						$aOrder = $oOrder->throwOrder( $iOrder );
						if( isset( $aOrder['iOrderAdvancePayment'] ) && $aOrder['iOrderAdvancePayment'] > 0 ){
							$oDB->executeSQL( 'UPDATE `' . $oDB->throwTableName( DB_ORDERS ) . '` SET `iOrderAdvance` = 2 WHERE `iOrder` = ' . $iOrder . ' AND `iPaymentSystem` = ' . PAYBYNET_SYSTEM );
							$oOrder->changeStatus( $iOrder, 24 );
						}
					}
				break;
			}
		}
	}
	exit;
} elseif( $aActions['a'] == 'przelewy24ok' ){
	header( 'Location: ' . $oPage->getLinkName( $config['platnosci_page_ok'] ) );
	exit;
} elseif( $aActions['a'] == 'przelewy24check' ){
	function p24_weryfikuj( $p24_id_sprzedawcy, $p24_session_id, $p24_order_id, $p24_kwota, $p24_crc ){
		$P = array(); $RET = array();
		$url = "https://secure.przelewy24.pl/trnVerify";
//		$url = "https://sandbox.przelewy24.pl/transakcja.php";
		$P[] = "p24_merchant_id=" . $p24_id_sprzedawcy;
		$P[] = "p24_pos_id=" . $p24_id_sprzedawcy;
		$P[] = "p24_session_id=" . $p24_session_id;
		$P[] = "p24_amount=" . $p24_kwota;
		$P[] = "p24_currency=" . $GLOBALS['config']['currency_symbol_ISO'];
		$P[] = "p24_order_id=" . $p24_order_id;
		$P[] = "p24_sign=" . md5( $p24_session_id . "|" . $p24_order_id . "|" . $p24_kwota . "|" . $GLOBALS['config']['currency_symbol_ISO'] . "|" . $p24_crc );
		$user_agent = 'Mozilla/5.0 (compatible; SellSmart/11.0; Linux) SellSmart/11.0';
		$ch = curl_init();
		curl_setopt( $ch, CURLOPT_POST, 1 );
		if( count( $P ) ) curl_setopt( $ch, CURLOPT_POSTFIELDS, join( "&", $P ) );
		curl_setopt( $ch, CURLOPT_URL,$url );
		curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 2 );
		curl_setopt( $ch, CURLOPT_USERAGENT, $user_agent );
		curl_setopt( $ch, CURLOPT_RETURNTRANSFER,1 );
		curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
		$result = curl_exec( $ch );
		curl_close( $ch );
		preg_match( '/error=([0-9]+)(&errorMessage=.*)?/', $result, $matches );
		if( $matches[1] == '0' ){
			return "TRUE";
		}
		return $matches;
	}
	$aOrderInfo = $oOrder->throwOrder( intval( $_POST['p24_session_id'] ) );
	$iAmount = sprintf( '%01.2f', $aOrderInfo['fOrderSummary'] + $aOrderInfo['fPaymentCarrierPrice'] ) * 100;

	$WYNIK = p24_weryfikuj( $config['przelewy24_id'], $aOrderInfo['iOrder'], $_POST['p24_order_id'], $iAmount, $config['przelewy24_crc'] );

	if( $WYNIK == "TRUE" ){
		if( isset( $config['przelewy24_on_accepted'] ) && $config['przelewy24_on_accepted'] > 0 ){
			if( $aOrderInfo['iOrderAdvancePayment'] > 0 ){
				$oDB->executeSQL( 'UPDATE `' . $oDB->throwTableName( DB_ORDERS ) . '` SET `iOrderAdvance` = 2 WHERE `iOrder` = ' . $aOrderInfo['iOrder'] );
				$oOrder->changeStatus( $aOrderInfo['iOrder'], 24 );
			}else{
				$oOrder->changeStatus( $aOrderInfo['iOrder'], $config['przelewy24_on_accepted'] );
			}
		}
	} else{
		if( isset( $config['przelewy24_on_cancel'] ) && $config['przelewy24_on_cancel'] > 0 ) $oOrder->changeStatus( intval( $_POST['p24_session_id'] ), $config['przelewy24_on_cancel'] );
		file_put_contents( 'logs/przelewy24.log', var_export( $_POST['p24_session_id'], true ) . "\n" . var_export( $WYNIK, true ) . "\n", FILE_APPEND );
	}
	exit;
} elseif( $aActions['a'] == 'lr' ){
	if( isset( $_GET['result'] ) ){
		if( $_GET['result'] == 'ok' ){
			$oTpl->assign( 'aMessage', Array( 'message' => $lang['LR_ok'] ) );
			$content.= $oTpl->parse( 'message.tpl' );
		} else{
			$oTpl->assign( 'aMessage', Array( 'message' => $lang['LR_fail'], 'bError' => true ) );
			$content.= $oTpl->parse( 'message.tpl' );
		}
	}
} elseif( $aActions['a'] == 'sofort_ok' ){
	$postdata = file_get_contents("php://input");
	function xPathVal( $xPath, $sPath, $oNode = null ){
		if( isset( $oNode ) ) $oTmp = $xPath->query( $sPath, $oNode );
		else $oTmp = $xPath->query( $sPath );
		if( empty( $oTmp->item( 0 )->value ) && isset( $oTmp->item( 0 )->childNodes ) ){
			return $oTmp->item( 0 )->childNodes->item( 0 )->wholeText;
		} else{
			return $oTmp->item( 0 )->value;
		}
	}

	$oResp = new DomDocument();
	$oResp->loadXML( $postdata );
	$xPath = new DOMXPath( $oResp );
	$sTransaction = xPathVal( $xPath, '/status_notification/transaction' );
	$iOrder = $oDB->executeSQL( 'SELECT `iOrder` FROM `' . $oDB->throwTableName( DB_ORDERS ) . '` WHERE `mPaymentChannel` = \'' . $oDB->escape( $sTransaction ) . '\' AND `iPaymentSystem` = ' . SOFORT_SYSTEM, true, DataBase::SINGLE_VALUE );

	if( !empty( $iOrder ) ){
		$aOrderInfo = $oOrder->throwOrder( $iOrder );
		if( $aOrderInfo['iOrderAdvancePayment'] > 0 ){
			$oDB->executeSQL( 'UPDATE `' . $oDB->throwTableName( DB_ORDERS ) . '` SET `iOrderAdvance` = 2 WHERE `iOrder` = ' . $iOrder );
			$oOrder->changeStatus( $iOrder, 24 );
		}else{
			$oOrder->changeStatus( $iOrder, $config['SOFORT_on_accepted'] );
		}
	}
} elseif( $aActions['a'] == 'transferuj' ){
	if( empty( $_POST ) ){
		echo('Empty POST!');
		exit;
	}
	if( md5( $_POST['id'] . $_POST['tr_id'] . $_POST['tr_amount'] . $_POST['tr_crc'] . $config['TRANSFERUJ_Auth_code'] ) != $_POST['md5sum'] ){
		echo('Wrong md5sum!');
		exit;
	}
	if( $_POST['id'] != $config['TRANSFERUJ_Customer_number'] ){
		echo('Wrong client id!');
		exit;
	}
	$oOrder->changeStatus( intval( $_POST['tr_crc'] ), $_POST['tr_status'] == 'TRUE' ? $config['TRANSFERUJ_on_accepted'] : $config['TRANSFERUJ_on_cancel'] );
	echo('TRUE');
	exit;
} elseif( $aActions['a'] == 'cashbill_verify' ){
	if( !empty( $_POST['service'] ) && !empty( $_POST['orderid'] ) && !empty( $_POST['amount'] ) && !empty( $_POST['userdata'] ) && !empty( $_POST['status'] )  && !empty( $_POST['sign'] ) ){
		if( $_POST['service'] != $config['CashBill_Service'] ){
			echo( 'Błędny Service' );
			exit;
		}
		if( $_POST['sign'] != md5( $config['CashBill_Service'] . $_POST['orderid'] . $_POST['amount'] . $_POST['userdata'] . $_POST['status'] . $config['CashBill_Key'] ) ){
			echo( 'Błędny SIGN' );
			exit;
		}
		$iOrder = 'SELECT `iOrder` FROM `' . $oDB->throwTableName( DB_ORDERS ) . '` WHERE `iOrder` = ' . intval( $_POST['userdata'] ) . ' AND `iPaymentSystem` = ' . CASHBILL_SYSTEM;
		$iOrder = $oDB->executeSQL( $iOrder, true, DataBase::SINGLE_VALUE );
		if( $iOrder != $_POST['userdata'] ){
			echo( 'Błędny userdata' );
			exit;
		}
		
		if( mb_strtoupper( $_POST['status'], 'UTF-8' ) == 'OK' ){
			$aOrderInfo = $oOrder->throwOrder( $iOrder );
			if( $aOrderInfo['iOrderAdvancePayment'] > 0 ){
				$oDB->executeSQL( 'UPDATE `' . $oDB->throwTableName( DB_ORDERS ) . '` SET `iOrderAdvance` = 2 WHERE `iOrder` = ' . $iOrder );
				$oOrder->changeStatus( $iOrder, 24 );
			}else{
				$oOrder->changeStatus( $iOrder, $config['CashBill_on_accepted'] );
			}
		} else{
			$oOrder->changeStatus( $iOrder, $config['CashBill_on_cancel'] );
		}
		echo( 'OK' );
		exit;
	} else{
		echo( 'Nie dostarczono wszystkich wymaganych danych' );
		exit;
	}
} elseif( $aActions['a'] == 'cashbill_redirect' ){
	if( mb_strtoupper( $_GET['status'], 'UTF-8' ) == 'OK' ){
		header( 'Location: ' . $oPage->getLinkName( $config['platnosci_page_ok'] ) );
		exit;
	} else{
		header( 'Location: ' . $oPage->getLinkName( $config['platnosci_page_fail'] ) );
		exit;
	}
} elseif( $aActions['a'] == 'bluemedia_verify' ){
	$sXml = base64_decode( $_POST['transactions'] ); // odkodowanie stringa z informacjami o transkacji
	$aXml = json_decode( json_encode( simplexml_load_string( $sXml ) ), true ); // przetworzenie stringa xml do tablicy asocjacyjnej
	
	$sToHash = '';
	
	foreach( $aXml['transactions']['transaction'] as $sField ){
		if( !is_array( $sField ) ){
			$sToHash .= $sField . '|';
		} else {
			foreach( $sField as $aField ){
				$sToHash .= $aField . '|';
			}
		}
	}
	
	$sHash = hash( $oBM->bmFunction, $oBM->bmServiceId . '|' . $sToHash . $oBM->bmKey ); // generowanie hasha do porównania z otrzymanym
	file_put_contents( 'bluemedia_log.txt', var_export( Array( $aXml, $sHash, $sToHash ), true ) . "\n\n", FILE_APPEND ); // logowanie otrzymywanych danych
	
	$aOrder = $oOrder->throwOrder( $aXml['transactions']['transaction']['orderID'] );
	
	$sql = 'SELECT COUNT( `iElement` ) AS `iCount` FROM `' . $oDB->throwTableName( DB_ORDERS_STATUS ) . '` WHERE `iStatus` = 4 AND `iOrder` = ' . $aXml['transactions']['transaction']['orderID'];
	$iOrderStatusHistory = $oDB->executeSQL( $sql, true, DATABASE::SINGLE_VALUE );
	
	if( $sHash == $aXml['hash'] ){
		if( $iOrderStatusHistory == 0 ){
			switch( $aXml['transactions']['transaction']['paymentStatus'] ){ // ustawienie statusu zamówienia
				case 'PENDING':
					$oOrder->changeStatus( $aXml['transactions']['transaction']['orderID'], 3 );
					break;
				case 'SUCCESS':
					if( $aOrder['iOrderAdvancePayment'] > 0 ){
						$oDB->executeSQL( 'UPDATE `' . $oDB->throwTableName( DB_ORDERS ) . '` SET `iOrderAdvance` = 2 WHERE `iOrder` = ' . $aXml['transactions']['transaction']['orderID'] );
						$oOrder->changeStatus( $aXml['transactions']['transaction']['orderID'], 24 );
					}else{
						$oOrder->changeStatus( $aXml['transactions']['transaction']['orderID'], 4 );
						$oOrder->changeStatus( $aXml['transactions']['transaction']['orderID'], 6 );
					}
					break;
				case 'FAILURE':
					$oOrder->changeStatus( $aXml['transactions']['transaction']['orderID'], 53 );
					break;
			}
		}
		$sStatus = "CONFIRMED";
	} else {
		/*** hash nie poprawny ***/
		$sStatus = "NOTCONFIRMED";
	}
	
	$sHashOut = hash( $oBM->bmFunction, $oBM->bmServiceId . "|" . $aXml['transactions']['transaction']['orderID'] . "|" . $sStatus . "|" . $oBM->bmKey );
	
	$sXmlOut = '<?xml version="1.0" encoding="UTF-8"?>
		<confirmationList>
		<serviceID>' . $oBM->bmServiceId . '</serviceID>
		<transactionsConfirmations>
			<transactionConfirmed>
				<orderID>' . $aXml['transactions']['transaction']['orderID'] . '</orderID>
				<confirmation>' . $sStatus . '</confirmation>
			</transactionConfirmed>
		</transactionsConfirmations>
		<hash>' . $sHashOut . '</hash>
	</confirmationList>';
	
	#file_put_contents( 'bluemedia_log.txt', var_export( Array( $sXmlOut ), true ) . "\n\n", FILE_APPEND ); // logowanie generowanych danych
	echo $sXmlOut;
	exit;
} elseif( $aActions['a'] == 'first_data' ){
	#file_put_contents( 'firstdata_log.txt', var_export( Array( $_POST ), true ) . "\n\n", FILE_APPEND ); // logowanie otrzymanych danych
	
	$aParams = array( );
	
	if( isset( $_POST['pos_id'] ) ) $aParams['pos_id'] = $_POST['pos_id'];
	if( isset( $_POST['order_id'] ) ) $aParams['order_id'] = $_POST['order_id'];
	if( isset( $_POST['session_id'] ) ) $aParams['session_id'] = $_POST['session_id'];
	if( isset( $_POST['amount'] ) ) $aParams['amount'] = $_POST['amount'];
	if( isset( $_POST['response_code'] ) ) $aParams['response_code'] = $_POST['response_code'];
	if( isset( $_POST['transaction_id'] ) ) $aParams['transaction_id'] = $_POST['transaction_id'];
	
	if( !empty( $_POST['card_type'] ) && $_POST['card_type'] != '' ){
		if( isset( $_POST['cc_number_hash'] ) ) $aParams['cc_number_hash'] = $_POST['cc_number_hash'];
		if( isset( $_POST['bin'] ) ) $aParams['bin'] = $_POST['bin'];
		if( isset( $_POST['card_type'] ) ) $aParams['card_type'] = $_POST['card_type'];
	}
	if( isset( $_POST['auth_code'] ) ) $aParams['auth_code'] = $_POST['auth_code'];
	
	
	
	$sControlData = $oFD->calculateControlData( $aParams );
	#file_put_contents( 'firstdata_log_incoming.txt', var_export( Array( $_POST, $aParams, $sControlData ), true ) . "\n\n", FILE_APPEND ); // logowanie otrzymanych danych
	
	if( $_POST['controlData'] == $sControlData ){
		if( isset( $_POST['response_code'] ) ){
			switch( $_POST['response_code'] ){
				case 30: // 30 (AUTHORIZED) - Transakcja zautoryzowana(zakończona)
					$oOrder->changeStatus( $_POST['order_id'], 3 );
					break;
				case 35: // CONFIRMED) – Zatwierdzona (do rozliczenia)
					if( $aOrder['iOrderAdvancePayment'] > 0 ){
						$oDB->executeSQL( 'UPDATE `' . $oDB->throwTableName( DB_ORDERS ) . '` SET `iOrderAdvance` = 2 WHERE `iOrder` = ' . $_POST['order_id'] );
						$oOrder->changeStatus( $_POST['order_id'], 24 );
					}else{
						$oOrder->changeStatus( $_POST['order_id'], 4 );
					}
					break;
				case 40: // (REJECTED) - Transakcja odrzucona przez system autoryzacyjny
					$oOrder->changeStatus( $_POST['order_id'], 53 );
					break;
				case 21: // (AUTHORIZATION_FAILED ) - Podczas autoryzacji wystąpił błąd techniczny
					$oOrder->changeStatus( $_POST['order_id'], 53 );
					break;
				case 50: // transakcja zakończona, wpłata zatwierdzona
					$oOrder->changeStatus( $_POST['order_id'], 4 );
					break;
			}
			echo "Odebrano dane";
		} else {
			echo "Nie znaleziono danych";
		}
	} else {
		echo "Problem z autoryzacją";
	}
	
	echo "Przetworzono";
	exit;
}
?>