<commit_before><?php
/**
 * Checkout.com Magento 2 Payment module (https://www.checkout.com)
 *
 * Copyright (c) 2017 Checkout.com (https://www.checkout.com)
 * Author: <NAME> | <EMAIL>
 *
 * License GNU/GPL V3 https://www.gnu.org/licenses/gpl-3.0.en.html
 */

namespace CheckoutCom\Magento2\Model\Adapter;

use InvalidArgumentException;
use Magento\Directory\Model\CurrencyFactory;
use Magento\Store\Model\StoreManagerInterface;
use CheckoutCom\Magento2\Gateway\Config\Config as GatewayConfig;

class ChargeAmountAdapter {

    /**
     * Currency types available in the module configuration.
     */
    const BASE_CURRENCY = 'base_currency';
    const ORDER_CURRENCY = 'order_currency';
    const CUSTOM_CURRENCY = 'custom_currency';

    /**
     * Currencies where charge amount is full.
     *
     * @var array
     */
    const FULL_VALUE_CURRENCIES = ['BYR', 'BIF', 'DJF', 'GNF', 'KMF', 'XAF', 'CLF', 'XPF', 'JPY', 'PYG', 'RWF', 'KRW', 'VUV', 'VND', 'XOF'];

    /**
     * Currencies where charge amount is divided by 1000.
     *
     * @var array
     */
    const DIV_1000_VALUE_CURRENCIES = ['BHD', 'KWD', 'OMR', 'JOD'];

    const DIV_1000 = 1000;

    const DIV_100 = 100;

    /**
     * @var GatewayConfig
     */
    protected $gatewayConfig;

    /**
     * @var StoreManagerInterface
     */
    protected $storeManager;

    /**
     * @var CurrencyFactory
     */
    protected $currencyFactory;

    /**
     * ChargeAmountAdaoter constructor.
     * @param GatewayConfig $gatewayConfig
     */
    public function __construct(GatewayConfig $gatewayConfig, StoreManagerInterface $storeManager, CurrencyFactory $currencyFactory) {
        $this->gatewayConfig = $gatewayConfig;
        $this->storeManager = $storeManager;
        $this->currencyFactory = $currencyFactory;
    }

    /**
     * Returns transformed amount by the given currency code which can be handled by the gateway API.
     *
     * @param float $amount Value from the store.
     * @param string $currencyCode
     * @return int
     * @throws InvalidArgumentException
     */
    public static function getGatewayAmountOfCurrency($amount, $currencyCode) {
        $currencyCode = strtoupper($currencyCode);

        if ( ! is_numeric($amount) ) {
            throw new InvalidArgumentException('The amount value is not numeric. The [' . $amount . '] value has been given.');
        }

        $amount = (float) $amount;

        if ($amount <= 0) {
            throw new InvalidArgumentException('The amount value must be positive. The [' . $amount . '] value has been given.');
        }

        if( in_array($currencyCode, self::FULL_VALUE_CURRENCIES, true) ) {
            return (int) $amount;
        }

        if( in_array($currencyCode, self::DIV_1000_VALUE_CURRENCIES, true) ) {
            return (int) ($amount * self::DIV_1000);
        }

        return (int) ($amount * self::DIV_100);
    }

    /**
     * Returns transformed amount by the given currency code which can be handled by the store.
     *
     * @param string|int $amount Value from the gateway.
     * @param $currencyCode
     * @return float
     */
    public static function getStoreAmountOfCurrency($amount, $currencyCode) {
        $currencyCode   = strtoupper($currencyCode);
        $amount         = (int) $amount;

        if( in_array($currencyCode, self::FULL_VALUE_CURRENCIES, true) ) {
            return (float) $amount;<commit_msg>Allow 0 values in checkout<commit_after><?php
/**
 * Checkout.com Magento 2 Payment module (https://www.checkout.com)
 *
 * Copyright (c) 2017 Checkout.com (https://www.checkout.com)
 * Author: <NAME> | <EMAIL>
 *
 * License GNU/GPL V3 https://www.gnu.org/licenses/gpl-3.0.en.html
 */

namespace CheckoutCom\Magento2\Model\Adapter;

use InvalidArgumentException;
use Magento\Directory\Model\CurrencyFactory;
use Magento\Store\Model\StoreManagerInterface;
use CheckoutCom\Magento2\Gateway\Config\Config as GatewayConfig;

class ChargeAmountAdapter {

    /**
     * Currency types available in the module configuration.
     */
    const BASE_CURRENCY = 'base_currency';
    const ORDER_CURRENCY = 'order_currency';
    const CUSTOM_CURRENCY = 'custom_currency';

    /**
     * Currencies where charge amount is full.
     *
     * @var array
     */
    const FULL_VALUE_CURRENCIES = ['BYR', 'BIF', 'DJF', 'GNF', 'KMF', 'XAF', 'CLF', 'XPF', 'JPY', 'PYG', 'RWF', 'KRW', 'VUV', 'VND', 'XOF'];

    /**
     * Currencies where charge amount is divided by 1000.
     *
     * @var array
     */
    const DIV_1000_VALUE_CURRENCIES = ['BHD', 'KWD', 'OMR', 'JOD'];

    const DIV_1000 = 1000;

    const DIV_100 = 100;

    /**
     * @var GatewayConfig
     */
    protected $gatewayConfig;

    /**
     * @var StoreManagerInterface
     */
    protected $storeManager;

    /**
     * @var CurrencyFactory
     */
    protected $currencyFactory;

    /**
     * ChargeAmountAdaoter constructor.
     * @param GatewayConfig $gatewayConfig
     */
    public function __construct(GatewayConfig $gatewayConfig, StoreManagerInterface $storeManager, CurrencyFactory $currencyFactory) {
        $this->gatewayConfig = $gatewayConfig;
        $this->storeManager = $storeManager;
        $this->currencyFactory = $currencyFactory;
    }

    /**
     * Returns transformed amount by the given currency code which can be handled by the gateway API.
     *
     * @param float $amount Value from the store.
     * @param string $currencyCode
     * @return int
     * @throws InvalidArgumentException
     */
    public static function getGatewayAmountOfCurrency($amount, $currencyCode) {
        $currencyCode = strtoupper($currencyCode);

        if ( ! is_numeric($amount) ) {
            throw new InvalidArgumentException('The amount value is not numeric. The [' . $amount . '] value has been given.');
        }

        $amount = (float) $amount;

        if( in_array($currencyCode, self::FULL_VALUE_CURRENCIES, true) ) {
            return (int) $amount;
        }

        if( in_array($currencyCode, self::DIV_1000_VALUE_CURRENCIES, true) ) {
            return (int) ($amount * self::DIV_1000);
        }

        return (int) ($amount * self::DIV_100);
    }

    /**
     * Returns transformed amount by the given currency code which can be handled by the store.
     *
     * @param string|int $amount Value from the gateway.
     * @param $currencyCode
     * @return float
     */
    public static function getStoreAmountOfCurrency($amount, $currencyCode) {
        $currencyCode   = strtoupper($currencyCode);
        $amount         = (int) $amount;

        if( in_array($currencyCode, self::FULL_VALUE_CURRENCIES, true) ) {
            return (float) $amount;
{'fraction_non_alphanumeric': 0.12111708482676224, 'fraction_numerical': 0.013142174432497013, 'mean_word_length': 2.745525727069351, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 13, 'https://': 6, 'lorem ipsum': 0, 'www.': 6, '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': '4107420', 'n_tokens_mistral': 2121, 'n_tokens_neox': 1993, 'n_words': 510}