cancel
Showing results for 
Search instead for 
Did you mean: 

Upgrading PHP SDK to PHP 8.1

I'm part of a development team that manages a website using the Authorize.net PHP SDK. I hope this is the right place to ask questions about this. 
 
The website is currently using v.2.0.2 of the Official PHP SDK for Authorize.Net. Our website uses PHP 7.4 but as this is now end-of-life, we're looking to upgrade to PHP 8.1. We ran some tests using 8.1, but the API threw fatal errors including:
 
Error [number 1] During inheritance of JsonSerializable: Uncaught ; File: folder_name/vendor/authorizenet/authorizenet/lib/net/authorize/api/contract/v1/MerchantAuthenticationType.php; Line: 11
 
Error [number 8192] Return type of net\authorize\api\contract\v1\MerchantAuthenticationType::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice; File: folder_name/vendor/authorizenet/authorizenet/lib/net/authorize/api/contract/v1/MerchantAuthenticationType.php; Line: 261
I looked on the Github pages at https://github.com/AuthorizeNet/sdk-php/ for an updated version of the code for PHP 8.1 but it looks like 2.0.2 is the latest version. I also saw quite a few people complaining that the code didn't work on PHP 8.1. 
 
I'd really appreciate guidance on where to go from here - are there plans to release a fix for PHP 8.1, or is there an easy way I can fix this myself? 
iteracy
Member
1 REPLY 1

If anyone with the same problem comes across this message: in the end, we fixed it ourselves without any help from Authorize.net (can you tell how angry I am about their lack of support?). We took the advice of jdpace2 in the Issues section of the Github repo (https://github.com/AuthorizeNet/sdk-php/issues/440#issuecomment-1622942466

Search for all instances of 

public function jsonSerialize()

Replace them with:

#[\ReturnTypeWillChange]
public function jsonSerialize()

This allowed us to move to PHP 8.1 without any issues. It's not a perfect solution, but it works for now.

iteracy
Member