<?php
require_once "PagSeguroLibrary/PagSeguroLibrary.php";
$paymentRequest = new PagSeguroPaymentRequest();
$paymentRequest->setCurrency("BRL");

$title_order = $WA_LABEL_PAYPAL_CART_TITLE;
if (strlen($title_order)==0)
{
	$title_order = "Order ".$wa_market_id_order;
}

$paymentRequest->addItem($wa_market_id_order,$title_order, 1 , doubleval($wa_market_total_price));
$paymentRequest->setReference($wa_market_id_order);


//$paymentRequest->setShippingAddress($postalCode,$street,$number,$complement,$district,$city, $state, 'BRA');

$paymentRequest->setSender($wa_market_first_name." ".$wa_market_last_name, $wa_market_email_buyer);

try {			
	$credentials = new PagSeguroAccountCredentials($WA_PAGSEGURO_EMAIL_ACCOUNT,$WA_PAGSEGURO_TOKEN_ACCOUNT);
	// Register this payment request in PagSeguro, to obtain the payment URL for redirect your customer.
	$url = $paymentRequest->register($credentials);
	$code="";
	$n = strrpos ( $url,"code=");
	if ($n>0)
	{
		$code=substr ( $url,$n+5);
	}

	//$transaction->bank_notification_code = $code;
	//$transaction->createOrModifyObject();
?>

	<form action="<?php echo $url;?>" method="get" target="_blank" >
		<input type="hidden"  name="code" value="<?php echo $code;?>">
		<span style="font-size:13pt;font-weight:bold;">
			<br>
<?php 
			echo($WA_LABEL_CHECKOUT_WARNING);
?>
			<br>
			<br>
		</span>
		<input type="submit" class="checkout" value="<?php echo($WA_LABEL_PROCESS_ORDER);?>">
	</form>

<?php

} catch (PagSeguroServiceException $e) {
	echo $e->getMessage();
}

?>