After connecting successfully to the Authorize.net with this line of code:
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
I receive this error in my browser:
An error occurred in script 'C:\xampp\htdocs\vendor\lib\net\authorize\api\contract\v1\MerchantAuthenticationType.php' on line 260: 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
I tried to supress the error in MerchantAuthenticationType.php, by placing #[\ReturnTypeWillChange] over the jsonSerialize() function as the error suggests:
#[\ReturnTypeWillChange]
// Json Serialize Code
public function jsonSerialize(){
$values = array_filter((array)get_object_vars($this),
function ($val){
return !is_null($val);
});
$mapper = \net\authorize\util\Mapper::Instance();
foreach($values as $key => $value){
$classDetails = $mapper->getClass(get_class() , $key);
if (isset($value)){
if ($classDetails->className === 'Date'){
$dateTime = $value->format('Y-m-d');
$values[$key] = $dateTime;
}
else if ($classDetails->className === 'DateTime'){
$dateTime = $value->format('Y-m-d\TH:i:s\Z');
$values[$key] = $dateTime;
}
if (is_array($value)){
if (!$classDetails->isInlineArray){
$subKey = $classDetails->arrayEntryname;
$subArray = [$subKey => $value];
$values[$key] = $subArray;
}
}
}
}
return $values;
}
This suppressed the error but then I received the following error:
An error occurred in script 'C:\xampp\htdocs\vendor\lib\net\authorize\util\Log.php' on line 162:
preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
This is the line of code that the new error is referring to in Log.php on line 162:
$prop->setValue($obj,preg_replace($inputPattern,$inputReplacement,$prop->getValue($obj)));
The full authorize.net method from Log.php is which contains this line of code is:
private function checkPropertyAndMask($prop, $obj){
foreach($this->sensitiveXmlTags as $i => $sensitiveField)
{
$inputPattern = "(.+)";
$inputReplacement = "xxxx";
if(trim($sensitiveField->pattern)) {
$inputPattern = $sensitiveField->pattern;
}
$inputPattern = $this->addDelimiterFwdSlash($inputPattern);
if(trim($sensitiveField->replacement)) {
$inputReplacement = $sensitiveField->replacement;
}
if(strcmp($prop->getName(),$sensitiveField->tagName)==0)
{
$prop->setValue($obj,preg_replace($inputPattern,$inputReplacement,$prop->getValue($obj)));
return $prop->getValue($obj);
}
}
return false;
}
Any help from someone familiar with this error would greatly be appreciated.
06-05-2022 11:24 AM - edited 06-05-2022 11:36 AM
public JsonSerializable::jsonSerialize(): mixed
Serializes the object to a value that can be serialized natively by json_encode().
06-07-2022 09:36 PM - last edited on 07-25-2022 10:32 PM by KH-Taylarie