PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / helpers / libraries / currency / converter.php
vikappointments / site / helpers / libraries / currency Last commit date
converter 4 days ago helper 4 days ago converter.php 4 days ago currency.php 4 days ago index.html 4 days ago
converter.php
66 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Currency converter class handler.
16 *
17 * @since 1.7.6
18 */
19 abstract class VAPCurrencyConverter
20 {
21 /** @var VAPCurrency */
22 protected $currency;
23
24 /**
25 * Class constructor.
26 *
27 * @param VAPCurrency $currency The source currency object.
28 */
29 public function __construct(VAPCurrency $currency)
30 {
31 $this->currency = $currency;
32 }
33
34 /**
35 * Returns a new currency instance containing the preferences of the
36 * specified one as well as the ratio to perform real-time conversions.
37 *
38 * @param string $currency The new currency (ISO 4217).
39 *
40 * @return VAPCurrency
41 */
42 abstract public function getCurrency(string $currency);
43
44 /**
45 * Returns the conversion rate among the specified currency and the default one.
46 *
47 * @param string $currency The destination currency (ISO 4217).
48 *
49 * @return float
50 */
51 abstract public function getRate(string $currency);
52
53 /**
54 * Converts the provided price from the original currency to the specified one.
55 *
56 * @param float $amount The amount to convert.
57 * @param string $currency The destination currency (ISO 4217).
58 *
59 * @return float
60 */
61 final public function getPrice(float $amount, string $currency)
62 {
63 return $amount / $this->getRate($currency);
64 }
65 }
66