Skip to content

Bug de precisión cuando se usa json_encode #49

@gonzalesc

Description

@gonzalesc

Hola.
Los invito a leer este bug : https://bugs.php.net/bug.php?id=72567

Y aunque la solución es corregir el parámetro serialize_precision en el php.ini , podemos cambiar el campo "amount" a string.

Modificando lib/Culqi/Client.php

`
namespace Culqi;
use Culqi\Error as Errors;

/**

  • Class Client

  • @Package Culqi
    */
    class Client {
    public function request($method, $url, $api_key, $data = NULL, $secure_url = false) {
    try {
    $url_params = is_array($data) ? '?' . http_build_query($data) : '';
    $headers= array("Authorization" => "Bearer ".$api_key, "Content-Type" => "application/json", "Accept" => "application/json");
    $options = array(
    'timeout' => 120
    );

         // TODO: We change to string to avoid the precision bug on PHP 7.1
         // URL : https://bugs.php.net/bug.php?id=72567
         if( is_array( $data ) && isset( $data['amount'] ) )
             $data['amount'] = strval( $data['amount'] );
    

........
}
`

PD: si alguien lanza el pullrequest sería de gran ayuda.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions