Skip to content

Commit 2bcb704

Browse files
committed
Royalty.createData() added
1 parent 28aa840 commit 2bcb704

5 files changed

Lines changed: 121 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 2.3.14
44

55
- 新增:settle_account.recipient extra 字段
6+
- 新增:Royalty.createData() 方法
67

78
---
89

src/main/java/com/pingplusplus/model/Royalty.java

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,59 @@ public static RoyaltyCollection list(Map<String, Object> params)
219219
*
220220
* @param params
221221
* @return RoyaltyCollection
222-
* @throws AuthenticationException
223-
* @throws InvalidRequestException
224-
* @throws APIConnectionException
225-
* @throws APIException
226-
* @throws ChannelException
227-
* @throws RateLimitException
222+
* @throws AuthenticationException 认证异常
223+
* @throws InvalidRequestException 错误请求
224+
* @throws APIConnectionException 连接异常
225+
* @throws APIException 系统异常
226+
* @throws ChannelException 渠道异常
227+
* @throws RateLimitException 请求超限
228228
*/
229229
public static RoyaltyCollection batchUpdate(Map<String, Object> params)
230230
throws AuthenticationException, InvalidRequestException,
231231
APIConnectionException, APIException, ChannelException, RateLimitException {
232232
return request(APIResource.RequestMethod.PUT, classURL(Royalty.class), params, RoyaltyCollection.class);
233233
}
234+
235+
/**
236+
* 创建分润
237+
*
238+
* @param orderId 订单 ID
239+
* @param params 分润信息参数
240+
* @return RoyaltyDataResult
241+
* @throws AuthenticationException 认证异常
242+
* @throws InvalidRequestException 错误请求
243+
* @throws APIConnectionException 连接异常
244+
* @throws APIException 系统异常
245+
* @throws ChannelException 渠道异常
246+
* @throws RateLimitException 请求超限
247+
*/
248+
public static RoyaltyDataResult createData(String orderId, Map<String, Object> params)
249+
throws AuthenticationException, InvalidRequestException,
250+
APIConnectionException, APIException, ChannelException, RateLimitException {
251+
return createData(orderId, params, null);
252+
}
253+
254+
/**
255+
* 创建分润
256+
*
257+
* @param orderId 订单 ID
258+
* @param params 分润信息参数
259+
* @param apiKey API Key
260+
* @return RoyaltyDataResult
261+
* @throws AuthenticationException 认证异常
262+
* @throws InvalidRequestException 错误请求
263+
* @throws APIConnectionException 连接异常
264+
* @throws APIException 系统异常
265+
* @throws ChannelException 渠道异常
266+
* @throws RateLimitException 请求超限
267+
*/
268+
public static RoyaltyDataResult createData(String orderId, Map<String, Object> params, String apiKey)
269+
throws AuthenticationException, InvalidRequestException,
270+
APIConnectionException, APIException, ChannelException, RateLimitException {
271+
return request(APIResource.RequestMethod.POST,
272+
String.format("%s/royalty_datas", instanceURL(Order.class, orderId)),
273+
apiKey,
274+
params,
275+
RoyaltyDataResult.class);
276+
}
234277
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.pingplusplus.model;
2+
3+
import com.pingplusplus.net.APIResource;
4+
5+
public class RoyaltyDataResult extends APIResource {
6+
String app;
7+
Boolean livemode;
8+
String order;
9+
Boolean succeeded;
10+
11+
public String getApp() {
12+
return app;
13+
}
14+
15+
public void setApp(String app) {
16+
this.app = app;
17+
}
18+
19+
public Boolean getLivemode() {
20+
return livemode;
21+
}
22+
23+
public void setLivemode(Boolean livemode) {
24+
this.livemode = livemode;
25+
}
26+
27+
public String getOrder() {
28+
return order;
29+
}
30+
31+
public void setOrder(String order) {
32+
this.order = order;
33+
}
34+
35+
public Boolean getSucceeded() {
36+
return succeeded;
37+
}
38+
39+
public void setSucceeded(Boolean succeeded) {
40+
this.succeeded = succeeded;
41+
}
42+
}

src/test/java/com/pingplusplus/order/RoyaltyTest.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.pingplusplus.order;
22

33
import com.pingplusplus.PingppTestBase;
4+
import com.pingplusplus.PingppTestData;
45
import com.pingplusplus.exception.*;
56
import com.pingplusplus.model.Royalty;
67
import com.pingplusplus.model.RoyaltyCollection;
8+
import com.pingplusplus.model.RoyaltyDataResult;
79
import org.junit.Test;
810

911
import java.util.ArrayList;
@@ -12,6 +14,7 @@
1214
import java.util.Map;
1315

1416
import static org.junit.Assert.assertEquals;
17+
import static org.junit.Assert.assertTrue;
1518

1619
public class RoyaltyTest extends PingppTestBase {
1720
/**
@@ -56,12 +59,36 @@ public void testRoyaltyBatchUpdate() throws RateLimitException,
5659
Map<String, Object> params = new HashMap<String, Object>();
5760
params.put("per_page", 3); // 可选
5861
params.put("page", 1); // 可选
59-
params.put("royalty_settlement", null); // 可选 关联的分润结算 ID
60-
params.put("royalty_transaction", null); // 可选 关联的分润结算明细 ID
62+
// params.put("royalty_settlement", null); // 可选 关联的分润结算 ID
63+
// params.put("royalty_transaction", null); // 可选 关联的分润结算明细 ID
6164
// 查询 royalty list 列表方法
6265
// 参数: params
6366
RoyaltyCollection objs = Royalty.list(params);
6467

6568
assertEquals("object should be list", "list", objs.getObject());
6669
}
70+
71+
/**
72+
* 创建分润
73+
*/
74+
@Test public void testRoyaltyDataCreate() throws RateLimitException,
75+
APIException, ChannelException, InvalidRequestException,
76+
APIConnectionException, AuthenticationException {
77+
Map<String, Object> params = new HashMap<String, Object>();
78+
params.put("app", PingppTestData.getAppID()); // 必传
79+
// params.put("charge", ""); // 条件可选,对于已经成功的 order 必传该字段
80+
List<Map<String, Object>> royaltyUsers = new ArrayList<>();
81+
Map<String, Object> user = new HashMap<String, Object>();
82+
user.put("user", "U201908030002");
83+
user.put("amount", 100);
84+
royaltyUsers.add(user);
85+
params.put("royalty_users", royaltyUsers); // 可选 分润的用户信息列表,默认为[],不分润。
86+
87+
String orderId = "2011909040000002881";
88+
RoyaltyDataResult result = Royalty.createData(orderId, params);
89+
90+
assertTrue("succeeded", result.getSucceeded());
91+
assertEquals("app should be the same", PingppTestData.getAppID(), result.getApp());
92+
assertEquals("order ID should returned as the same", orderId, result.getOrder());
93+
}
6794
}

0 commit comments

Comments
 (0)