Yuansfer DOCS
Search…
JAVA SDK

Requirements

    JAVA >= 1.6

Installation

1
<dependency>
2
<groupId>com.yuansfer</groupId>
3
<artifactId>yuansfer-payment</artifactId>
4
<version>2.0.0</version>
5
</dependency>
Copied!

Example

1. Init

1
YuanpayConfig config = new YuanpayConfig();
2
config.setEnv(EnviromentEnums.SANDBOX.getValue())
3
.setMerchantNo("200043")
4
.setStoreNo("300014")
5
.setToken("5cbfb079f15b150122261c8537086d77a");
6
7
YuanpayClient client = new YuanpayV200Client(config);
Copied!

2. Online API

1
JSONArray goods = new JSONArray();
2
JSONObject item = new JSONObject();
3
item.put("goods_name","name1");
4
item.put("quantity", "1");
5
goods.add(item);
6
7
8
OnlineSecurepayRequest request = new OnlineSecurepayRequest();
9
request.setAmount("0.01")
10
.setCurrency("USD")
11
.setVendor("alipay")
12
.setTerminal("ONLINE")
13
.setReference(System.nanoTime()+"")
14
.setIpnUrl("http://zk-tys.yunkeguan.com/ttest/test")
15
.setCallbackUrl("http://zk-tys.yunkeguan.com/ttest/test2?status={status}")
16
.setDescription("testDescription")
17
.setNote("testNote")
18
.setGoodsInfo(goods.toString());
19
20
OnlineSecurepayResponse response = client.execute(request);
21
System.out.println(JSONObject.fromObject(response));
Copied!

3. Offline API

1
InstoreCreateTranQrcodeRequest request = new InstoreCreateTranQrcodeRequest();
2
3
request.setAmount("0.01")
4
.setCurrency("USD")
5
.setIpnUrl("http://zk-tys.yunkeguan.com/ttest/test")
6
.setNeedQrcode("true")
7
.setReference(System.nanoTime()+"")
8
.setTimeout(120)
9
.setVendor("alipay");
10
11
InstoreCreateTranQrcodeResponse response = client.execute(request);
12
System.out.println(JSONObject.fromObject(response));
Copied!

4. Mobile API

1
MobilePrepayRequest request = new MobilePrepayRequest();
2
request.setAmount("0.01")
3
.setCurrency("USD")
4
.setDescription("testDescription")
5
.setIpnUrl("http://zk-tys.yunkeguan.com/ttest/test")
6
.setNote("testNote")
7
.setReference(System.nanoTime()+"")
8
.setTerminal("APP")
9
.setVendor("alipay");
10
11
MobilePrepayResponse response = client.execute(request);
12
System.out.println(JSONObject.fromObject(response));
Copied!

5. Data API

1
RefundRequest request = new RefundRequest();
2
3
request.setAmount("0.01")
4
.setRefundReference("refund" + System.nanoTime())
5
.setTransactionNo("297553630266977466");
6
7
RefundResponse response = client.execute(request);
8
System.out.println(JSONObject.fromObject(response));
Copied!
Last modified 7mo ago