<commit_before><?php

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

namespace Tala\Billing\AuthorizeNet;

use Tala\Exception;
use Tala\Exception\InvalidResponseException;
use Tala\FormRedirectResponse;
use Tala\Request;

/**
 * Authorize.Net SIM Class
 */
class SIMGateway extends AIMGateway
{
    public function authorize(Request $request, $source)
    {
        $data = $this->buildAuthorizeOrPurchase($request, $source, 'AUTH_ONLY');

        return new FormRedirectResponse($this->getCurrentEndpoint(), $data);
    }

    public function completeAuthorize(Request $request)
    {
        if ( ! $this->validateReturnHash()) {
            throw new InvalidResponseException();
        }

        $responseCode = isset($_POST['x_response_code']) ? $_POST['x_response_code'] : '';
        $message = isset($_POST['x_response_reason_text']) ? $_POST['x_response_reason_text'] : '';
        $reference = isset($_POST['x_trans_id']) ? $_POST['x_trans_id'] : '';

        if ($response_code == '1') {
            return new Response($reference, $message);
        }

        throw new Exception($message);
    }

    public function purchase(Request $request, $source)
    {
        $data = $this->buildAuthorizeOrPurchase($request, $source, 'AUTH_CAPTURE');

        return new FormRedirectResponse($this->getCurrentEndpoint(), $data);
    }

    public function completePurchase(Request $request)
    {
        return $this->completeAuthorize($request);
    }

    protected function buildAuthorizeOrPurchase($request, $source, $method)
    {
        $request->validateRequired(array('amount', 'returnUrl'));

        $data = array();
        $data['x_login'] = $this->apiLoginId;
        $data['x_type'] = $method;
        $data['x_fp_sequence'] = mt_rand();
        $data['x_fp_timestamp'] = time();
        $data['x_delim_data'] = 'FALSE';<commit_msg>AuthorizeNet fixes<commit_after><?php

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

namespace Tala\Billing\AuthorizeNet;

use Tala\Exception;
use Tala\Exception\InvalidResponseException;
use Tala\FormRedirectResponse;
use Tala\Request;

/**
 * Authorize.Net SIM Class
 */
class SIMGateway extends AIMGateway
{
    public function authorize(Request $request, $source)
    {
        $data = $this->buildAuthorizeOrPurchase($request, $source, 'AUTH_ONLY');

        return new FormRedirectResponse($this->getCurrentEndpoint(), $data);
    }

    public function completeAuthorize(Request $request)
    {
        if ( ! $this->validateReturnHash($request)) {
            throw new InvalidResponseException();
        }

        $responseCode = isset($_POST['x_response_code']) ? $_POST['x_response_code'] : '';
        $message = isset($_POST['x_response_reason_text']) ? $_POST['x_response_reason_text'] : '';
        $reference = isset($_POST['x_trans_id']) ? $_POST['x_trans_id'] : '';

        if ($responseCode == '1') {
            return new Response($reference, $message);
        }

        throw new Exception($message);
    }

    public function purchase(Request $request, $source)
    {
        $data = $this->buildAuthorizeOrPurchase($request, $source, 'AUTH_CAPTURE');

        return new FormRedirectResponse($this->getCurrentEndpoint(), $data);
    }

    public function completePurchase(Request $request)
    {
        return $this->completeAuthorize($request);
    }

    protected function buildAuthorizeOrPurchase($request, $source, $method)
    {
        $request->validateRequired(array('amount', 'returnUrl'));

        $data = array();
        $data['x_login'] = $this->apiLoginId;
        $data['x_type'] = $method;
        $data['x_fp_sequence'] = mt_rand();
        $data['x_fp_timestamp'] = time();
        $data['x_delim_data'] = 'FALSE';
{'fraction_non_alphanumeric': 0.14064039408866996, 'fraction_numerical': 0.0004926108374384236, 'mean_word_length': 3.4045553145336225, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7477483', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1168, 'n_words': 256}