chengkun
2025-06-05 4080b5997b38ca84b3b203c7101dcadb97b76925
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
package com.alipay.easysdk.payment.facetoface;
 
import com.alipay.easysdk.TestAccount;
import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.util.ResponseChecker;
import com.alipay.easysdk.payment.facetoface.models.AlipayTradePayResponse;
import com.alipay.easysdk.payment.facetoface.models.AlipayTradePrecreateResponse;
import org.junit.Before;
import org.junit.Test;
 
import java.util.UUID;
 
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
 
public class ClientTest {
 
    @Before
    public void setUp() {
        Factory.setOptions(TestAccount.Mini.CONFIG);
    }
 
    @Test
    public void testPay() throws Exception {
        AlipayTradePayResponse response = Factory.Payment.FaceToFace().pay("iPhone6 16G",
                "64628156-f784-4572-9540-485b7c91b850", "0.01", "289821051157962364");
 
        assertThat(ResponseChecker.success(response), is(false));
        assertThat(response.code, is("40004"));
        assertThat(response.msg, is("Business Failed"));
        assertThat(response.subCode, is("ACQ.PAYMENT_AUTH_CODE_INVALID"));
        assertThat(response.subMsg, is("支付失败,获取顾客账户信息失败,请顾客刷新付款码后重新收款,如再次收款失败,请联系管理员处理。[SOUNDWAVE_PARSER_FAIL]"));
        assertThat(response.httpBody, not(nullValue()));
    }
 
    @Test
    public void testPreCreate() throws Exception {
        AlipayTradePrecreateResponse response = Factory.Payment.FaceToFace().preCreate("iPhone6 16G",
                createNewAndReturnOutTradeNo(), "0.10");
 
        assertThat(ResponseChecker.success(response), is(true));
        assertThat(response.code, is("10000"));
        assertThat(response.msg, is("Success"));
        assertThat(response.subCode, is(nullValue()));
        assertThat(response.subMsg, is(nullValue()));
        assertThat(response.httpBody, not(nullValue()));
        assertThat(response.qrCode.startsWith("https://qr.alipay.com/"), is(true));
    }
 
    private String createNewAndReturnOutTradeNo() throws Exception {
        return Factory.Payment.Common().create("Iphone6 16G", UUID.randomUUID().toString(),
                "88.88", "2088002656718920").outTradeNo;
    }
}