square / connect-php-sdk

PHP client library for the Square Connect APIs
https://developer.squareup.com/docs
Apache License 2.0
114 stars 55 forks source link

listPaymentsWithHttpInfo not returning batch_token with V1TransactionsApi #118

Closed TravisCornelius closed 4 years ago

TravisCornelius commented 4 years ago

Maxing out the 200 limit, and need to get the batch token, even setting the limit to 1, I'm still not getting any batch token info in the [link] header params.

SquareConnect\Util\CaseInsensitiveArray Object
(
    [lower_dict:SquareConnect\Util\CaseInsensitiveArray:private] => Array
        (
            [0] => HTTP/1.1 200 OK
            [content-type] => application/json
            [link] => ;rel='next'
            [vary] => Origin, Accept-Encoding
            [x-content-type-options] => nosniff
            [x-download-options] => noopen
            [x-frame-options] => SAMEORIGIN
            [x-permitted-cross-domain-policies] => none
            [x-xss-protection] => 1; mode=block
            [date] => Mon, 03 Feb 2020 23:44:34 GMT
            [strict-transport-security] => max-age=631152000; includeSubDomains; preload
            [transfer-encoding] => chunked
        )

    [storage:ArrayObject:private] => Array
        (
            [0] => HTTP/1.1 200 OK
            [Content-Type] => application/json
            [Link] => ;rel='next'
            [Vary] => Origin, Accept-Encoding
            [X-Content-Type-Options] => nosniff
            [X-Download-Options] => noopen
            [X-Frame-Options] => SAMEORIGIN
            [X-Permitted-Cross-Domain-Policies] => none
            [X-Xss-Protection] => 1; mode=block
            [Date] => Mon, 03 Feb 2020 23:44:34 GMT
            [Strict-Transport-Security] => max-age=631152000; includeSubDomains; preload
            [Transfer-Encoding] => chunked
        )

)

SquareConnect\Configuration::getDefaultConfiguration()->setAccessToken(API_KEY_SQUARE);
$api_instance = new \SquareConnect\Api\V1TransactionsApi();
list($result, $status, $headers) = $api_instance->listPaymentsWithHttpInfo($square_location_id, $order, $start, $end, $limit, $batch_token);
$batch_token = \SquareConnect\ApiClient::getV1BatchTokenFromHeaders($headers);

However, in Terminal I'm able run the same command and I get the batch_token: curl -I https://connect.squareup.com/v1/XXXXXXXXXXXX/payments -X GET -H 'Content-Type: application/json' -H 'Square-Version: 2020-01-22' -H 'Authorization: Bearer XXXXXXXXXX'

I'm also able to get the token via:

 $url = "https://connect.squareup.com/v1/XXXXXXXXXXXXX/payments";
          $headers[] = "Accept: application/json";
          $headers[] = "Content-Type: application/json";
          $headers[] = "Square-Version: 2020-01-22";
          $headers[] = "Authorization: Bearer XXXXXXXXXXXXXXXXX";

          $ch = curl_init();

          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($ch, CURLOPT_HEADER, 1);

          $response = curl_exec($ch);

          // Retudn headers seperatly from the Response Body
          $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
          $headers = substr($response, 0, $header_size);
          $body = substr($response, $header_size);

          curl_close($ch);
TravisCornelius commented 4 years ago

In the callApi method of the ApiClient.php file if I add

header('Content-type: text/html; charset=UTF-8');

it seems to display in the print_r

StephenJosey commented 4 years ago

Thanks for reporting. We're looking into the cause behind this, I'm seeing the same as you.

StephenJosey commented 4 years ago

@TravisCornelius great news! A fix has been released for this. Please update to version 2.20200122.1, and it should work :). Let me know if that's not the case.