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