Midtrans/midtrans-php

TODO: check whether HTTP request body exists, if not throw a proper error. To prevent confusing array-key not exist related err msg.

rizdaprasetya opened this issue · 1 comments

Current Unexpected:

public function __construct($input_source = "php://input")
{
$raw_notification = json_decode(file_get_contents($input_source), true);
$status_response = Transaction::status($raw_notification['transaction_id']);
$this->response = $status_response;
}

On that function,

  • when HTTP request come and that function get executed,
    • IF the HTTP request body is not exist, THEN it will unexpectedly throw error of Trying to access array offset on value of type null on line 26.
    • which could be misleading because it just throw array-key related error message without actually explaining what went wrong.

Expected:

  • The code should better check
    • Is parsing of the HTTP request body succeeds ?
    • Is json_decode succeeds ?
    • is $raw_notification['transaction_id'] exists?
    • optionally: Is the HTTP request valid HTTP POST method?
  • Then the code should throw a more user-friendly error message that indicate what failed.
    • So that user could understand better.

Note:

  • This will not prevent the actual root cause of issue that triggers the exception. But at least by letting user know what process failed, they can have better insight in investigating the actual root cause. e.g. HTTP Request body is missing from the request, then they can check their infra is something removing the body.

Duplicate or could be merged with this backlog.