조민수 조민수 09-07
(test) nice pay update
@9f24ffeda75c735d416c2f3f5838b27cbcec42b8
src/main/java/itn/let/mjo/pay/service/impl/MjonPayServiceImpl.java
--- src/main/java/itn/let/mjo/pay/service/impl/MjonPayServiceImpl.java
+++ src/main/java/itn/let/mjo/pay/service/impl/MjonPayServiceImpl.java
@@ -167,8 +167,7 @@
 
     //nice - nicepay, sb - 세틀뱅크(가상계좌), kgm - kg 모바일 (핸드폰 결제)
     @Override
-    public MjonPayVO insertPay(MjonPayVO mjonPayVO, HttpServletRequest request, String p_payment_comp
-    ) throws Exception {
+    public MjonPayVO insertPay(MjonPayVO mjonPayVO, HttpServletRequest request, String p_payment_comp) throws Exception {
         System.out.println("START 카드결제");
         if (!isSupportedPaymentComp(p_payment_comp)) {
             mjonPayVO.setPaySuccess(false);
@@ -729,7 +728,7 @@
         result.setBankName((String) resultData.get("BankName"));
 
         boolean resultSuccess = isInnopaySuccess(responsePayMethod, resultCode);
-        boolean amountValid = amt != null && amt.equals(responseAmt);
+        boolean amountValid = isSamePaymentAmount(amt, responseAmt);
         boolean tidValid = txTid != null && txTid.equals(responseTid);
 
         result.setSuccess(resultSuccess && amountValid && tidValid);
@@ -737,6 +736,16 @@
         return result;
     }
 
+    // PG 응답 금액은 고정 길이로 앞에 0이 채워질 수 있다.
+    static boolean isSamePaymentAmount(String requestedAmount, String approvedAmount) {
+        if (requestedAmount == null || approvedAmount == null
+                || !requestedAmount.matches("[0-9]+") || !approvedAmount.matches("[0-9]+")) {
+            return false;
+        }
+        return new java.math.BigInteger(requestedAmount)
+                .equals(new java.math.BigInteger(approvedAmount));
+    }
+
     private String getMerchantKey() {
         return "33F49GnCMS1mFYlGXisbUDzVf2ATWCl9k3R++d5hDd3Frmuos/XLx8XhXpe+LDYAbpGKZYSwtlyyLOtS/8aD7A==";
     }
Add a comment
List