Bläddra i källkod

fix: localize OMG payment attempt validation

qmj 2 veckor sedan
förälder
incheckning
619c822daf

+ 5 - 0
ruoyi-admin/src/main/resources/i18n/messages.properties

@@ -217,3 +217,8 @@ line.pay.refund.already.completed=LINE Pay 支付已经退款
 line.pay.order.completion.not.allowed=当前 LINE Pay 订单状态不允许完成
 line.pay.legacy.endpoint.disabled=LINE Pay 订单请使用专用订单操作接口
 rider.operation.role.required=只有骑手可以操作配送订单
+omg.payment.ddid.required=OMG 支付订单号不能为空
+omg.payment.merchantTradeNo.required=OMG MerchantTradeNo 不能为空
+omg.payment.storeId.required=OMG 门店 ID 不能为空
+omg.payment.merchantId.required=OMG 商户号不能为空
+omg.payment.amount.invalid=OMG 支付金额必须大于 0

+ 5 - 0
ruoyi-admin/src/main/resources/i18n/messages_en_US.properties

@@ -221,3 +221,8 @@ line.pay.refund.already.completed=The LINE Pay payment has already been refunded
 line.pay.order.completion.not.allowed=The current LINE Pay order state does not allow completion
 line.pay.legacy.endpoint.disabled=Use the dedicated order operation endpoint for LINE Pay orders
 rider.operation.role.required=Only riders can operate delivery orders
+omg.payment.ddid.required=OMG payment order number is required
+omg.payment.merchantTradeNo.required=OMG MerchantTradeNo is required
+omg.payment.storeId.required=OMG store id is required
+omg.payment.merchantId.required=OMG merchant id is required
+omg.payment.amount.invalid=OMG payment amount must be greater than 0

+ 5 - 0
ruoyi-admin/src/main/resources/i18n/messages_vi.properties

@@ -221,3 +221,8 @@ line.pay.refund.already.completed=Giao dịch LINE Pay đã được hoàn tiề
 line.pay.order.completion.not.allowed=Trạng thái đơn hàng LINE Pay hiện tại không cho phép hoàn tất
 line.pay.legacy.endpoint.disabled=Hãy sử dụng API thao tác đơn hàng chuyên dụng cho đơn LINE Pay
 rider.operation.role.required=Chỉ tài xế giao hàng mới có thể thao tác đơn giao hàng
+omg.payment.ddid.required=Mã đơn hàng thanh toán OMG là bắt buộc
+omg.payment.merchantTradeNo.required=OMG MerchantTradeNo là bắt buộc
+omg.payment.storeId.required=ID cửa hàng OMG là bắt buộc
+omg.payment.merchantId.required=Mã thương nhân OMG là bắt buộc
+omg.payment.amount.invalid=Số tiền thanh toán OMG phải lớn hơn 0

+ 5 - 0
ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties

@@ -221,3 +221,8 @@ line.pay.refund.already.completed=LINE Pay 支付已经退款
 line.pay.order.completion.not.allowed=当前 LINE Pay 订单状态不允许完成
 line.pay.legacy.endpoint.disabled=LINE Pay 订单请使用专用订单操作接口
 rider.operation.role.required=只有骑手可以操作配送订单
+omg.payment.ddid.required=OMG 支付订单号不能为空
+omg.payment.merchantTradeNo.required=OMG MerchantTradeNo 不能为空
+omg.payment.storeId.required=OMG 门店 ID 不能为空
+omg.payment.merchantId.required=OMG 商户号不能为空
+omg.payment.amount.invalid=OMG 支付金额必须大于 0

+ 5 - 0
ruoyi-admin/src/main/resources/i18n/messages_zh_TW.properties

@@ -221,3 +221,8 @@ line.pay.refund.already.completed=LINE Pay 支付已經退款
 line.pay.order.completion.not.allowed=目前 LINE Pay 訂單狀態不允許完成
 line.pay.legacy.endpoint.disabled=LINE Pay 訂單請使用專用訂單操作介面
 rider.operation.role.required=只有騎手可以操作配送訂單
+omg.payment.ddid.required=OMG 支付訂單號不能為空
+omg.payment.merchantTradeNo.required=OMG MerchantTradeNo 不能為空
+omg.payment.storeId.required=OMG 門店 ID 不能為空
+omg.payment.merchantId.required=OMG 商戶號不能為空
+omg.payment.amount.invalid=OMG 支付金額必須大於 0

+ 6 - 5
ruoyi-system/src/main/java/com/ruoyi/system/omgpay/service/impl/OmgPaymentAttemptServiceImpl.java

