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

namespace Ogone;

use InvalidArgumentException;

abstract class AbstractPaymentRequest extends AbstractRequest
{
    protected $brandsmap = array(
        'Acceptgiro' => 'Acceptgiro',
        'AIRPLUS' => 'CreditCard',
        'American Express' => 'CreditCard',
        'Aurora' => 'CreditCard',
        'Aurore' => 'CreditCard',
        'Bank transfer' => 'Bank transfer',
        'BCMC' => 'CreditCard',
        'Belfius Direct Net' => 'Belfius Direct Net',
        'Billy' => 'CreditCard',
        'cashU' => 'cashU',
        'CB' => 'CreditCard',
        'CBC Online' => 'CBC Online',
        'CENTEA Online' => 'CENTEA Online',
        'Cofinoga' => 'CreditCard',
        'Dankort' => 'CreditCard',
        'Dexia Direct Net' => 'Dexia Direct Net',
        'Diners Club' => 'CreditCard',
        'Direct Debits AT' => 'Direct Debits AT',
        'Direct Debits DE' => 'Direct Debits DE',
        'Direct Debits NL' => 'Direct Debits NL',
        'eDankort' => 'eDankort',
        'EPS' => 'EPS',
        'Fortis Pay Button' => 'Fortis Pay Button',
        'giropay' => 'giropay',
        'iDEAL' => 'iDEAL',
        'ING HomePay' => 'ING HomePay',
        'InterSolve' => 'InterSolve',
        'JCB' => 'CreditCard',
        'KBC Online' => 'KBC Online',
        'Maestro' => 'CreditCard',
        'MaestroUK' => 'CreditCard',
        'MasterCard' => 'CreditCard',
        'MiniTix' => 'MiniTix',
        'MPASS' => 'MPASS',
        'NetReserve' => 'CreditCard',
        'Payment on Delivery' => 'Payment on Delivery',
        'PAYPAL' => 'PAYPAL',
        'paysafecard' => 'paysafecard',
        'PingPing' => 'PingPing',
        'PostFinance + card' => 'PostFinance Card',
        'PostFinance e-finance' => 'PostFinance e-finance',
        'PRIVILEGE' => 'CreditCard',
        'Sofort Uberweisung' => 'DirectEbanking',
        'Solo' => 'CreditCard',
        'TUNZ' => 'TUNZ',
        'UATP' => 'CreditCard',
        'UNEUROCOM' => 'UNEUROCOM',
        'VISA' => 'CreditCard',
        'Wallie' => 'Wallie',
    );

    /** Note this is public to allow easy modification, if need be. */
    public $allowedcurrencies = array(
        'AED', 'ANG', 'ARS', 'AUD', 'AWG', 'BGN', 'BRL', 'BYR', 'CAD', 'CHF',
        'CNY', 'CZK', 'DKK', 'EEK', 'EGP', 'EUR', 'GBP', 'GEL', 'HKD', 'HRK',
        'HUF', 'ILS', 'ISK', 'JPY', 'KRW', 'LTL', 'LVL', 'MAD', 'MXN', 'NOK',
        'NZD', 'PLN', 'RON', 'RUB', 'SEK', 'SGD', 'SKK', 'THB', 'TRY', 'UAH',
        'USD', 'XAF', 'XOF', 'XPF', 'ZAR'
    );

    public function setOrderid($orderid)
    {
        if (strlen($orderid) > 30) {
            throw new InvalidArgumentException("Orderid cannot be longer than 30 characters");
        }
        if (preg_match('/[^a-zA-Z0-9_-]/', $orderid)) {
            throw new InvalidArgumentException("Order id cannot contain special characters");
        }
        $this->parameters['orderid'] = $orderid;
    }

    /** Friend alias for setCom() */
    public function setOrderDescription($orderDescription)
    {
        $this->setCom($orderDescription);
    }

    public function setCom($com)
    {
        if (strlen($com) > 100) {
            throw new InvalidArgumentException("Order description cannot be longer than 100 characters");
        }
        $this->parameters['com'] = $com;
    }

