<commit_before><?php

namespace Xsolla\SDK\PaymentPage;

use Xsolla\SDK\Project;
use Xsolla\SDK\User;
use Xsolla\SDK\Invoice;

class UrlBuilder
{
    const BASE_URL = 'https://secure.xsolla.com/paystation2/?';

    protected $project;

    protected $parameters = array();

    protected $immutableParameters = array();

    protected $hiddenParameters = array();

    protected $lockedParameters = array();

    protected $immutableLockedParameters = array(
        'project' => 'project',
        'signparams' => 'signparams',
    );

    protected $defaultLockedParameters = array(
        'theme' => 'theme',
        'project' => 'project',
        'signparams' => 'signparams',
        'v0' => 'v0',
        'v1' => 'v1',
        'v2' => 'v2',
        'v3' => 'v3',
        'out' => 'out',
        'email' => 'email',
        'currency' => 'currency',
        'userip' => 'userip',
        'allowSubscription' => 'allowSubscription',
        'fastcheckout' => 'fastcheckout',
        'id_package' => 'id_package',
    );

    protected $defaultParameters = array();

    public function __construct(Project $project, array $immutableParameters = array())
    {
        $this->project = $project;
        $this->immutableParameters = $immutableParameters;
        $this->clear();
    }

    public function setUser(User $user, $lockForUser = true, $hideFromUser = false)
    {
        $this->setParameter('v1', $user->getV1(), $lockForUser, $hideFromUser);
        $this->setParameter('v2', $user->getV2(), $lockForUser, $hideFromUser);
        $this->setParameter('v3', $user->getV3(), $lockForUser, $hideFromUser);
        $this->setParameter('email', $user->getEmail(), $lockForUser, $hideFromUser);
        $this->setParameter('userip', $user->getUserIP(), $lockForUser, $hideFromUser);
        $this->setParameter('phone', $user->getPhone(), $lockForUser, $hideFromUser);

        return $this;
    }

    public function setInvoice(Invoice $invoice, $lockForUser = true, $hideFromUser = false)
    {
        $this->setParameter('out', $invoice->getVirtualCurrencyAmount(), $lockForUser, $hideFromUser);
        $this->setParameter('currency', $invoice->getCurrency(), $lockForUser, $hideFromUser);

        return $this;
    }

    /**
     * @param string $locale 2-letter definition is used according to ISO 639-1 standard
     * @return $this
     */
    public function setLocale($locale)
    {
        return $this->setParameter('local', $locale, false, false);
    }

    /**
     * @param string $country 2-letter definition of the country is used according to ISO 3166-1 alpha-2 standard
     * @return $this
     */
    public function setCountry($country)
    {
        return $this->setParameter('country', $country, false, false);
    }

    /**
     * @param string $name Additional parameters described in documentation http://xsolla.github.io/en/pswidget.html#title4
     * @param string $value
     * @param bool $lockForUser Deny user change parameter value on payment page. Also parameter will be hidden on payment page
     * @param bool $hideFromUser Hide parameter value on payment page
     * @return $this
     */
    public function setParameter($name, $value, $lockForUser = false, $hideFromUser = false)
    {
        if (!$value) {
            return $this;
        }
        $this->parameters[$name] = $value;
        if ($hideFromUser) {
            $this->hiddenParameters[] = $name;
        }
        if ($lockForUser) {
            $this->lockParameterForUser($name);
        } else {
            $this->unlockParameterForUser($name);
        }

        return $this;
    }

    /**
     * @param string $name Allow user change parameter value on payment page
     * @return $this
     */
    public function lockParameterForUser($name)
    {
        $this->lockedParameters[$name] = $name;
        return $this;
    }

    /**
     * @param string $name Deny user change parameter value on payment page
     * @return $this
     */
    public function unlockParameterForUser($name)
    {
        unset($this->lockedParameters[$name]);
        return $this;
    }

    public function clear()
    {
        $this->parameters = array();
        $this->hiddenParameters = array();
        $this->lockedParameters = $this->defaultLockedParameters;

        return $this;
    }

