Skip to content
This repository was archived by the owner on Oct 10, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Klarna.php
Original file line number Diff line number Diff line change
Expand Up @@ -3651,13 +3651,24 @@ protected function xmlrpc_call($method, $array)
}
}

//Send the message.
$selectDateTime = microtime(true);
if (self::$xmlrpcDebug) {
$this->xmlrpc->setDebug(2);
}
//Save previous XML RPC client encoding settings.
$tmp_xmlrpc_defencoding = $GLOBALS['xmlrpc_defencoding'];
$tmp_xmlrpc_internalencoding = $GLOBALS['xmlrpc_internalencoding'];
//Set XML RPC client encoding settings.
$GLOBALS['xmlrpc_defencoding'] = 'ISO-8859-1';
$GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit odd.. isn't this the purpose of the $accepted_charset_encodings and $request_charset_encoding fields?

    // The charset encoding used by the server for received messages and
    // by the client for received responses when received charset cannot be determined
    // or is not supported
    $GLOBALS['xmlrpc_defencoding']='UTF-8';

    // The encoding used internally by PHP.
    // String values received as xml will be converted to this, and php strings will be converted to xml
    // as if having been coded with this
    $GLOBALS['xmlrpc_internalencoding']='ISO-8859-1';

Those globals seems to only be there as a fallback.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it works for UTF-8 based PHP applications with current Klarna API (using ISO-8859-1 by default)
Without that both input strings, being sent to Klarna API, as well as strings received from Klarna API (e.g. error messages) are incorrectly interpreted.

Most important is line 3663 - it sets encoding, in which strings accepted as parts of arguments are interpreted and returned strings are encoded. I suppose neither of these things is being set by $accepted_charset_encodings nor $request_charset_encoding, but it is actually the bit, which allows XML RPC client communicate correctly with the rest of the application.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some further investigation, the simplest solution (for us both), would be for you to just set

$GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';

After you have configured the Klarna object (that's when the xmlrpc.inc file is loaded by the composer autoload and the globals are set).

We do not want to change the default encoding due to backward compatibility reasons.


//Send the message.
$xmlrpcresp = $this->xmlrpc->send($msg);

//Restore previous XML RPC client encoding settings.
$GLOBALS['xmlrpc_defencoding'] = $tmp_xmlrpc_defencoding;
$GLOBALS['xmlrpc_internalencoding'] = $tmp_xmlrpc_internalencoding;

//Calculate time and selectTime.
$timeend = microtime(true);
$time = (int) (($selectDateTime - $timestart) * 1000);
Expand Down