Simulação de Parcelamentos

Para facilitar o calculo de parcelamento, conforme configuração realizada pelo lojista no TrayCheckout, é disponibiliza a API de Simulação de Parcelamentos, onde através do token do lojista e o valor da transação, são retornados os parcelamentos de todas as formas de pagamento.

OBS: A API de Simulação de Parcelamentos é utilizada somente para facilitar a exibição deste parcelamento na loja virtual, onde é enviada somente a quantidade de parcelas para a API de Pagamento.

Para esta integração, deverá ser feito uso da API a seguir:

Endereço para Integração
Ambiente de Testes https://api.sandbox.traycheckout.com.br/v1/transactions/simulate_splitting
Ambiente de Produção https://api.traycheckout.com.br/v1/transactions/simulate_splitting
Protocolo Rest/HTTP

Para a integração com esta API, segue abaixo os dados necessários para envio:

Dados de Entrada Obrig. Formato / Tam. Max Descrição
token_account Sim Texto / 20 Token de Integração
price Sim Decimal Valor Total para Simulação

Veja abaixo um exemplo da simulação de parcelamentos:

    <?php
        /* Dados para Simulação de Parcelamentos */
        $params['token_account'] = '### Token de Integração ###';
        $params['price'] = '### Valor Total para Simulação ###';

        $urlPost = "https://api.sandbox.traycheckout.com.br/v1/transactions/simulate_splitting";

        ob_start();

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $urlPost);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        curl_exec($ch);

        /* XML de retorno */ 
        $resposta = simplexml_load_string(ob_get_contents());

        ob_end_clean();
        curl_close($ch);

        if($resposta->message_response->message == "success"){
            //Tratamento dos dados de resposta com sucesso.
        }else{
            //Tratamento das mensagens de erro
        }
    ?>

Após o processamento, é retornado um XML de resposta com os detalhes da simulação de parcelamentos realizada com sucesso. Segue abaixo detalhamento de cada nó do XML de resposta:

XML de Resposta

<transaction>

Nó principal da resposta

<transaction>

<message_response>

Nó que contém o resultado da resposta

<transaction>

<message_response>

<message>

Resposta sobre a solicitação

Em caso de sucesso: success

Em caso de erro: error

<transaction>

<data_response>

Nó que contém os dados da resposta

<transaction>

<data_response>

<payment_methods>

Nó que contém os dados da simulação de parcelamentos

<transaction>

<data_response>

<payment_methods>

<payment_method>

Nó que contém os dado da simulação de uma forma de pagamento

<transaction>

<data_response>

<payment_methods>

<payment_method>

<price_customer>

Valor para o Consumidor

<transaction>

<data_response>

<payment_methods>

<payment_method>

<price_seller>

Valor para o Vendedor

<transaction>

<data_response>

<payment_methods>

<payment_method>

<price_original>

Valor Original

<transaction>

<data_response>

<payment_methods>

<payment_method>

<split>

Número de Parcelas

<transaction>

<data_response>

<payment_methods>

<payment_method>

<payment_method_name>

Nome do Meio de Pagamento

<transaction>

<data_response>

<payment_methods>

<payment_method>

<payment_method_id>

Código do Meio de Pagamento

<transaction>

<data_response>

<payment_methods>

<payment_method>

<splittings>

Nó com os valores de parcelamento do meio de pagamento

<transaction>

<data_response>

<payment_methods>

<payment_method>

<splittings>

<split>

Número da parcela

<transaction>

<data_response>

<payment_methods>

<payment_method>

<splittings>

<value_split>

Valor da parcela

<transaction>

<data_response>

<payment_methods>

<payment_method>

<splittings>

<value_transaction>

Valor da transação

<transaction>

<data_response>

<payment_methods>

<payment_method>

<splittings>

<addition_retention>

Taxa de Retenção

<transaction>

<data_response>

<payment_methods>

<payment_method>

<splittings>

<split_rate>

Taxa de Parcelamento

