From f55fd3d984a2542fde2dcf277d1e4a514747c183 Mon Sep 17 00:00:00 2001 From: japatel Date: Fri, 24 Oct 2014 14:59:00 -0500 Subject: [PATCH] Fixed Double JSON Encoding - Updated PPModel to not double encode urls in Json String. --- lib/PayPal/Common/PPModel.php | 5 ++++- tests/PayPal/Test/Api/FlowConfigTest.php | 2 +- tests/PayPal/Test/Api/WebProfileTest.php | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/PayPal/Common/PPModel.php b/lib/PayPal/Common/PPModel.php index 37f6afe..5b6800b 100644 --- a/lib/PayPal/Common/PPModel.php +++ b/lib/PayPal/Common/PPModel.php @@ -218,7 +218,10 @@ class PPModel */ public function toJSON($options = 0) { - return json_encode($this->toArray(), $options); + // Because of PHP Version 5.3, we cannot use JSON_UNESCAPED_SLASHES option + // Instead we would use the str_replace command for now. + // TODO: Replace this code with return json_encode($this->toArray(), $options | 64); once we support PHP >= 5.4 + return str_replace('\\/', '/', json_encode($this->toArray(), $options)); } /** diff --git a/tests/PayPal/Test/Api/FlowConfigTest.php b/tests/PayPal/Test/Api/FlowConfigTest.php index cd8d20e..8df6953 100644 --- a/tests/PayPal/Test/Api/FlowConfigTest.php +++ b/tests/PayPal/Test/Api/FlowConfigTest.php @@ -18,7 +18,7 @@ class FlowConfigTest extends \PHPUnit_Framework_TestCase */ public static function getJson() { - return json_encode(json_decode('{"landing_page_type":"TestSample","bank_txn_pending_url":"http://www.google.com"}')); + return '{"landing_page_type":"TestSample","bank_txn_pending_url":"http://www.google.com"}'; } /** diff --git a/tests/PayPal/Test/Api/WebProfileTest.php b/tests/PayPal/Test/Api/WebProfileTest.php index 0c0345b..9adf308 100644 --- a/tests/PayPal/Test/Api/WebProfileTest.php +++ b/tests/PayPal/Test/Api/WebProfileTest.php @@ -22,7 +22,7 @@ class WebProfileTest extends \PHPUnit_Framework_TestCase */ public static function getJson() { - return json_encode(json_decode('{"id":"TestSample","name":"TestSample","flow_config":' .FlowConfigTest::getJson() . ',"input_fields":' .InputFieldsTest::getJson() . ',"presentation":' .PresentationTest::getJson() . '}')); + return '{"id":"TestSample","name":"TestSample","flow_config":' .FlowConfigTest::getJson() . ',"input_fields":' .InputFieldsTest::getJson() . ',"presentation":' .PresentationTest::getJson() . '}'; } /**