HTTP Code 0 is odd
That means theres something super wrong on your server, and it’s ability to make HTTP requests
Expand the code to spit out more information about the error.
Line 55 is blank?
Line line 80 $error = 'An Error Occured at code for token exchange: ' . print_r($r, true); you probably want to update, to dump out the whole $i object and trace the issue.
HTTP Code 0 can be “failed to find the server” or other issue
You can also use
https://www.php.net/curl_error
To help debug
Not this code tested fine on localtest and is similar to what I use in production