Pagseguro class does not work with CNPJ.

Asked

Viewed 1,277 times

3

I was having a problem making payments using the class provided by pagseguro and cnpj. Every time I tried to make the payment, I made the following mistake:

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.

1 answer

5


I found that this is a fault in the pagseguro class. The correction is very simple. Open the Pagseguropaymentparser.class.php file and go to line 72, where there is the following code snippet:

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();
                        }
                    }
                }
            }

Browser other questions tagged

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