Skip to content

Commit

Permalink
fix : mdr callculation
Browse files Browse the repository at this point in the history
  • Loading branch information
otnansirk committed Jul 31, 2023
1 parent 35e2a1a commit bde7d7f
Showing 1 changed file with 51 additions and 36 deletions.
87 changes: 51 additions & 36 deletions src/Helpers/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,54 @@ class Calculation
{


public static $TAX = config("dana.fee_tax", 0.11); // is equal to 11%
public static $FEES = [
"CREDIT_CARD" => [
"mdr_percent" => config("dana.mdr_percent.credit_card", 0.018),
// is equal to 1.8%
],
"DEBIT_CARD" => [
"mdr_percent" => config("dana.mdr_percent.debit_card", 0.018),
// is equal to 1.8%
],
"BALANCE" => [
"mdr_percent" => config("dana.mdr_percent.balance", 0.012),
// is equal to 1.2%
],
"DIRECT_DEBIT_CREDIT_CARD" => [
"mdr_percent" => config("dana.mdr_percent.direct_debit_credit_card", 0.012),
// is equal to 1.2%
],
"DIRECT_DEBIT_DEBIT_CARD" => [
"mdr_percent" => config("dana.mdr_percent.direct_debit_debit_card", 0.012),
// is equal to 1.2%
],
"VIRTUAL_ACCOUNT" => [
"mdr_before_tax" => config("dana.mdr_before_tax.virtual_account", 2000),
// is equal to 2000 Rupiah
],
"ONLINE_CREDIT" => [
"mdr_percent" => config("dana.mdr_percent.online_credit", 0.012),
// is equal to 1.2%
]
];

/**
* DANA tax
*
* @return float
*/
public function taxValue(): float
{
return config("dana.fee_tax", 0.11); // is equal to 11%
}

/**
* DANA fees
*
* @return array
*/
public function fees(): array
{
return [
"CREDIT_CARD" => [
"mdr_percent" => config("dana.mdr_percent.credit_card", 0.018),
// is equal to 1.8%
],
"DEBIT_CARD" => [
"mdr_percent" => config("dana.mdr_percent.debit_card", 0.018),
// is equal to 1.8%
],
"BALANCE" => [
"mdr_percent" => config("dana.mdr_percent.balance", 0.012),
// is equal to 1.2%
],
"DIRECT_DEBIT_CREDIT_CARD" => [
"mdr_percent" => config("dana.mdr_percent.direct_debit_credit_card", 0.012),
// is equal to 1.2%
],
"DIRECT_DEBIT_DEBIT_CARD" => [
"mdr_percent" => config("dana.mdr_percent.direct_debit_debit_card", 0.012),
// is equal to 1.2%
],
"VIRTUAL_ACCOUNT" => [
"mdr_before_tax" => config("dana.mdr_before_tax.virtual_account", 2000),
// is equal to 2000 Rupiah
],
"ONLINE_CREDIT" => [
"mdr_percent" => config("dana.mdr_percent.online_credit", 0.012),
// is equal to 1.2%
]
];
}
/**
* Get calculation dana fee
*
Expand All @@ -47,18 +62,18 @@ class Calculation
*/
public function calculateMDR(int $payAmount, string $payMethod): array
{
$mdr = data_get(self::$FEES, "$payMethod.mdr_percent", null);
$mdr = data_get($this->fees(), "$payMethod.mdr_percent", null);

$mdrBeforeTax = ($mdr) ? $mdr * $payAmount : data_get(self::$FEES, "$payMethod.mdr_before_tax", null);
$taxValue = $mdrBeforeTax * self::$TAX;
$mdrBeforeTax = ($mdr) ? $mdr * $payAmount : data_get($this->fees(), "$payMethod.mdr_before_tax", null);
$taxValue = $mdrBeforeTax * $this->taxValue();
$mdrIncludeTax = $mdrBeforeTax + $taxValue;
$settleAmount = $payAmount - $mdrIncludeTax;

return [
"mdr_percent" => $mdr,
"mdr_before_tax" => $mdrBeforeTax,
"mdr_include_tax" => $mdrIncludeTax,
"tax_percent" => self::$TAX,
"tax_percent" => $this->taxValue(),
"tax" => $taxValue,
"payment_method" => $payMethod,
"settle_amount" => $settleAmount
Expand Down

0 comments on commit bde7d7f

Please sign in to comment.