Recurring payment error PagSeguro

1

I have a problem with the Secure Pag API in the / pre-approvals method it always returns me missing parameters but I am sending the parameters that the documentation asks for. I followed the step by step documentation 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 retrieve the data sent from the form, the documentation is very confusing I found some with the sending of this form 'senderPhone' and others with the sending of this form 'sender.phone.number', I am sending the email and token, I am already able to make single payment via ticket and card, but recurring payment always returns me errors like:

InmyHTMLformI'msendingalltherequiredinformation,I'vedebuggedthecodeandI'mactuallysendingeverything:

Please, if you're confused, please excuse me, but I'm desperate!

    
asked by anonymous 21.11.2018 / 21:39

1 answer

3

Do you speak Matthew Blz?

Apparently the error is in the data you are sending, just debugging to see what can be right. However, we did an integration with Pagseguro recently and used 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 you can help with something.

    
21.11.2018 / 22:39