0

I'm getting from payment gateway response like this .

{"orders":[{"amount_charged":"0.00","status":"error","currency":"KZT","description":"dfd","updated":"2022-09-09 00:24:52","id":"71857529528744416","operations":[{"amount":"1512.00","created":"2022-09-09 00:24:52","type":"authorize","currency":"KZT","status":"error"}],"failure_message":"Internal bank error","amount_refunded":"0.00","created":"2022-09-09 00:24:34","merchant_order_id":"12","amount":"1512.00","pan":"489993****2157"}]}1

It look like json but 1 in end is extra . I dont know why it here . Ok, question isnt about it . I cut last character and result look like json. I try to decode it but

json_decode(substr($server_output, 0, -1),true);

result still json

{"orders":[{"created":"2022-09-09 00:24:34","merchant_order_id":"12","pan":"489993****2157","amount":"1512.00","description":"dfd","amount_charged":"0.00","status":"error","currency":"KZT","operations":[{"currency":"KZT","status":"error","type":"authorize","created":"2022-09-09 00:24:52","amount":"1512.00"}],"updated":"2022-09-09 00:24:52","id":"71857529528744416","failure_message":"Internal bank error","amount_refunded":"0.00"}]}

Why json_decode not working ?

3
  • 1
    Your code works and convert JSON string into a PHP array which then you send to client as JSON again Commented Sep 8, 2022 at 20:29
  • 1
    What do you mean with not working? Runs as expected. 3v4l.org/alVP6 Commented Sep 8, 2022 at 20:32
  • 1
    Are you assigning the json_decode() call to a new variable, or are you just checking $server_output again without assigning to it? Commented Sep 8, 2022 at 20:42

1 Answer 1

1

works as expected, gonna need to share your code if your still having issues.

$server_output = '{"orders":[{"created":"2022-09-09 00:24:34","merchant_order_id":"12","pan":"489993****2157","amount":"1512.00","description":"dfd","amount_charged":"0.00","status":"error","currency":"KZT","operations":[{"currency":"KZT","status":"error","type":"authorize","created":"2022-09-09 00:24:52","amount":"1512.00"}],"updated":"2022-09-09 00:24:52","id":"71857529528744416","failure_message":"Internal bank error","amount_refunded":"0.00"}]}1';

$server_output = json_decode(substr($server_output, 0, -1), true);

[
  "orders" => [
    [
      "created" => "2022-09-09 00:24:34",
      "merchant_order_id" => "12",
      "pan" => "489993****2157",
      "amount" => "1512.00",
      "description" => "dfd",
      "amount_charged" => "0.00",
      "status" => "error",
      "currency" => "KZT",
      "operations" => [
        [
          "currency" => "KZT",
          "status" => "error",
          "type" => "authorize",
          "created" => "2022-09-09 00:24:52",
          "amount" => "1512.00",
        ],
      ],
      "updated" => "2022-09-09 00:24:52",
      "id" => "71857529528744416",
      "failure_message" => "Internal bank error",
      "amount_refunded" => "0.00",
    ],
  ],
]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.