    /**
     * Set amount in cents, eg EUR 12.34 is written as 1234
     */
    public function setAmount($amount)
    {
        if (!is_int($amount)) {
            throw new InvalidArgumentException("Integer expected. Amount is always in cents");
        }
        if ($amount <= 0) {
            throw new InvalidArgumentException("Amount must be a positive number");
        }
        if ($amount >= 1.0E+15) {
            throw new InvalidArgumentException("Amount is too high");
        }
        $this->parameters['amount'] = $amount;

    }

    public function setCurrency($currency)
    {
        if (!in_array(strtoupper($currency), $this->allowedcurrencies)) {
            throw new InvalidArgumentException("Unknown currency");
        }
        $this->parameters['currency'] = $currency;
    }

    public function setEmail($email)
    {
        if (strlen($email) > 50) {
            throw new InvalidArgumentException("Email is too long");
        }
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            throw new InvalidArgumentException("Email is invalid");
        }
        $this->parameters['email'] = $email;
    }

    public function setOwnerAddress($owneraddress)
    {
        if (strlen($owneraddress) > 35) {
            throw new InvalidArgumentException("Owner address is too long");
        }
        $this->parameters['owneraddress'] = $owneraddress;
    }

    public function setOwnerZip($ownerzip)
    {
        if (strlen($ownerzip) > 10) {
            throw new InvalidArgumentException("Owner Zip is too long");
        }
        $this->parameters['ownerzip'] = $ownerzip;
    }

    public function setOwnerTown($ownertown)
    {
        if (strlen($ownertown) > 25) {
            throw new InvalidArgumentException("Owner town is too long");
        }
        $this->parameters['ownertown'] = $ownertown;
    }

    /**
     * Alias for setOwnercty
     * @see http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm
     */
    public function setOwnerCountry($ownercountry)
    {
        $this->setOwnercty($ownercountry);
    }

    /**
     * @see http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm
     */
    public function setOwnercty($ownercty)
    {
        if (!preg_match('/^[A-Z]{2}$/', strtoupper($ownercty))) {
            throw new InvalidArgumentException("Illegal country code");
        }
        $this->parameters['ownercty'] = strtoupper($ownercty);
    }<commit_msg>allow 40 chars for OwnerTown<commit_after><?php
