1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
<?php
/**
*/
namespace Commercetools\Core\Model\Common;
/**
* @package Commercetools\Core\Model\Common
* @link https://docs.commercetools.com/http-api-types.html#money
* @method string getCurrencyCode()
* @method int getCentAmount()
* @method HighPrecisionMoney setCurrencyCode(string $currencyCode = null)
* @method HighPrecisionMoney setCentAmount(int $centAmount = null)
* @method string getType()
* @method HighPrecisionMoney setType(string $type = null)
* @method int getFractionDigits()
* @method HighPrecisionMoney setFractionDigits(int $fractionDigits = null)
* @method int getPreciseAmount()
* @method HighPrecisionMoney setPreciseAmount(int $preciseAmount = null)
* @method string getHighPrecision()
* @method HighPrecisionMoney setHighPrecision(string $highPrecision = null)
*/
class HighPrecisionMoney extends Money
{
const PRECISE_AMOUNT = 'preciseAmount';
/**
* @inheritDoc
*/
public function __construct(array $data = [], $context = null)
{
$data[static::TYPE] = static::TYPE_HIGH_PRECISION;
parent::__construct($data, $context);
}
public function fieldDefinitions()
{
return [
static::CURRENCY_CODE => [self::TYPE => 'string'],
static::CENT_AMOUNT => [self::TYPE => 'int'],
static::TYPE => [self::TYPE => 'string'],
static::FRACTION_DIGITS => [self::TYPE => 'int'],
static::PRECISE_AMOUNT => [self::TYPE => 'int'],
];
}
/**
* @param string $currencyCode
* @param int $amount
* @param int $fractionDigits
* @param Context|callable $context
* @return HighPrecisionMoney
*/
public static function ofCurrencyAmountAndFraction($currencyCode, $amount, $fractionDigits, $context = null)
{
$money = static::of($context);
return $money->setCurrencyCode($currencyCode)
->setPreciseAmount($amount)
->setFractionDigits($fractionDigits);
}
/**
* @param $currencyCode
* @param $centAmount
* @param Context|callable $context
* @return HighPrecisionMoney|Money
*/
public static function ofCurrencyAndAmount($currencyCode, $centAmount, $context = null)
{
$money = static::of($context);
return $money->setCurrencyCode($currencyCode)
->setPreciseAmount($centAmount)
->setFractionDigits(2);
}
}