I don't think we should set the date to today when it is not present in the response. It works on create because the function is executed before the user input is assigned, but in the edit it is the other way around. Design flaw imo.
if ($response) {
if (is_array($response['expiration_date'])) {
$expiry = new DateTime($response['expiration_date'][1]);
}
else {
$expiry = new DateTime($response['expiration_date']);
}
return $expiry->format('Y-m-d');
}
Here you can see, that it hits the else branch and sets current date as expiration, because the response doesnt have that field.
Requested change could be to have
if ($response) {
if (is_array($response['expiration_date'])) {
$expiry = new DateTime($response['expiration_date'][1]);
}
elseif (isset($response['expiration_date'])) {
$expiry = new DateTime($response['expiration_date']);
}
else {
return null;
}
return $expiry->format('Y-m-d');
}
and then when type null is returned, expiration is not set or set to 'NULL' depending on edit/creation/cron