mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Transactions\Services;
|
|
|
|
use App\Models\SegmentConstant;
|
|
|
|
class CalculatesTransactionServiceCharge
|
|
{
|
|
/** @var CalculatesTransactionTransferFee */
|
|
private $calculatesTransactionTransferFee;
|
|
|
|
/**
|
|
* CalculatesTransactionServiceCharge constructor.
|
|
* @param CalculatesTransactionTransferFee $calculatesTransactionTransferFee
|
|
*/
|
|
public function __construct(CalculatesTransactionTransferFee $calculatesTransactionTransferFee)
|
|
{
|
|
$this->calculatesTransactionTransferFee = $calculatesTransactionTransferFee;
|
|
}
|
|
|
|
|
|
/**
|
|
* @param float $amount
|
|
* @param float $rate
|
|
* @param SegmentConstant|null $service_charge
|
|
* @return float
|
|
*/
|
|
public function execute(float $amount, float $rate, ?SegmentConstant $service_charge) {
|
|
|
|
if(!$service_charge) {
|
|
return 0;
|
|
}
|
|
|
|
$transfer_fee = $this->calculatesTransactionTransferFee->execute(($amount * (1 / $rate)), $service_charge);
|
|
return $service_charge->detail->amount->type === 'percentage' ? (($amount + $transfer_fee) * ( (float) $service_charge->detail->amount->value /100) * (1/$rate)) : (float) $service_charge->detail->amount->value;
|
|
|
|
}
|
|
|
|
} |