PDO, Select a query with some fields, from a certain user and code

Asked

Viewed 278 times

0

I need to set up a consultation where I’ll only have five fields (STATUS, ID_USUARIO, PACKED, ID_TRANSACAO and ENTREGUE).

I need that when I have change of STATUS change to another table, and update the current field ENTREGUE from "N" to "S" and no more consultation on this already delivered.

At the same time, I need PACKED Identify how much will be delivered because this taking as ID ie, id 1 corresponds to 30 Chips...

Below my status code; I have no idea how to make this logic work.

 <?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();                       
}
?>
  • Apparently simple answer, plus your question is a bit scrambled. Could you send an example of what you are trying to do.

  • @Daniel101 example is a return of the paid by an xml, but I already have data of the purchase registered in the database, I want to update this data in the bd, take from one table to another the credit, and at the same time validating q and only for that user and for that transaction in it I have the code that I need to validate when the return of the payment occurs, take the credit q user bought and enter in his account in another table. in the case in the payment table I need to make a sort of check of which type of package he bought because the packages are as id, and I need to pass a valr

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.