/*
 * This file is part of the Marlon Ogone package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Ogone;

use InvalidArgumentException;

abstract class AbstractPaymentRequest extends AbstractRequest
{
    protected $brandsmap = array(
        'Acceptgiro' => 'Acceptgiro',
        'AIRPLUS' => 'CreditCard',
        'American Express' => 'CreditCard',
        'Aurora' => 'CreditCard',
        'Aurore' => 'CreditCard',
        'Bank transfer' => 'Bank transfer',
        'BCMC' => 'CreditCard',
        'Belfius Direct Net' => 'Belfius Direct Net',
        'Billy' => 'CreditCard',
        'cashU' => 'cashU',
        'CB' => 'CreditCard',
        'CBC Online' => 'CBC Online',
        'CENTEA Online' => 'CENTEA Online',
        'Cofinoga' => 'CreditCard',
        'Dankort' => 'CreditCard',
        'Dexia Direct Net' => 'Dexia Direct Net',
        'Diners Club' => 'CreditCard',
        'Direct Debits AT' => 'Direct Debits AT',
        'Direct Debits DE' => 'Direct Debits DE',
        'Direct Debits NL' => 'Direct Debits NL',
        'eDankort' => 'eDankort',
        'EPS' => 'EPS',
        'Fortis Pay Button' => 'Fortis Pay Button',
        'giropay' => 'giropay',
        'iDEAL' => 'iDEAL',
        'ING HomePay' => 'ING HomePay',
        'InterSolve' => 'InterSolve',
        'JCB' => 'CreditCard',
        'KBC Online' => 'KBC Online',
        'Maestro' => 'CreditCard',
        'MaestroUK' => 'CreditCard',
        'MasterCard' => 'CreditCard',
        'MiniTix' => 'MiniTix',
        'MPASS' => 'MPASS',
        'NetReserve' => 'CreditCard',
        'Payment on Delivery' => 'Payment on Delivery',
        'PAYPAL' => 'PAYPAL',
        'paysafecard' => 'paysafecard',
        'PingPing' => 'PingPing',
        'PostFinance + card' => 'PostFinance Card',
        'PostFinance e-finance' => 'PostFinance e-finance',
        'PRIVILEGE' => 'CreditCard',
        'Sofort Uberweisung' => 'DirectEbanking',
        'Solo' => 'CreditCard',
        'TUNZ' => 'TUNZ',
        'UATP' => 'CreditCard',
        'UNEUROCOM' => 'UNEUROCOM',
        'VISA' => 'CreditCard',
        'Wallie' => 'Wallie',
    );

    /** Note this is public to allow easy modification, if need be. */
    public $allowedcurrencies = array(
        'AED', 'ANG', 'ARS', 'AUD', 'AWG', 'BGN', 'BRL', 'BYR', 'CAD', 'CHF',
        'CNY', 'CZK', 'DKK', 'EEK', 'EGP', 'EUR', 'GBP', 'GEL', 'HKD', 'HRK',
        'HUF', 'ILS', 'ISK', 'JPY', 'KRW', 'LTL', 'LVL', 'MAD', 'MXN', 'NOK',
        'NZD', 'PLN', 'RON', 'RUB', 'SEK', 'SGD', 'SKK', 'THB', 'TRY', 'UAH',
        'USD', 'XAF', 'XOF', 'XPF', 'ZAR'
    );

    public function setOrderid($orderid)
    {
        if (strlen($orderid) > 30) {
            throw new InvalidArgumentException("Orderid cannot be longer than 30 characters");
        }
        if (preg_match('/[^a-zA-Z0-9_-]/', $orderid)) {
            throw new InvalidArgumentException("Order id cannot contain special characters");
        }
        $this->parameters['orderid'] = $orderid;
    }

    /** Friend alias for setCom() */
    public function setOrderDescription($orderDescription)
    {
        $this->setCom($orderDescription);
    }

    public function setCom($com)
    {
        if (strlen($com) > 100) {
            throw new InvalidArgumentException("Order description cannot be longer than 100 characters");
        }
        $this->parameters['com'] = $com;
    }

    /**
     * Set amount in cents, eg EUR 12.34 is written as 1234
     */
    public function setAmount($amount)
    {
        if (!is_int($amount)) {
            throw new InvalidArgumentException("Integer expected. Amount is always in cents");
        }
        if ($amount <= 0) {
            throw new InvalidArgumentException("Amount must be a positive number");
        }
        if ($amount >= 1.0E+15) {
            throw new InvalidArgumentException("Amount is too high");
        }
        $this->parameters['amount'] = $amount;

    }

    public function setCurrency($currency)
    {
        if (!in_array(strtoupper($currency), $this->allowedcurrencies)) {
            throw new InvalidArgumentException("Unknown currency");
        }
        $this->parameters['currency'] = $currency;
    }

    public function setEmail($email)
    {
        if (strlen($email) > 50) {
            throw new InvalidArgumentException("Email is too long");
        }
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            throw new InvalidArgumentException("Email is invalid");
        }
        $this->parameters['email'] = $email;
    }

    public function setOwnerAddress($owneraddress)
    {
        if (strlen($owneraddress) > 35) {
            throw new InvalidArgumentException("Owner address is too long");
        }
        $this->parameters['owneraddress'] = $owneraddress;
    }

    public function setOwnerZip($ownerzip)
    {
        if (strlen($ownerzip) > 10) {
            throw new InvalidArgumentException("Owner Zip is too long");
        }
        $this->parameters['ownerzip'] = $ownerzip;
    }

    public function setOwnerTown($ownertown)
    {
        if (strlen($ownertown) > 40) {
            throw new InvalidArgumentException("Owner town is too long");
        }
        $this->parameters['ownertown'] = $ownertown;
    }

    /**
     * Alias for setOwnercty
     * @see http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm
     */
    public function setOwnerCountry($ownercountry)
    {
        $this->setOwnercty($ownercountry);
    }

    /**
     * @see http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm
     */
    public function setOwnercty($ownercty)
    {
        if (!preg_match('/^[A-Z]{2}$/', strtoupper($ownercty))) {
            throw new InvalidArgumentException("Illegal country code");
        }
        $this->parameters['ownercty'] = strtoupper($ownercty);
    }
{'fraction_non_alphanumeric': 0.15465700403524665, 'fraction_numerical': 0.007082269620357407, 'mean_word_length': 2.4451063829787234, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 145, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '4506848', 'n_tokens_mistral': 3965, 'n_tokens_neox': 3756, 'n_words': 910}