I can understand the script , except for the part that works the XML ... so I can not tell if the error is in in>, or XML that it tries to get.
Code:
<?php
require ("includes/connection.php");
require ("includes/start-session.php");
require ("includes/encript.php");
?>
<?php
header("access-control-allow-origin: https://ws.sandbox.pagseguro.uol.com.br");
$email = 'email@sandboxpagseguro';
$token = 'tokensandbox';
$pagamento = $_GET['transaction_id'];
$url = 'https://ws.sandbox.pagseguro.uol.com.br/v2/transactions/'. $pagamento .'?email=' .$email. '&token=' .$token;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$transaction= curl_exec($curl);
curl_close($curl);
if($transaction == 'Unauthorized'){
//Caso o token ou e-mail não sejam validados pelo PagSeguro.
echo 'Unauthorized';
exit;
}
$transaction = simplexml_load_string($transaction);
if($transaction->code > 0) {
$transaction_id = $transaction->code;
$client_id = $transaction->reference;
$payment_type = $transaction->paymentMethod->type;
if($payment_type == 1){
$payment_method = "Cartão de crédito";
} elseif($payment_type == 2){
$payment_method = "Boleto";
} elseif($payment_type == 3){
$payment_method = "Débito online (TEF)";
} else {
$payment_method = "Outro";
}
$payment_type_method = $transaction->type;
if($payment_type_method == 1){
$payment_method_transiction = "Pagamento";
} elseif($payment_type_method == 11){
$payment_method_transiction = "Assinatura";
} else {
$payment_method_transiction = "Outro";
}
$parceled = $transaction->installmentCount;
$parceled_value = $transaction->installmentFeeAmount;
$product = $transaction->items->item->id;
$product_value = $transaction->items->item->amount;
$transaction_date = date('d/m/Y', strtotime($transaction->date));
$transaction_date_last = date('d/m/Y', strtotime($transaction->lastEventDate));
if($transaction->status == 1){
$transaction_status = 'Aguardando pagamento';
} elseif($transaction->status == 2){
$transaction_status = 'Em análise';
} elseif($transaction->status == 3){ // :)
$transaction_status = 'Paga';
} elseif($transaction->status == 4){ // :D
$transaction_status = 'Disponível';
} elseif($transaction->status == 5){
$transaction_status = 'Em disputa';
} elseif($transaction->status == 6){
$transaction_status = 'Devolvida';
} elseif($transaction->status == 7){
$transaction_status = 'Cancelada';
}
$client_name = $transaction->sender->name;
// Faz a inserção no BD.
$insert = $mysqli->query("INSERT INTO 'payments'('transaction_id', 'client_id', 'payment_method', 'payment_method_transiction', 'transaction_status', 'transaction_date', 'transaction_date_last', 'product', 'product_value', 'client_name') VALUES ('$transaction_id', '$client_id', '$payment_method', '$payment_method_transiction', '$transaction_status', '$transaction_date', '$transaction_date_last', '$product', '$product_value', '$client_name')");
if ($insert) {
echo 'dados inseridos';
} else {
echo 'falha na inserção dos dados.';
}
} else {
echo $transaction->code;
}
?>
Parse Error:
Warning: simplexml_load_string (): Entity: line 1: parser error: Start tag expected, '<' not found in /home/u657579475/public_html/loja/confirm.php on line 26
Warning: simplexml_load_string (): Forbidden in /home/u657579475/public_html/loja/confirm.php on line 26
Warning: simplexml_load_string (): ^ in /home/u657579475/public_html/loja/confirm.php on line 26
Line 26:
$transaction = simplexml_load_string($transaction);