-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
♻️ [refactor] 송금 수수료 정책 추가, 코드 리팩토리 중
- Loading branch information
Showing
3 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...n/java/com/moin/remittance/application/service/v2/calculating/ExchangeRateCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.moin.remittance.application.service.v2.calculating; | ||
|
||
import com.moin.remittance.application.service.v2.calculating.policy.RemittanceFeePolicy; | ||
import java.math.BigDecimal; | ||
import java.math.RoundingMode; | ||
import java.util.Currency; | ||
|
||
public class ExchangeRateCalculator { | ||
public static double calculateExchangeRate(long amount, double currencyUnit, double basePrice, String currencyCode) { | ||
BigDecimal sourceAmount = new BigDecimal(amount); | ||
BigDecimal fee = RemittanceFeePolicy.calculateFee(amount); | ||
|
||
BigDecimal krw = sourceAmount.subtract(fee); | ||
BigDecimal targetCurrencyToKrwExchangeRate = new BigDecimal(basePrice / currencyUnit).setScale(4, RoundingMode.HALF_UP);// 소수점 넷째자리에서 반올림 | ||
System.out.println(targetCurrencyToKrwExchangeRate); | ||
|
||
int decimalPlaces = Currency.getInstance(currencyCode).getDefaultFractionDigits(); | ||
|
||
BigDecimal targetAmount = krw.divide(targetCurrencyToKrwExchangeRate, decimalPlaces, BigDecimal.ROUND_HALF_UP);// 자릿수 getDefaultFractionDigits | ||
|
||
return Double.parseDouble(String.valueOf(targetAmount)); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...va/com/moin/remittance/application/service/v2/calculating/policy/RemittanceFeePolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.moin.remittance.application.service.v2.calculating.policy; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.RoundingMode; | ||
|
||
public class RemittanceFeePolicy { | ||
|
||
public static BigDecimal calculateFee(long amount) { | ||
final double HUNDRED_EXCEED_FEE = 3000.0; | ||
final double HUNDRED_EXCEED_FEE_RATE = 0.1; | ||
|
||
final double HUNDRED_DOWN_FEE = 1000.0; | ||
final double HUNDRED_DOWN_FEE_RATE = 0.2; | ||
|
||
double sourceAmount = (double) amount; | ||
|
||
double targetFee = (sourceAmount > 0.0 && sourceAmount <= 1000000.0)? | ||
(sourceAmount * HUNDRED_DOWN_FEE_RATE) + HUNDRED_DOWN_FEE : (sourceAmount * HUNDRED_EXCEED_FEE_RATE) + HUNDRED_EXCEED_FEE; | ||
|
||
return new BigDecimal(targetFee).setScale(1, RoundingMode.HALF_UP); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters