Coder Social home page Coder Social logo

Comments (12)

f3l1x avatar f3l1x commented on August 12, 2024

It look's pretty simple to implement it, would you try it?

from gopay-inline.

haltuf avatar haltuf commented on August 12, 2024

Working on it.

from gopay-inline.

haltuf avatar haltuf commented on August 12, 2024

Well, not as easy as it looks on the first sight. API call /accounts/account-statement returns application/octet-stream
When called, the Markette\GopayInline\Http\Response does not contain the content of the file, just headers. Any idea how to fix this and not break everything else?

from gopay-inline.

f3l1x avatar f3l1x commented on August 12, 2024

Mmm. Can you check return header/content-type?

https://github.com/Markette/GopayInline/blob/master/src/Http/Curl.php#L34-L44

from gopay-inline.

haltuf avatar haltuf commented on August 12, 2024

object(Markette\GopayInline\Http\Response)#94 (4) { ["data":protected]=> NULL ["headers":protected]=> array(26) { ["url"]=> string(52) "https://gate.gopay.cz/api/accounts/account-statement" ["content_type"]=> string(24) "application/octet-stream" ["http_code"]=> int(200) ["header_size"]=> int(598) ["request_size"]=> int(379) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(0.232824) ["namelookup_time"]=> float(3.1E-5) ["connect_time"]=> float(0.008602) ["pretransfer_time"]=> float(0.039469) ["size_upload"]=> float(101) ["size_download"]=> float(60416) ["speed_download"]=> float(259492) ["speed_upload"]=> float(433) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(101) ["starttransfer_time"]=> float(0.224169) ["redirect_time"]=> float(0) ["redirect_url"]=> string(0) "" ["primary_ip"]=> string(13) "35.156.106.68" ["certinfo"]=> array(0) { } ["primary_port"]=> int(443) ["local_ip"]=> string(13) "88.86.109.181" ["local_port"]=> int(40482) } ["code":protected]=> int(200) ["error":protected]=> NULL }

The problem is in line
https://github.com/Markette/GopayInline/blob/master/src/Http/Curl.php#L41

$result contains binary content of the file (xls/abo or csv).
json_decode($result) then makes it NULL.

from gopay-inline.

haltuf avatar haltuf commented on August 12, 2024

My idea is to rewrite https://github.com/Markette/GopayInline/blob/master/src/Http/Curl.php#L40-44 to:

} else {

$info = curl_getinfo($ch);
$response->setCode(curl_getinfo($ch, CURLINFO_HTTP_CODE));
$response->setHeaders($info);

if($info['content_type'] == 'application/json') {
    $response->setData(json_decode($result));
} else {
    $response->setData($result);
}

}

What do you say?

from gopay-inline.

f3l1x avatar f3l1x commented on August 12, 2024

Nice idea, that's what I was thinking about. Could we also check application/octet-stream content type? Just for sure.

from gopay-inline.

haltuf avatar haltuf commented on August 12, 2024

So like this?

if($info['content_type'] == 'application/json') {
    $response->setData(json_decode($result));
} elseif($info['content_type'] == 'application/octet-stream' {
    $response->setData($result);
} else {
    $response->setData($result);
}

from gopay-inline.

f3l1x avatar f3l1x commented on August 12, 2024

At this moment we had just application/json. Your plan is to add a application/octet-stream. And I would like to throw an exception if neight of these conditions is mached. Do you agree or do you think it's pointless?

from gopay-inline.

haltuf avatar haltuf commented on August 12, 2024

I wouldn't throw an Exception as it poses a risk of breaking things, that currently work (we would have to check that all the current calls do return application/json correctly to be sure). Saying this, I would restate my suggestion to this:

if($info['content_type'] == 'application/octet-stream') {
    $response->setData($result);
} else {
    $response->setData(json_decode($result));
}

This way we make sure, that everything works exactly as now (and we don't break something by accident), with the exception of application/octet-stream that has newly added behaviour.

from gopay-inline.

f3l1x avatar f3l1x commented on August 12, 2024

Ouk.

from gopay-inline.

f3l1x avatar f3l1x commented on August 12, 2024

Resolved via #25

from gopay-inline.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.