Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to Simulate HTTP 302 response
    text
    copied!<p>I'm trying to incorporate PagSeguro (a payment gateway - Brazil's version of PayPal) into my site. After the customer finishes with PagSeguro, they send data (via POST) to a function which I specify. However, I'm not receiving the POST. After doing all the troubleshooting I could think of, I contacted PagSeguro. They said that their log indicates that the POST is being sent as normal but they are receiving an HTTP 302 response.</p> <p>In order to figure out why this is happening, I created a form with hidden values to simulate sending a POST to my function. I put this form under a different domain just in case it had something to do with that. Every time I send the POST from my simulation form, I receive an HTTP 200 response, and my log indicates that the POST was received.</p> <p>How is it possible that PagSeguro is receiving a different response than my simulation? Could it have something to do with the server or is it something to do with my script?</p> <p>Here is the function (using CodeIgniter) that should be receiving the POST:</p> <pre><code>function pagseguro_retorno(){ if (count($_POST) == 0) { return FALSE; } $msg = 'POST RECEIVED'; $simulate = $this-&gt;input-&gt;post('Simulate'); if ( ! empty($simulate)){ $result = 'VERIFICADO'; $msg .= ' FROM SIMULATOR'; } else { $this-&gt;load-&gt;library(PagSeguroNpi); $result = $this-&gt;PagSeguroNpi-&gt;notificationPost(); } $this-&gt;log($msg); if ($result == "VERIFICADO") { $id = $this-&gt;input-&gt;post('Referencia');//cart id $this-&gt;load-&gt;model('transacao_model'); $trans_row = $this-&gt;transacao_model-&gt;get_transaction($id); if ( ! is_object($trans_row)){ //LOAD NEW TRANSACTION if ( ! $this-&gt;new_transaction($id)){ $notice = "Unable to load new transaction&lt;/p&gt;&lt;p&gt;"; $this-&gt;log($notice); $notice .= '&lt;pre&gt;'.print_r($_POST, TRUE).'&lt;/pre&gt;'; $this-&gt;email_notice($notice); } } $this-&gt;load-&gt;model('carrinho_model'); if($_POST['StatusTransacao'] == 'Aprovado'){ $status = 'apr'; }elseif($_POST['StatusTransacao'] == 'Em Análise'){ $status = 'anl'; }elseif($_POST['StatusTransacao'] == 'Aguardando Pagto'){ $status = 'wtg'; }elseif($_POST['StatusTransacao'] == 'Completo'){ $status = 'cmp'; //nothing more happens here - client must click on 'mark as shipped' before cart is removed and history data is loaded }elseif($_POST['StatusTransacao'] == 'Cancelado'){ //reshelf - don't set $status, because the cart's about to be destroyed $this-&gt;carrinho_model-&gt;reshelf(array($id)); } if (isset($status)){ $this-&gt;carrinho_model-&gt;update_carrinho($id, array('status' =&gt; $status)); } } else if ($result == "FALSO") { $notice = "PagSeguro return was invalid."; $this-&gt;log($notice); $notice .= '&lt;pre&gt;'.print_r($_POST, TRUE).'&lt;/pre&gt;'; $this-&gt;email_notice($notice); } else { $notice = "Error in PagSeguro request"; $this-&gt;log($notice); $notice .= '&lt;pre&gt;'.print_r($_POST, TRUE).'&lt;/pre&gt;'; $this-&gt;email_notice($notice); } } </code></pre> <p>SECURITY UPDATE:</p> <p>After posting, I soon realized that I was opening myself up to hack attempts. The function necessarily has to be public, so anyone who knows the name of the function could access it and post 'simulate' to get immediate verification. Then they could pass whatever data they wanted.</p> <p>I changed the name of the function to something that would be impossible to guess, and when not in production mode, I've disabled the simulate option.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload