yeg
2026-09-12 6af5b0ccfcfdee62c53d2edcac97c92ede876692
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.talentcard.server.business.payment.huifu;
 
import static org.assertj.core.api.Assertions.assertThat;
 
import java.util.HashMap;
import java.util.Map;
 
import org.junit.jupiter.api.Test;
 
/**
 * A merchant onboarding application that the provider accepts for review must not be treated as a
 * failure. The provider answers such a submission with business return code {@code 90000000}
 * ("审核中") in the merchant onboarding return code table, which is neither {@code 00000000} nor a
 * rejection. Parsing it as a rejection would mark a submitted application, and its settlement bank
 * card, as rejected while the provider is still reviewing them.
 */
class HuifuOnboardingResultTests {
 
    @Test
    void anAcceptedApplicationUnderReviewIsNotAFailure() {
        Map<String, Object> response = response("90000000", "审核中");
 
        HuifuEnterpriseOnboardingGateway.Result enterprise = HuifuEnterpriseOnboardingGateway.Result.from(response);
        assertThat(enterprise.accepted()).isTrue();
        assertThat(enterprise.code()).isEqualTo("90000000");
        assertThat(enterprise.huifuId()).isEqualTo("6666000123123123");
        assertThat(enterprise.applyNo()).isEqualTo("2022012500073423");
        // The provider issues the card token only when the application is approved.
        assertThat(enterprise.tokenNo()).isEmpty();
 
        Map<String, Object> individualResponse = response("90000000", "审核中");
        HuifuIndividualOnboardingGateway.Result individual = HuifuIndividualOnboardingGateway.Result.from(individualResponse);
        assertThat(individual.accepted()).isTrue();
        assertThat(individual.huifuId()).isEqualTo("6666000123123123");
        assertThat(individual.tokenNo()).isEmpty();
    }
 
    @Test
    void anApprovedApplicationKeepsReturningTheMerchantNumberAndCardToken() {
        Map<String, Object> response = response("00000000", "成功");
        businessData(response).put("token_no", "10000713406");
 
        HuifuEnterpriseOnboardingGateway.Result result = HuifuEnterpriseOnboardingGateway.Result.from(response);
        assertThat(result.accepted()).isTrue();
        assertThat(result.huifuId()).isEqualTo("6666000123123123");
        assertThat(result.applyNo()).isEqualTo("2022012500073423");
        assertThat(result.tokenNo()).isEqualTo("10000713406");
    }
 
    @Test
    void aProviderRejectionAndAnUnknownOutcomeStayUnaccepted() {
        HuifuEnterpriseOnboardingGateway.Result frozenSubMerchant = HuifuEnterpriseOnboardingGateway.Result.from(response("20000006", "商户状态异常"));
        assertThat(frozenSubMerchant.accepted()).isFalse();
        assertThat(frozenSubMerchant.code()).isEqualTo("20000006");
        assertThat(frozenSubMerchant.message()).isEqualTo("商户状态异常");
 
        // A business response without a business code must never be read as acceptance.
        assertThat(HuifuIndividualOnboardingGateway.Result.from(response("", "")).accepted()).isFalse();
    }
 
    @Test
    void theBusinessCodeIsReadFromTheNestedDataObject() {
        // The mock tool and the SDK both nest the business fields under "data"; the outer gateway
        // code is 10000 and must not decide the business outcome.
        Map<String, Object> response = response("90000000", "审核中");
        Map<String, Object> envelope = new HashMap<>(response);
        envelope.put("resp_code", "10000");
        envelope.put("resp_desc", "成功调用");
 
        assertThat(HuifuEnterpriseOnboardingGateway.Result.from(envelope).accepted()).isTrue();
        assertThat(HuifuEnterpriseOnboardingGateway.Result.from(envelope).code()).isEqualTo("90000000");
    }
 
    private Map<String, Object> response(String code, String message) {
        Map<String, Object> response = new HashMap<>();
        response.put("data", businessData(code, message));
        return response;
    }
 
    private Map<String, Object> businessData(String code, String message) {
        Map<String, Object> data = new HashMap<>();
        data.put("resp_code", code);
        data.put("resp_desc", message);
        data.put("huifu_id", "6666000123123123");
        data.put("apply_no", "2022012500073423");
        return data;
    }
 
    /** The business fields live inside the nested {@code data} object of the provider response. */
    @SuppressWarnings("unchecked")
    private Map<String, Object> businessData(Map<String, Object> response) {
        return (Map<String, Object>) response.get("data");
    }
}