Exemplo do XML de resposta após a simulação de parcelamentos com sucesso:

    <transaction>
        <message_response>
            <message>success</message>
        </message_response>
        <data_response>
            <payment_methods type="array">
                <payment_method>
                    <price_customer>123.00</price_customer>
                    <price_seller>96.83</price_seller>
                    <price_original>123.00</price_original>
                    <split type="integer">12</split>
                    <payment_method_name>Visa</payment_method_name>
                    <payment_method_id type="integer">3</payment_method_id>
                    <splittings type="array">
                        <splitting>
                            <split type="integer">1</split>
                            <value_split>123.00</value_split>
                            <value_transaction>123.00</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="integer">0</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">2</split>
                            <value_split>61.50</value_split>
                            <value_transaction>123.00</value_transaction>
                            <addition_retention>3.68</addition_retention>
                            <split_rate type="integer">0</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">3</split>
                            <value_split>41.00</value_split>
                            <value_transaction>123.00</value_transaction>
                            <addition_retention>4.92</addition_retention>
                            <split_rate type="integer">0</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">4</split>
                            <value_split>30.75</value_split>
                            <value_transaction>123.00</value_transaction>
                            <addition_retention>9.32</addition_retention>
                            <split_rate type="integer">0</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">5</split>
                            <value_split>26.85</value_split>
                            <value_transaction>134.25</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">2.99</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">6</split>
                            <value_split>22.70</value_split>
                            <value_transaction>136.20</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">2.99</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">7</split>
                            <value_split>19.73</value_split>
                            <value_transaction>138.11</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">2.99</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">8</split>
                            <value_split>18.26</value_split>
                            <value_transaction>146.08</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">3.99</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">9</split>
                            <value_split>16.54</value_split>
                            <value_transaction>148.86</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">3.99</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">10</split>
                            <value_split>15.16</value_split>
                            <value_transaction>151.60</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">3.99</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">11</split>
                            <value_split>14.03</value_split>
                            <value_transaction>154.33</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">3.99</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">12</split>
                            <value_split>13.10</value_split>
                            <value_transaction>157.20</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">3.99</split_rate>
                        </splitting>
                    </splittings>
                </payment_method>
                <payment_method>
                    <price_customer>123.00</price_customer>
                    <price_seller>114.75</price_seller>
                    <price_original>123.00</price_original>
                    <split type="integer">12</split>
                    <payment_method_name>Mastercard</payment_method_name>
                    <payment_method_id type="integer">4</payment_method_id>
                    <splittings type="array">
                        <splitting>
                            <split type="integer">1</split>
                            <value_split>123.00</value_split>
                            <value_transaction>123.00</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="integer">0</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">2</split>
                            <value_split>63.34</value_split>
                            <value_transaction>126.68</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">1.99</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">3</split>
                            <value_split>42.64</value_split>
                            <value_transaction>127.92</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">1.99</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">4</split>
                            <value_split>32.29</value_split>
                            <value_transaction>129.16</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">1.99</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">5</split>
                            <value_split>26.09</value_split>
                            <value_transaction>130.45</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">1.99</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">6</split>
                            <value_split>21.95</value_split>
                            <value_transaction>131.70</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">1.99</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">7</split>
                            <value_split>19.00</value_split>
                            <value_transaction>133.00</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">1.99</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">8</split>
                            <value_split>16.78</value_split>
                            <value_transaction>134.24</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">1.99</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">9</split>
                            <value_split>15.06</value_split>
                            <value_transaction>135.54</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">1.99</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">10</split>
                            <value_split>13.69</value_split>
                            <value_transaction>136.90</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">1.99</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">11</split>
                            <value_split>12.56</value_split>
                            <value_transaction>138.16</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">1.99</split_rate>
                        </splitting>
                        <splitting>
                            <split type="integer">12</split>
                            <value_split>11.62</value_split>
                            <value_transaction>139.44</value_transaction>
                            <addition_retention>0.00</addition_retention>
                            <split_rate type="decimal">1.99</split_rate>
                        </splitting>
                    </splittings>
                </payment_method>
            </payment_methods>
        </data_response>
    </transaction>

Mensagens de Erro

No caso de erro, a API retorna uma mensagem de erro. Assim é possível identificar o erro ocorrido e realizar o tratamento através do código e/ou mensagem retornada.

Abaixo segue os detalhes de cada nó do XML de resposta:

XML de Resposta

<withdraw>

Nó principal da resposta

<withdraw>

<message_response>

Nó que contém o resultado da resposta

<withdraw>

<message_response>

<message>

Resposta sobre a solicitação

Em caso de sucesso: success

Em caso de erro: error

<withdraw>

<error_response>

Nó que contém os erros encontrados

<withdraw>

<error_response>

<general_errors>

Nó que contém os erros encontrados

<withdraw>

<error_response>

<general_errors>

<general_error>

Nó que contém o detalhamento de um erro

<withdraw>

<error_response>

<general_errors>

<general_error>

<code>

Código do erro

<withdraw>

<error_response>

<general_errors>

<general_error>

<message>

Mensagem do erro

Exemplo de um retorno com erro:

    <withdraw>
        <message_response>
            <message>error</message>
        </message_response>
        <error_response>
            <general_errors type="array">
                <general_error>
                    <code>001001</code>
                    <message>Token inválido ou não encontrado.</message>
                </general_error>
            </general_errors>
        </error_response>
    </withdraw>

As mensagens de erros retornados pela API estão listadas na tabela abaixo:

CódigoMensagem
001001 Token inválido ou não encontrado.
003002 Valor da Transação Inválido.