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
6 REPLIES 6

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

I encountered a

 

PHP Fatal error

 

when we upgraded to PHP 8.0 from PHP7.4 (PHP 8 Support for AuthorizeNet/sdk-php). Eventually Authorize.net did update the version to 2.0.2 which resolved the error. I am hopeful someone from the Authorize.net development team will bump the version to 2.0.3 and properly resolve the return type issue.

The new issue caused by upgrading to PHP 8.1 from PHP 8.0 (PHP 8.0 is EOL as of 11-26-2023) is the same error that @iteracy received:

 

Deprecated [description] => 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]

 

The workaround was to fork the https://github.com/AuthorizeNet/sdk-php and do a search and replace for all references of 

 

public function jsonSerialize(){

 

 then replace this with

 

   #[\ReturnTypeWillChange]
    public function jsonSerialize(): mixed
    {

 

Based on the error message I received, specifying the return type to mixed and/or adding #[\ReturnTypeWillChange] will temporarily suppress the notice. I tested the fork with our PHPUnit test suite and the errors went away and the warning message went away. You can use our version of the AuthorizeNet/sdk-php -> https://github.com/resumeblaze/sdk-php

You can see there were 528 additions and 178 deletions: https://github.com/AuthorizeNet/sdk-php/compare/master...resumeblaze:sdk-php:master. Then number of changes is inline with other users that have come across the same issue, for examplehttps://github.com/AuthorizeNet/sdk-php/compare/master...zhartaunik:authorizenet-sdk-php:master.

Its important to note this does not fix the problem, it will suppress the notice so that you may use the package with PHP 8.1.

dblaze
Contributor

I can't believe they still haven't fixed this

Here is an update from support. Looks like support can't help with this issue and the case was automatically closed.

Thank you for contacting Authorize.Net in regard to integration, happy to assist.

I understand that you need assistance on the compatibility of PHP versions. We apologize, but we are not trained in web development or integration, so our ability to answer developer or integration related questions is limited. We can only assist for some basic troubleshooting steps about integration.

We appreciate your time and business.

If the information provided above satisfies your needs, please close this Support Case. Otherwise, please add an update to this Support Case with your follow-up questions so I can further assist you. For your convenience the Authorize.Net Support Center, located at: https://support.authorize.net. You may also call us at (877) 447-3938, available 24 hours a day, 7 days a week.

For more information regarding our privacy practices, visit the privacy page at Authorize.Net.

dblaze
Contributor

One more update! I spoke to someone at Authorize.net today and they are aware of the issue. They have been contacted by several merchants encountering the same error. Keep the pressure on the support team and open tickets at https://support.authorize.net/. They said they will update the SDK soon. Make sure to point out that PHP 8.1 is the current (stable version of PHP). 8.0 is no longer supported: https://www.php.net/supported-versions.php.

dblaze
Contributor

It appears that when you upgrade to PHP 8.2, there is another subtle error. The latest release of PHP is 8.2, not 8.1. There are only security updates for PHP 8.1 for the next 10-months. 8.2 is in active development for the next 10-months. See
https://www.php.net/supported-versions.php

/authorizenet/lib/net/authorize/util/Log.php:366
Creation of dynamic property net\authorize\util\Log::$sensitiveStringRegexes is deprecated

This is a simple fix, go to:
sdk-php/lib/net/authorize/util/Log.php on line 34 and add a declaration.

private $sensitiveStringRegexes = NULL;

The warning will go away. I have made this change to the forked repository at https://github.com/resumeblaze/sdk-php/releases/tag/2.0.4

I bumped our forked version from 2.0.3 to 2.0.4

dblaze
Contributor