Class of the pagseguro does not work with CNPJ.

2

I had a problem making payments using the class provided by pagseguro and cnpj. Every time I tried to make the payment, I gave the following error:

HTTP 400 - BAD_REQUEST [THE REQUEST CANNOT BE FULFILLED DUE TO BAD SYNTAX]
11164 - senderCPF invalid value:...

Even changing the document type to CNPJ, the error persisted with senderCPF.

    
asked by anonymous 05.06.2015 / 22:19

1 answer

4

I have discovered that this is a flaw in the payroll class. The fix is very simple. Open the file PagSeguroPaymentParser.class.php and go to line 72, where the following code snippet exists:

if ($payment->getSender()->getDocuments() != null) {
                $documents = $payment->getSender()->getDocuments();
                if (is_array($documents) && count($documents) == 1) {
                    foreach ($documents as $document) {
                        if (!is_null($document)) {
                            $data['senderCPF'] = $document->getValue(); //essa linha ta errada.. estão ignorando o tipo do documento q vc informa
                        }
                    }
                }
            }

Just change by:

if ($payment->getSender()->getDocuments() != null) {
                $documents = $payment->getSender()->getDocuments();
                if (is_array($documents) && count($documents) == 1) {
                    foreach ($documents as $document) {
                        if (!is_null($document)) {
                            $data['sender'.$document->getType()] = $document->getValue();
                        }
                    }
                }
            }
    
05.06.2015 / 22:19