fjbender / simple-php-integration

This is a very simple Payone Integration in PHP
https://www.payone.de/
Other
17 stars 5 forks source link

Replace JSONP with RESTful API + CORS #4

Open hyzhak opened 7 years ago

hyzhak commented 7 years ago

Hi guys! Thanks for your service. What about to use RESTful API + CORS? CORS is mature approach that is used in many projects recommended as modern alternative to JSONP.

More information here: https://www.html5rocks.com/en/tutorials/cors/

fjbender commented 7 years ago

Thanks for the input! We are in dire need of a RESTful API and will definitely take CORS into account.

However, as this is a rather big project, we'll still need some time to figure stuff out.

hyzhak commented 7 years ago

@fjbender thanks for you work guys!

AlexanderHH commented 7 years ago

You have small bug that occours in windows machines: $explode = explode(PHP_EOL, $response->getBody());

Please replace it direct with "\n" to avoid splitting problems.

fjbender commented 7 years ago

@AlexanderHH Thanks, see https://github.com/fjbender/simple-php-integration/commit/d80eb918733ebf5b1e862af667ecc99f7f5abf6a

AlexanderHH commented 7 years ago

I also prefer to use regex instead of splitting and in some case joining of data like in the parseResponse() method. I changed it to:

        $lines = explode("\n", $response->getBody());
        foreach ($lines as $line) {
            if (!preg_match('/^(.+)=(.+)$/U', $line, $regs)) {
                continue;
            }

            $key = trim($regs[1]);
            $value = trim($regs[2]);

            $result[$key] = $value;
        }
fjbender commented 7 years ago

@AlexanderHH Thanks, can you make a pull request if you already implemented it? :)