From bde7d7f7a1e3c7423a1e0b3e3608c61a62c61020 Mon Sep 17 00:00:00 2001 From: k15 Date: Mon, 31 Jul 2023 11:55:19 +0700 Subject: [PATCH] fix : mdr callculation --- src/Helpers/Calculation.php | 87 ++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 36 deletions(-) diff --git a/src/Helpers/Calculation.php b/src/Helpers/Calculation.php index f682473..932d9a7 100644 --- a/src/Helpers/Calculation.php +++ b/src/Helpers/Calculation.php @@ -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 * @@ -47,10 +62,10 @@ 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; @@ -58,7 +73,7 @@ public function calculateMDR(int $payAmount, string $payMethod): array "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