liujie
2026-08-04 e9e42b621afdf6ac94f5327ee843b32b10a401b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.tourguide.modules.order.service;
 
import com.alibaba.fastjson.JSONObject;
import com.tourguide.common.huifu.properties.HuiFuProperties;
import com.tourguide.modules.order.payment.HuifuPaymentNotice;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
 
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
 
class HuifuPaymentCallbackServiceTest {
    @Test
    void successfulNoticeShouldDelegateVerifiedPaymentData() {
        HuiFuProperties properties = new HuiFuProperties();
        properties.setHuifuId("merchant-1");
        TourOrderPaymentService orderPaymentService = mock(TourOrderPaymentService.class);
        HuifuPaymentCallbackService service = new HuifuPaymentCallbackService(properties, orderPaymentService);
        JSONObject body = new JSONObject();
        body.put("req_seq_id", "DG001");
        body.put("huifu_id", "merchant-1");
        body.put("trans_stat", "S");
        body.put("trans_amt", "36.00");
        body.put("hf_seq_id", "HF001");
        body.put("end_time", "20260803160530");
 
        service.handle(body);
 
        ArgumentCaptor<HuifuPaymentNotice> captor = ArgumentCaptor.forClass(HuifuPaymentNotice.class);
        verify(orderPaymentService).confirm(captor.capture());
        HuifuPaymentNotice notice = captor.getValue();
        assertThat(notice.getReqSeqId()).isEqualTo("DG001");
        assertThat(notice.getAmount()).isEqualByComparingTo("36.00");
        assertThat(notice.getProviderTransactionId()).isEqualTo("HF001");
        assertThat(notice.getPaidAt()).isEqualTo("2026-08-03T16:05:30");
    }
 
    @Test
    void unsuccessfulNoticeShouldNotConfirmOrder() {
        HuiFuProperties properties = new HuiFuProperties();
        properties.setHuifuId("merchant-1");
        TourOrderPaymentService orderPaymentService = mock(TourOrderPaymentService.class);
        HuifuPaymentCallbackService service = new HuifuPaymentCallbackService(properties, orderPaymentService);
        JSONObject body = new JSONObject();
        body.put("req_seq_id", "DG001");
        body.put("huifu_id", "merchant-1");
        body.put("trans_stat", "F");
 
        service.handle(body);
 
        verify(orderPaymentService, never()).confirm(org.mockito.ArgumentMatchers.any());
    }
}