getData('x_amount'))) { $this->setData('x_amount', '0.00'); } if (!empty($this->getData('x_SHA2_Hash'))) { $hash = $this->generateSha2Hash($storedHash); return Security::compareStrings($hash, $this->getData('x_SHA2_Hash')); } elseif (!empty($this->getData('x_MD5_Hash'))) { $hash = $this->generateHash($storedHash, $merchantApiLogin, $this->getXAmount(), $this->getXTransId()); return Security::compareStrings($hash, $this->getData('x_MD5_Hash')); } return false; } /** * Return if this is approved response from Authorize.net auth request. * * @return bool */ public function isApproved() { return $this->getXResponseCode() == \Magento\Authorizenet\Model\Directpost::RESPONSE_CODE_APPROVED; } /** * Generates an SHA2 hash to compare against AuthNet's. * * @param string $signatureKey * @return string * @see https://support.authorize.net/s/article/MD5-Hash-End-of-Life-Signature-Key-Replacement */ private function generateSha2Hash(string $signatureKey): string { $hashFields = [ 'x_trans_id', 'x_test_request', 'x_response_code', 'x_auth_code', 'x_cvv2_resp_code', 'x_cavv_response', 'x_avs_code', 'x_method', 'x_account_number', 'x_amount', 'x_company', 'x_first_name', 'x_last_name', 'x_address', 'x_city', 'x_state', 'x_zip', 'x_country', 'x_phone', 'x_fax', 'x_email', 'x_ship_to_company', 'x_ship_to_first_name', 'x_ship_to_last_name', 'x_ship_to_address', 'x_ship_to_city', 'x_ship_to_state', 'x_ship_to_zip', 'x_ship_to_country', 'x_invoice_num', ]; $message = '^'; foreach ($hashFields as $field) { $message .= ($this->getData($field) ?? '') . '^'; } return strtoupper(hash_hmac('sha512', $message, pack('H*', $signatureKey))); } }