/
Currency.php
130 lines (118 loc) · 4.84 KB
/
Currency.php
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
namespace Df\Payment;
use Df\Directory\FE\Currency as CurrencyFE;
use Df\Payment\Method as M;
use Magento\Framework\App\ScopeInterface as IScope;
use Magento\Quote\Model\Quote as Q;
use Magento\Sales\Model\Order as O;
use Magento\Store\Model\Store;
/**
* 2017-10-12
* @see \Dfe\Spryng\Currency
* @see \Dfe\Stripe\Currency
*/
class Currency {
/**
* 2016-09-05
* Отныне валюта платёжных транзакций настраивается администратором опцией
* «Mage2.PRO» → «Payment» → <...> → «Payment Currency»
* 2017-02-08
* Конвертирует $a из учётной валюты в валюту платежа
* ($oq используется только для определения магазина => настроек магазина).
* @used-by \Df\Payment\Method::convert()
* @used-by \Df\Payment\Method::isAvailable()
* @param O|Q $oq
*/
final function fromBase(float $a, $oq):float {return $this->convert($a, df_currency_base_c($oq), $oq);}
/**
* 2016-09-05
* Отныне валюта платёжных транзакций настраивается администратором опцией
* «Mage2.PRO» → «Payment» → <...> → «Payment Currency»
* 2017-02-08 Converts $a from the currency of $oq to the payment currency.
* @used-by dfpex_from_doc()
* @used-by \Df\Payment\ConfigProvider::amount()
* @param O|Q $oq
*/
final function fromOrder(float $a, $oq):float {return $this->convert($a, df_oq_currency_c($oq), $oq);}
/**
* 2016-09-05 «Mage2.PRO» → «Payment» → <...> → «Payment Currency».
* Текущая валюта может меняться динамически (в том числе посетителем магазина и сессией),
* поэтому мы используем параметр store, а не scope.
* @used-by self::oq()
* @used-by self::rateToPayment()
* @used-by \Df\Payment\ConfigProvider::config()
* @param null|string|int|IScope|Store $s [optional]
*/
final function iso3($s = null, string $oc = ''):string {return dfc($this, function($s, string $oc):string {return
CurrencyFE::v($this->_iso3($s), $s, $oc)
;}, [$s, $oc]);}
/**
* 2016-09-07
* @used-by self::convert()
* @used-by self::toBase()
* @used-by self::toOrder()
* @used-by \Df\Payment\Method::cPayment()
* @used-by \Df\Payment\Method::isAvailable()
* @used-by \Df\Payment\Operation\Source::currencyC()
* @param O|Q $oq
*/
final function oq($oq):string {return $this->iso3($oq->getStore(), df_oq_currency_c($oq));}
/**
* 2016-09-06 Курс обмена учётной валюты на платёжную.
* @used-by \Df\Payment\ConfigProvider::config()
*/
final function rateToPayment():float {return df_currency_base()->getRate($this->iso3());}
/**
* 2016-09-08
* Конвертирует $a из валюты платежа в учётную ($oq используется только для определения магазина => настроек магазина).
* @used-by \Df\Payment\Method::convert()
* @param O|Q $oq
*/
final function toBase(float $a, $oq):float {return df_currency_convert($a, $this->oq($oq), df_currency_base($oq));}
/**
* 2016-09-07 Конвертирует $a из валюты платежа в валюту заказа $o.
* @used-by \Df\Payment\Method::convert()
*/
final function toOrder(float $a, O $o):float {return df_currency_convert($a, $this->oq($o), $o->getOrderCurrencyCode());}
/**
* 2017-10-12
* @used-by self::iso3()
* @see \Dfe\Spryng\Currency::_iso3()
* @see \Dfe\Stripe\Currency::_iso3()
* @param null|string|int|IScope|Store $s [optional]
*/
protected function _iso3($s = null):string {return $this->s()->v('currency', $s);}
/**
* 2017-10-12
* @final I do not use the PHP «final» keyword here to allow refine the return type using PHPDoc.
* @used-by \Dfe\Stripe\Method::cardType()
*/
protected function m():Method {return $this->_m;}
/**
* 2017-10-12
* @final I do not use the PHP «final» keyword here to allow refine the return type using PHPDoc.
* @used-by self::_iso3()
*/
protected function s():Settings {return $this->_m->s();}
/**
* 2016-09-05 Конвертирует денежную величину в валюту «Mage2.PRO» → «Payment» → <...> → «Payment Currency».
* @used-by self::fromBase()
* @used-by self::fromOrder()
* @param O|Q $oq
*/
private function convert(float $a, string $from, $oq):float {return df_currency_convert($a, $from, $this->oq($oq));}
/**
* 2017-10-12
* @used-by self::factory()
* @var M
*/
private $_m;
/**
* 2017-10-12
* @used-by dfp_currency()
* @param object|string $m
*/
final static function f($m):self {return dfcf(function(M $m) { /** @var self $i */
$i = df_new(df_con_heir($m, __CLASS__)); $i->_m = $m; return $i;
}, [dfpm($m)]);}
}