<commit_before><?php

/**
 * This file is part of the AuthnetJSON package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace JohnConde\Authnet;

/**
 * Wrapper to simplify the creation of SIM data
 *
 * @package    AuthnetJSON
 * @author     <NAME> <<EMAIL>>
 * @copyright  <NAME> <<EMAIL>>
 * @license    http://www.apache.org/licenses/LICENSE-2.0.html Apache License, Version 2.0
 * @link       https://github.com/stymiee/authnetjson
 */

class AuthnetSim
{
    /**
     * @var     string  Authorize.Net API login ID
     */
    private $login;

    /**
     * @var     string  Authorize.Net API Transaction Key
     */
    private $transactionKey;

    /**
     * @var     string  URL endpoint for processing a transaction
     */
    private $url;

    /**
     * @var     integer  Randomly generated number
     */
    private $sequence;

    /**
     * @var     integer  Unix timestamp the request was made
     */
    private $timestamp;

    /**
     * Creates a SIM wrapper by setting the Authorize.Net credentials and URL of the endpoint to be used
     * for the API call
     *
     * @param   string  $login              Authorize.Net API login ID
     * @param   string  $transactionKey     Authorize.Net API Transaction Key
     * @param   string  $api_url            URL endpoint for processing a transaction
     */
    public function __construct($login, $transactionKey, $api_url)
    {
        $this->login          = $login;
        $this->transactionKey = $transactionKey;
        $this->url            = $api_url;
        $this->resetParameters();
    }

    /**
     * Returns the hash for the SIM transaction
     *
     * @param   float  $amount   The amount of the transaction
     * @return  string           Hash of five different unique transaction parameters
     * @throws  \JohnConde\Authnet\AuthnetInvalidAmountException
     */
    public function getFingerprint($amount)
    {
        if (!filter_var($amount, FILTER_VALIDATE_FLOAT)) {
            throw new AuthnetInvalidAmountException('You must enter a valid amount greater than zero.');
        }

        return hash_hmac('md5', sprintf('%s^%s^%s^%s^',
            $this->login,
            $this->sequence,
            $this->timestamp,
            $amount
        ), $this->transactionKey);
    }
<commit_msg>Changed SIM algorithm to SHA512. Added FILTER_FLAG_ALLOW_THOUSAND when validating amount for SIM fingerprint<commit_after><?php

/**
 * This file is part of the AuthnetJSON package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace JohnConde\Authnet;

/**
 * Wrapper to simplify the creation of SIM data
 *
 * @package    AuthnetJSON
 * @author     <NAME> <<EMAIL>>
 * @copyright  <NAME> <<EMAIL>>
 * @license    http://www.apache.org/licenses/LICENSE-2.0.html Apache License, Version 2.0
 * @link       https://github.com/stymiee/authnetjson
 */

class AuthnetSim
{
    /**
     * @var     string  Authorize.Net API login ID
     */
    private $login;

    /**
     * @var     string  Authorize.Net API Transaction Key
     */
    private $transactionKey;

    /**
     * @var     string  URL endpoint for processing a transaction
     */
    private $url;

    /**
     * @var     integer  Randomly generated number
     */
    private $sequence;

    /**
     * @var     integer  Unix timestamp the request was made
     */
    private $timestamp;

    /**
     * Creates a SIM wrapper by setting the Authorize.Net credentials and URL of the endpoint to be used
     * for the API call
     *
     * @param   string  $login              Authorize.Net API login ID
     * @param   string  $transactionKey     Authorize.Net API Transaction Key
     * @param   string  $api_url            URL endpoint for processing a transaction
     */
    public function __construct($login, $transactionKey, $api_url)
    {
        $this->login          = $login;
        $this->transactionKey = $transactionKey;
        $this->url            = $api_url;
        $this->resetParameters();
    }

    /**
     * Returns the hash for the SIM transaction
     *
     * @param   float  $amount   The amount of the transaction
     * @return  string           Hash of five different unique transaction parameters
     * @throws  \JohnConde\Authnet\AuthnetInvalidAmountException
     */
    public function getFingerprint($amount)
    {
        if (!filter_var($amount, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND)) {
            throw new AuthnetInvalidAmountException('You must enter a valid amount greater than zero.');
        }

        return hash_hmac('sha512', sprintf('%s^%s^%s^%s^',
            $this->login,
            $this->sequence,
            $this->timestamp,
            $amount
        ), $this->transactionKey);
    }

{'fraction_non_alphanumeric': 0.10092480900683555, 'fraction_numerical': 0.0030156815440289505, 'mean_word_length': 2.1870595771941064, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 37, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2821141', 'n_tokens_mistral': 1412, 'n_tokens_neox': 1379, 'n_words': 431}