-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support BOM removal #3
Comments
Authorize.Net did inform many customers that the BOM would be removed from JSON responses in August 2016, to comply with RFC-7159. That obviously hasn't happened, at least not on the sandbox account.
|
Sample code showing this: // $create_transaction_request is an authorise transaction, for example.
// $client is a Guzzle client and $endpoint is the sandbox.
$response = $client->request('POST', $endpoint, [
'json' => $create_transaction_request, // Guzzle will convert this to JSON.
]);
$result = (string)$response->getBody();
echo "<p>Length with BOM: " . strlen($result) . "</p>";
// With BOM: 540
var_dump(json_decode($result)); // NULL :-(
// Remove the BOM
$result = preg_replace('/^[\x00-\x1F\x80-\xFF]{1,3}/', '', $result);
echo "<p>Length without BOM: " . strlen($result) . "</p>";
// Without BOM: 537
var_dump(json_decode($result)); // ...the full response :-) Just using |
This is a bit messy. The JSON response from Authorize.Net includes a BOM sequence at the start. This is invisible to the human eye, but causes
json_decode()
to throw a wobbly. It simply cannot decode the JSON with the BOM.This is suggested in many places to remove the BOM:
I would probably be a little more specific by looking at only the first (up to) three characters:
There is also a plugin for Guzzle that removes the BOM, but that appears to be for older Guzzle versions. Not sure about the latest.
Anyway, it has not really got anything to do with these messages, because it's not a part of the data, but if we are not aware of it, it will certainly come to bite us when not dealt with at the transport level.
The text was updated successfully, but these errors were encountered: