<?php

/******************************************************************************
 *
 *	PROJECT: Flynax Classifieds Software
 *	VERSION: 4.X
 *	LICENSE: FL0M2SG681CQ - http://www.flynax.com/license-agreement.html
 *	PRODUCT: Pets Classifieds
 *	DOMAIN: pupsnshop.com
 *	FILE: POST.GATEWAY.PHP
 *
 *	The software is a commercial product delivered under single, non-exclusive, 
 *	non-transferable license for one domain or IP address. Therefore distribution, 
 *	sale or transfer of the file in whole or in part without permission of Flynax 
 *	respective owners is considered to be illegal and breach of Flynax License End 
 *	User Agreement. 
 *
 *	You are not allowed to remove this information from the file without permission
 *	of Flynax respective owners.
 *
 *	Flynax Classifieds Software 2014 |  All copyrights reserved. 
 *
 *	http://www.flynax.com/
 *
 ******************************************************************************/

if ( isset( $_POST['jwt'] ) ) 
{
	require_once( '../../../includes/config.inc.php' );

	/* system controller */
	require_once( RL_INC . 'control.inc.php' );

	$reefless->loadClass( 'Cache' );
	$reefless->loadClass( 'JWT', null, 'googleWallet' );
	$reefless->loadClass( 'GoogleWallet', null, 'googleWallet' );

	/* load system configurations */
	$config = $rlConfig -> allConfig();

	$jwt = trim( $_POST['jwt'] );
	$response = $rlJWT -> decode( $jwt, $config['google_wallet_secret_key'], false );

	$oredr_id = $response->response->orderId;
	$items = $response->request->sellerData;

	$items = explode( '|', base64_decode( $items ) );

	$plan_id = $items[0];
	$item_id = $items[1];
	$account_id = $items[2];
	$total = $items[3];
	$callback_class = $items[4];
	$callback_method = $items[5];
	$lang_code = $items[6];
	$callback_plugin = $items[7] ? $items[7] : false;
	$txn_id = $items[8];

    if(!$oredr_id)
	{
		$errors = true;
		$rlDebug -> logger( "googleWallet: Failed Order ID" );
	}
	
	if(!$item_id || !$account_id) 
	{
		$errors = true;
		$rlDebug -> logger( "googleWallet: empty item id or account id" );
	}

	if(!$errors)
	{
		$reefless -> loadClass( str_replace( 'rl', '', $callback_class ), null, $callback_plugin );
		$$callback_class -> $callback_method( $item_id, $plan_id, $account_id, $txn_id, 'googleWallet', $total );

		/* response to google */
		$response_data = array( 
				'response.status' => 200,
				'response.content' => $order_id
			);

		header("HTTP/1.0 200 OK");
		echo $oredr_id;
		exit;
	}
	else
	{
		$file = fopen('response.log', 'a');

		$line = "\n\n".date('Y.m.d H:i:s').":\n";
	    fwrite($file, $line);

		foreach($_REQUEST as $p_key => $p_val)
		{                 
			$line = "[{$_SERVER['REQUEST_METHOD']}]: {$p_key} => {$p_val}\n";
    		fwrite($file, $line);
		}

		$items = var_export($items, true);  
		$line = "{$items}\n";
    	fwrite( $file, $line );

		fclose( $file );
	}
}