<?php
/**copyrights**/

$reefless -> loadClass( 'Actions' );
$reefless -> loadClass( 'PagSeguro', null, 'pagSeguro' );

$price = number_format( $price, 2 );
$txn_id = $reefless -> generateHash( 8, 'upper' );

/* system data */
$data = $plan_id . '|' . $item_id . '|' . $account_id . '|' . $price . '|' . $callback_class . '|' . $callback_method . '|' . $cancel_url . '|' . $success_url . '|' . RL_LANG_CODE . '|' . $callback_plugin;
$data = base64_encode( $data );

$insert = array(
		'Txn_id' => $txn_id,
		'Item' => $data,
		'Date' => 'NOW()'
	);

$rlActions -> insertOne( $insert, 'pagseguro_transactions' );

$notify_url = RL_PLUGINS_URL . 'pagSeguro/controllers/post.gateway.php';
$redirect_url = RL_PLUGINS_URL . 'pagSeguro/controllers/redirect.php';

$request = array(
		'item_name' => $item_name,
		'price' => $price,
		'txn_id' => $txn_id,
		'redirect_url' =>  $redirect_url,
		'notification_url' => $notify_url,
	);

$payment_url = $rlPagSeguro -> createRequest( $request );

if($payment_url)
{
	echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$payment_url.'">';
}
else
{
	echo 'Fatal error! Please contact to administrator.';
}

exit;
?>