Recurring payment error Pagseguro

Asked

Viewed 1,196 times

0

I have a problem with the Secure Pag API in the /pre-approvals method it always returns to me that parameters are missing but I am sending yes the parameters that the documentation asks for. I followed the documentation step by step and still nothing.

$data['plan'] = 'CEC9F172-DDDD-DACD-D408-EF866A920B11';
    $data['sender.name'] = $dados['nome'];
    $data['sender.email'] = $dados['email'];
    $data['sender.hash'] = $dados['hash_comprador'];
    $data['sender.phone.number'] = str_replace("-", "", substr($dados["telefone"], 5));
    $data['senderPhone'] = str_replace("-", "", substr($dados["telefone"], 5));
    $data['sender.phone.areaCode'] = substr($dados["telefone"], 1, 2);
    $data['senderAreaCode'] = (int) substr($dados["telefone"], 1, 2);

    $data['sender.address.street'] = $dados['rua'];
    $data['sender.address.number'] = $dados['numero'];
    // $data['senderAddressComplement'] = $dados['nome'];
    $data['sender.address.district'] = $dados['bairro'];
    $data['sender.address.city'] = $dados['cidade'];
    $data['sender.address.state'] = $dados['uf'];
    $data['sender.address.country'] = 'BRA';
    $data['sender.address.postalCode'] = str_replace("-", "", $dados["cep"]);
    // $data['senderDocumentsType'] = $dados['nome'];
    // $data['senderDocumentsValue'] = $dados['nome'];
    $data['paymentMethod.type'] = 'creditCard';
    $data['paymentMethod.creditCard.token'] = $dados['card_token'];
    $data['paymentMethod.creditCard.holder.name'] = $dados['nome'];
    $data['paymentMethod.creditCard.holder.birthDate'] = $dados['nascimento'];

    $data = http_build_query($data);

    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
                                        'Content-type: application/x-www-form-urlencoded;charset=ISO-8859-1',
                                        'Accept: application/vnd.pagseguro.com.br.v3+xml;charset=ISO-8859-1'
                                        ));
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    $xml = curl_exec($curl);

In the code above, I recover the sending data from the form, the documentation is very confusing I found some with sending this way 'senderPhone' and others with sending this way 'Sender.phone.number', I am sending the e-mail and token, I am already managing to make single payment via billet and card, but the recurring payment always returns me errors like: inserir a descrição da imagem aqui

In my HTML form I am sending all the required information, I will debug the code and I am actually sending everything:

inserir a descrição da imagem aqui

Please, if you’re confused, I’m sorry, but I’m desperate!

  • I suggest you take a look at Pagseguro-PHP-SDK, provided by Pagseguro on the link https://github.com/pagseguro/pagseguro-php-sdk. They provide a complete sdk for integration, I think it helps a lot in integration.

1 answer

3


This is Matthew blz?

Apparently the error is in the data you are sending, only thrashing to see what might be right. However, we have made an integration with the Paying recently and we use the following code:

$pagURL = 'https://ws.pagseguro.uol.com.br/';
        $notificationCode = 'your-notification-code';
        $mail = 'your-email';
        $token = 'your-token';

        $url = $pagURL . "pre-approvals"
            . $notificationCode 
            . "?email=" . $mail 
            . "&token=" . $token;

        $data = Json::encode(array(
            "plan" => "*********",
            "reference" => "*********",
            "sender" => array(
                "name" => "*********",
                "email" => "*********",
                "hash" => "*********",
                "phone" => array(
                    "areaCode" => "*********",
                    "number" => "*********"
                ),
                "address" => array(
                    "street" => "*********",
                    "number" => "*********",
                    "complement" => "*********",
                    "district" => "*********",
                    "city" => "*********",
                    "state" => "*********",
                    "country" => "BRA",
                    "postalCode" => "*********",
                ),
                "documents" => array(array(
                    "type" => "CPF",
                    "value" => "*********",
                ))
            ),
            "paymentMethod" => array(
                "type" => "CREDITCARD",
                "creditCard" => array(
                    "token" => "*********",
                    "holder" => array(
                        "name" => "*********",
                        "birthDate" => "*********",
                        "documents" => array(array(
                            "type" => "CPF",
                            "value" => "*********",
                        )),
                        "phone" => array(
                            "areaCode" => "*********",
                            "number" => "*********",
                        )
                    )
                )
            )
        ));

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_HTTPHEADER => array('Accept: application/vnd.pagseguro.com.br.v3+json;charset=ISO-8859-1','Content-Type: application/json; charset=ISO-8859-1'),
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_POSTFIELDS => $data
        ));

        try
        {
            $response = curl_exec($curl);
            $response = Json::decode($response);
        }
        catch(\Exception $e)
        {
            throw $e;
        }

The Json class can be found here: Json.php

I hope there’s something I can do.

  • Thank you very much Jhonsore, it worked perfectly by sending the parameters in this way!

Browser other questions tagged

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