    public function getLink()
    {
        $parameters = array_merge($this->parameters, $this->immutableParameters);
        $parameters['project'] = $this->project->getProjectId();<commit_msg>Grammar changes<commit_after><?php

namespace Xsolla\SDK\PaymentPage;

use Xsolla\SDK\Project;
use Xsolla\SDK\User;
use Xsolla\SDK\Invoice;

class UrlBuilder
{
    const BASE_URL = 'https://secure.xsolla.com/paystation2/?';

    protected $project;

    protected $parameters = array();

    protected $immutableParameters = array();

    protected $hiddenParameters = array();

    protected $lockedParameters = array();

    protected $immutableLockedParameters = array(
        'project' => 'project',
        'signparams' => 'signparams',
    );

    protected $defaultLockedParameters = array(
        'theme' => 'theme',
        'project' => 'project',
        'signparams' => 'signparams',
        'v0' => 'v0',
        'v1' => 'v1',
        'v2' => 'v2',
        'v3' => 'v3',
        'out' => 'out',
        'email' => 'email',
        'currency' => 'currency',
        'userip' => 'userip',
        'allowSubscription' => 'allowSubscription',
        'fastcheckout' => 'fastcheckout',
        'id_package' => 'id_package',
    );

    protected $defaultParameters = array();

    public function __construct(Project $project, array $immutableParameters = array())
    {
        $this->project = $project;
        $this->immutableParameters = $immutableParameters;
        $this->clear();
    }

    public function setUser(User $user, $lockForUser = true, $hideFromUser = false)
    {
        $this->setParameter('v1', $user->getV1(), $lockForUser, $hideFromUser);
        $this->setParameter('v2', $user->getV2(), $lockForUser, $hideFromUser);
        $this->setParameter('v3', $user->getV3(), $lockForUser, $hideFromUser);
        $this->setParameter('email', $user->getEmail(), $lockForUser, $hideFromUser);
        $this->setParameter('userip', $user->getUserIP(), $lockForUser, $hideFromUser);
        $this->setParameter('phone', $user->getPhone(), $lockForUser, $hideFromUser);

        return $this;
    }

    public function setInvoice(Invoice $invoice, $lockForUser = true, $hideFromUser = false)
    {
        $this->setParameter('out', $invoice->getVirtualCurrencyAmount(), $lockForUser, $hideFromUser);
        $this->setParameter('currency', $invoice->getCurrency(), $lockForUser, $hideFromUser);

        return $this;
    }

    /**
     * @param string $locale 2-letter definition is used according to ISO 639-1 standard
     * @return $this
     */
    public function setLocale($locale)
    {
        return $this->setParameter('local', $locale, false, false);
    }

    /**
     * @param string $country 2-letter definition of the country is used according to ISO 3166-1 alpha-2 standard
     * @return $this
     */
    public function setCountry($country)
    {
        return $this->setParameter('country', $country, false, false);
    }

    /**
     * @param string $name Additional parameters are described in documentation http://xsolla.github.io/en/pswidget.html#title4
     * @param string $value
     * @param bool $lockForUser Denies user to change parameter value on payment page. Also parameter will be hidden on payment page
     * @param bool $hideFromUser Hides parameter value on payment page
     * @return $this
     */
    public function setParameter($name, $value, $lockForUser = false, $hideFromUser = false)
    {
        if (!$value) {
            return $this;
        }
        $this->parameters[$name] = $value;
        if ($hideFromUser) {
            $this->hiddenParameters[] = $name;
        }
        if ($lockForUser) {
            $this->lockParameterForUser($name);
        } else {
            $this->unlockParameterForUser($name);
        }

        return $this;
    }

    /**
     * @param string $name Allows user to change parameter value on payment page
     * @return $this
     */
    public function lockParameterForUser($name)
    {
        $this->lockedParameters[$name] = $name;
        return $this;
    }

    /**
     * @param string $name Denies user change parameter value on payment page
     * @return $this
     */
    public function unlockParameterForUser($name)
    {
        unset($this->lockedParameters[$name]);
        return $this;
    }

    public function clear()
    {
        $this->parameters = array();
        $this->hiddenParameters = array();
        $this->lockedParameters = $this->defaultLockedParameters;

        return $this;
    }

    public function getLink()
    {
        $parameters = array_merge($this->parameters, $this->immutableParameters);
        $parameters['project'] = $this->project->getProjectId();
{'fraction_non_alphanumeric': 0.1426991150442478, 'fraction_numerical': 0.006194690265486726, 'mean_word_length': 2.7159884915741883, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 105, 'https://': 2, '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': '4015692', 'n_tokens_mistral': 2654, 'n_tokens_neox': 2608, 'n_words': 615}