0
I have progressed a lot in the code, within what I thought was necessary, only I don’t know how to organize my syntax so that everything happens as I want, the switch/case that runs in the bank to see which id is registered and take the value on switch and move to the other table in the update... is occurring some error someone could help?
<?php
require_once("core/config/config.php");
if (isset($_POST['notificationType']) && $_POST['notificationType'] == 'transaction') {
//CÓDIGO DA NOTIFICAÇÃO
$code = $_POST['notificationCode'];
//MONTAMOS A URL PARA PEGAR O STATUS
$url = 'https://ws.sandbox.pagseguro.uol.com.br/v2/transactions/notifications/' . $code . '?email=' . $email . '&token=' . $token;
//PEGAMOS O STATUS VIA CURL
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$transaction= curl_exec($curl);
curl_close($curl);
//SE DER ALGUM ERRO NO NOSSO CURL VAI VIM COMO Unauthorized
if($transaction == 'Unauthorized'){
exit;//Mantenha essa linha
}
$pdo = conectaDB();
$get = $pdo->prepare("SELECT * FROM pagseguro");
$get->execute();
$query = $get->fetchAll(PDO::FETCH_ASSOC);
foreach ($query as $row) {
$user = $row['id_user'];
$codigo_transacao = $row['id_transacao'];
$codigo = $row['packed'];
}
$entregue = 'S';
switch ($query->$codigo) {
case '1':
$chips = '30.00';
break;
case '2':
$chips = '50.00';
break;
case '3':
$chips = '100.00';
break;
case '4':
$chips = '250.00';
break;
}
//COMVERTE O RERTORNO EM STRING
$transaction = simplexml_load_string($transaction);
/*
* STATUS RETORNO
* 1 - Aguardando pagamento
* 2 - Em análise
* 3 - Paga
* 4 - Disponível
* 5 - Em disputa
* 6 - Devolvida
* 7 - Cancelada
*/
//PEGAMOS O CÓDIGO DO STATUS
switch ($transaction->status) {
case '1':
$status = 'Aguardando pagamento';
break;
case '2':
$status = 'Em análise';
break;
case '3':
$status = 'Paga';
$edit2 = $pdo->prepare("UPDATE pagseguro SET entregue=:entregue WHERE id_transacao=:id_transacao");
$edit2->bindValue(':entregue', $entregue);
$edit2->bindValue(':id_transacao', $transaction->code);
$edit2->execute();
// SECOND CASE
$update = $pdo->prepare("UPDATE users SET credits=:credits WHERE username=:user_pagseguro");
$update->bindValue(':credits', $chips);
$update->bindValue(':user_pagseguro', $user);
$update->execute();
break;
case '4':
$status = 'Disponível';
break;
case '5':
$status = 'Em disputa';
break;
case '6':
$status = 'Devolvida';
break;
case '7':
$status = 'Cancelada';
break;
}
//ATUALIZAMOS O STATUS NO BANCO DADOS.
$pdo = conectaDB();
$edit = $pdo->prepare("UPDATE pagseguro SET status=:status WHERE id_transacao=:id_transacao");
$edit->bindValue(':status', $status);
$edit->bindValue(':id_transacao', $transaction->code);
$edit->execute();
}
?>
example of a piece of my bank in part q has transfer package and user id...
───────────────────────────────────────────────────────── | id_user | codigo_transacao | packed | ───────────────────────────────────────────────────────── | Joaozinho | 2asd654asd65as4c | 1 | ───────────────────────────────────────────────────────── | Mariazinha | 1asd654as123214d | 2 | ───────────────────────────────────────────────────────── | Carlinhos | 4asd654asd65as4dasd2 | 4 | ─────────────────────────────────────────────────────────
UPDATED THE CODE :
– Bruno Roberto
@diegofm but in case I need to do more than 2 example actions, update the current table and update another bank table when the payment is ok... in case the logic of the programming is correct right?
– Bruno Roberto