@@ -2,6 +2,7 @@ package com.ruoyi.system.omgpay.service.impl;
 
 import cn.hutool.core.util.StrUtil;
 import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.MessageUtils;
 import com.ruoyi.system.omgpay.domain.OmgPaymentAttempt;
 import com.ruoyi.system.omgpay.domain.OmgPaymentOrderSnapshot;
 import com.ruoyi.system.omgpay.mapper.OmgPaymentAttemptMapper;
@@ -54,19 +55,19 @@ public class OmgPaymentAttemptServiceImpl implements IOmgPaymentAttemptService {
     private static void validateCreatedFacts(String ddId, String merchantTradeNo, Long storeId,
                                              String merchantId, Integer amount) {
         if (StrUtil.isBlank(ddId)) {
-            throw new ServiceException("OMG payment ddId is required");
+            throw new ServiceException(MessageUtils.message("omg.payment.ddid.required"));
         }
         if (StrUtil.isBlank(merchantTradeNo)) {
-            throw new ServiceException("OMG payment merchantTradeNo is required");
+            throw new ServiceException(MessageUtils.message("omg.payment.merchantTradeNo.required"));
         }
         if (storeId == null) {
-            throw new ServiceException("OMG payment storeId is required");
+            throw new ServiceException(MessageUtils.message("omg.payment.storeId.required"));
         }
         if (StrUtil.isBlank(merchantId)) {
-            throw new ServiceException("OMG payment merchantId is required");
+            throw new ServiceException(MessageUtils.message("omg.payment.merchantId.required"));
         }
         if (amount == null || amount <= 0) {
-            throw new ServiceException("OMG payment amount must be positive");
+            throw new ServiceException(MessageUtils.message("omg.payment.amount.invalid"));
         }
     }
 }

+ 44 - 3
ruoyi-system/src/test/java/com/ruoyi/system/omgpay/service/OmgPaymentAttemptServiceTest.java

@@ -1,6 +1,7 @@
 package com.ruoyi.system.omgpay.service;
 
 import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.MessageUtils;
 import com.ruoyi.system.omgpay.domain.OmgPaymentAttempt;
 import com.ruoyi.system.omgpay.mapper.OmgPaymentAttemptMapper;
 import com.ruoyi.system.omgpay.service.impl.OmgPaymentAttemptServiceImpl;
@@ -14,6 +15,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mockStatic;
 import static org.mockito.Mockito.verifyNoInteractions;
 import static org.mockito.Mockito.when;
 
@@ -27,10 +29,33 @@ class OmgPaymentAttemptServiceTest {
     private OmgPaymentAttemptServiceImpl service;
 
     @Test
-    void createCreatedRejectsInvalidSnapshotsBeforeInsert() {
-        assertThrows(ServiceException.class,
+    void createCreatedRejectsBlankDdIdUsingMessageUtils() {
+        assertLocalizedValidationFailure("omg.payment.ddid.required",
+                () -> service.createCreated("   ", "OMG123", 10L, "M1", 100));
+    }
+
+    @Test
+    void createCreatedRejectsBlankMerchantTradeNoUsingMessageUtils() {
+        assertLocalizedValidationFailure("omg.payment.merchantTradeNo.required",
+                () -> service.createCreated("DD-1", "   ", 10L, "M1", 100));
+    }
+
+    @Test
+    void createCreatedRejectsNullStoreIdUsingMessageUtils() {
+        assertLocalizedValidationFailure("omg.payment.storeId.required",
+                () -> service.createCreated("DD-1", "OMG123", null, "M1", 100));
+    }
+
+    @Test
+    void createCreatedRejectsBlankMerchantIdUsingMessageUtils() {
+        assertLocalizedValidationFailure("omg.payment.merchantId.required",
+                () -> service.createCreated("DD-1", "OMG123", 10L, "   ", 100));
+    }
+
+    @Test
+    void createCreatedRejectsNonPositiveAmountUsingMessageUtils() {
+        assertLocalizedValidationFailure("omg.payment.amount.invalid",
                 () -> service.createCreated("DD-1", "OMG123", 10L, "M1", 0));
-        verifyNoInteractions(mapper);
     }
 
     @Test
@@ -47,4 +72,20 @@ class OmgPaymentAttemptServiceTest {
         assertEquals(7L, row.getId());
         assertNull(row.getActiveDdId());
     }
+
+    private void assertLocalizedValidationFailure(String key, ThrowingRunnable runnable) {
+        try (var messages = mockStatic(MessageUtils.class)) {
+            messages.when(() -> MessageUtils.message(key)).thenReturn("localized-" + key);
+
+            ServiceException exception = assertThrows(ServiceException.class, runnable::run);
+
+            assertEquals("localized-" + key, exception.getMessage());
+            verifyNoInteractions(mapper);
+        }
+    }
+
+    @FunctionalInterface
+    private interface ThrowingRunnable {
+        void run();
+    }
 }