• Resolved samuelmafra

    (@samuelmafra)


    Ocorre em alguns valores do checkout, como exemplo com total de 140.55.

    “errors”: {
    “order.items[0].amount”: [
    “Input string ‘14055.000000000002’ is not a valid integer. Path ‘items[0].amount’, line 1, position 73.”,
    “The field amount must be greater than or equal to 1”
    ]
    },

    O problema está no arquivo PagarmeApiV5.php linha 38.

    ‘amount’ => $order->get_total() * 100,

    Pode ser resolvido convertendo a string para integer:

    ‘amount’ => (int)$order->get_total() * 100,

    Espero ter ajudado.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author marcosgn

    (@marcosgn)

    Obrigado Samuel, vou corrigir, valeu mesmo. Se puder avaliar agrade?o!

    A solu??o funciona e por isso te agrade?o, Samuel. Entretanto, quando um pedido possui decimal (ex.: 150,37), ao aderir à sua solu??o, o PIX fica apenas 150,00, ou seja, ele ignora os decimais. A princípio pode n?o ser um problema, mas em um volume alto pode complicar. Será que há outra solu??o?

    Thread Starter samuelmafra

    (@samuelmafra)

    Resolvi o problema das casas decimais assim:

    Adicionar o código abaixo antes do $data = array……

    $orderTotal=$order->get_total();
    $orderTotal = number_format($orderTotal,2);
    $orderTotal = str_replace(“,”, “”, $orderTotal);
    $orderTotal = str_replace(“.”, “”, $orderTotal);

    E depois no amount, adicione:

    ‘amount’ => $orderTotal,

    Segue código na ordem:

      public function generate_transaction_data($order)
      {
        // Set the request data.
        
        $orderTotal=$order->get_total();
        $orderTotal = number_format($orderTotal,2);
        $orderTotal = str_replace(",", "", $orderTotal);
        $orderTotal = str_replace(".", "", $orderTotal);
        
        
        $data = array(
          'metadata' => [
            'order_number' => $order->get_order_number(),
          ],
          'items' => [
            [
              'amount' => $orderTotal,
              'description' => 'WCPagarmePixPayment',
              'quantity' => 1
            ]
          ],

    Perfeito, Samuel. Testado e aprovado! Obrigado, meu caro.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Input string is not a valid integer’ is closed to new replies.