Pessoal estou com uma dor de cabeça com isso vou mandar o codigo do xml do que eu quero pegar e do que não está indo

> xml

    <result>
    <success>true</success>
    <data>
    <charges>
    <charge>
    <code>80079409</code>
    <dueDate>16/08/2019</dueDate>
    <checkoutUrl>
    https://sandbox.boletobancario.com/boletofacil/checkout/5E4426FF099E1A1C88E388EEB03571610B43523DFB8C8356
    </checkoutUrl>
    <link>
    https://sandbox.boletobancario.com/boletofacil/charge/boleto.pdf?token=539231:m:bb5b865782ceec0633b43500fe3a2633d51b43303e1c7674a80e0e12383df30b
    </link>
    <payNumber>BOLETO PAGO</payNumber>
    <billetDetails>
    <bankAccount>0655/46480-8</bankAccount>
    <ourNumber>176/80079409-2</ourNumber>
    <barcodeNumber>34191798300000021001768007940920655464808000</barcodeNumber>
    <portfolio>176</portfolio>
    </billetDetails>
    <payments>
    <payment>
    <id>27942</id>
    <amount>21.00</amount>
    <date>12/08/2019</date>
    <fee>3.90</fee>
    <type>BOLETO</type>
    <status>CONFIRMED</status>
    <creditCardId/>
    </payment>
    </payments>
    </charge>
    <charge>
    <code>80079399</code>
    <dueDate>16/08/2019</dueDate>
    <checkoutUrl>
    https://sandbox.boletobancario.com/boletofacil/checkout/4E6E654050A7F01250197376A4F2DDC5E16C6B297FDA03F2
    </checkoutUrl>
    <link>
    https://sandbox.boletobancario.com/boletofacil/charge/boleto.pdf?token=539221:m:2dedab41ca47e7c16c80b1da059be0bb83f2ef860b68302729671a18f18da845
    </link>
    <payNumber>BOLETO PAGO</payNumber>
    <billetDetails>
    <bankAccount>0655/46480-8</bankAccount>
    <ourNumber>176/80079399-5</ourNumber>
    <barcodeNumber>34191798300000032001768007939950655464808000</barcodeNumber>
    <portfolio>176</portfolio>
    </billetDetails>
    <payments>
    <payment>
    <id>27941</id>
    <amount>32.00</amount>
    <date>12/08/2019</date>
    <fee>3.90</fee>
    <type>BOLETO</type>
    <status>CONFIRMED</status>
    <creditCardId/>
    </payment>
    </payments>
    </charge>

> consultarboletos.php

    <?php 
        include("../../conexao.php");
    
    
    if(!isset($_SESSION)){
        session_start();
    }
        $query4 = "select * from funcionalidades where id = '1'";
        $result4 = mysqli_query($conexao, $query4);
        $dados4 = mysqli_fetch_array($result4);
    
          if(mysqli_num_rows ($result4) > 0) {
            
          }
        if($dados4['status'] == 1) {
        if (isset($_POST['data'])){
                $data =  $_POST['data'];
                $token = "3C9D99D90FF1F6F9AF2353D708CA2C59BFC6828CBDFF4ED2254F9CE4D3EBA416";
                    
                function gerar($token,$data){
                    $url = "https://sandbox.boletobancario.com/boletofacil/integration/api/v1/list-charges?";
                    $url .= "token=".$token."&";
                    $url .= "beginPaymentDate=".$data."&";
                    $url .= "responseType=XML";
                    
                    return $url;
                }
                
                  $xml = gerar($token,$data);
                  $boleto = simplexml_load_file($xml);
                $capeta = $boleto->data->charges->charge;
                foreach($capeta as $dados){
               
                 echo $dados->code;
             echo "<br>";
                 echo $dados->payNumber;
                  echo "<br>";
                }
                 
              
        }
        }else{
            echo "Função desabilitada contate um administrador para fazer a liberação!";
        }
    ?>

Assim ele pega as informações no loop correto ja no consultarpagamento2.php
já assim ele so pega 1 e não pega o resto

> consultarpagamento2.php

   

     <?php 
        include("../../conexao.php");
    
    
    if(!isset($_SESSION)){
        session_start();
    }
        $query4 = "select * from funcionalidades where id = '1'";
        $result4 = mysqli_query($conexao, $query4);
        $dados4 = mysqli_fetch_array($result4);
    
          if(mysqli_num_rows ($result4) > 0) {
            
          }
        if($dados4['status'] == 1) {
        if (isset($_POST['data'])){
                $data =  $_POST['data'];
                $token = "3C9D99D90FF1F6F9AF2353D708CA2C59BFC6828CBDFF4ED2254F9CE4D3EBA416";
                    
                function gerar($token,$data){
                    $url = "https://sandbox.boletobancario.com/boletofacil/integration/api/v1/list-charges?";
                    $url .= "token=".$token."&";
                    $url .= "beginPaymentDate=".$data."&";
                    $url .= "responseType=XML";
                    
                    return $url;
                }
                
                  $xml = gerar($token,$data);
                  $boleto = simplexml_load_file($xml);
                $capeta = $boleto->data->charges->charge->payments->payment;
                foreach($capeta as $dados){
               
                 echo $dados->id;
             echo "";
                 echo $dados->amount;
                 
                }
                 
              
        }
        }else{
            echo "Função desabilitada contate um administrador para fazer a liberação!";
        }
    ?>