|
@@ -84,6 +84,7 @@ public class ReceiptBillGatewayTest {
|
|
|
originalApiBase = AdapayCore.apiBase;
|
|
originalApiBase = AdapayCore.apiBase;
|
|
|
huifuServer = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
|
|
huifuServer = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
|
|
|
huifuServer.createContext("/", this::handleHuifu);
|
|
huifuServer.createContext("/", this::handleHuifu);
|
|
|
|
|
+ huifuServer.createContext("/v1/settle_accounts/balance", this::handleBasicBalance);
|
|
|
huifuServer.start();
|
|
huifuServer.start();
|
|
|
AdapayCore.apiBase = "http://127.0.0.1:" + huifuServer.getAddress().getPort();
|
|
AdapayCore.apiBase = "http://127.0.0.1:" + huifuServer.getAddress().getPort();
|
|
|
stored.setTenantId(101);
|
|
stored.setTenantId(101);
|
|
@@ -190,6 +191,38 @@ public class ReceiptBillGatewayTest {
|
|
|
return new BillHttp.Reply(200, envelope.getBytes(UTF_8));
|
|
return new BillHttp.Reply(200, envelope.getBytes(UTF_8));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void handleBasicBalance(HttpExchange exchange) throws IOException {
|
|
|
|
|
+ try {
|
|
|
|
|
+ requests++;
|
|
|
|
|
+ assertEquals("GET", exchange.getRequestMethod());
|
|
|
|
|
+ assertEquals("offline-api", exchange.getRequestHeaders().getFirst("Authorization"));
|
|
|
|
|
+ List<String> query = Arrays.asList(exchange.getRequestURI().getQuery().split("&"));
|
|
|
|
|
+ Collections.sort(query);
|
|
|
|
|
+ assertEquals(Arrays.asList("acct_type=01", "app_id=ada", "member_id=0"), query);
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ result.put("object", "account_balance");
|
|
|
|
|
+ result.put("status", "succeeded");
|
|
|
|
|
+ result.put("prod_mode", true);
|
|
|
|
|
+ result.put("app_id", "foreignBalance".equals(mode) ? "other" : "ada");
|
|
|
|
|
+ result.put("acct_balance", "90.00");
|
|
|
|
|
+ result.put("avl_balance", "zeroBalance".equals(mode) ? "0.00" : "12.34");
|
|
|
|
|
+ if ("missingBalance".equals(mode)) result.remove("avl_balance");
|
|
|
|
|
+ if ("invalidBalance".equals(mode)) result.put("avl_balance", "12.345");
|
|
|
|
|
+ String data = JSON.writeValueAsString(result);
|
|
|
|
|
+ Map<String, String> envelope = new HashMap<>();
|
|
|
|
|
+ envelope.put("data", data);
|
|
|
|
|
+ envelope.put("signature", sign("SHA1withRSA", "badBalanceSignature".equals(mode) ? "changed" : data));
|
|
|
|
|
+ byte[] response = JSON.writeValueAsBytes(envelope);
|
|
|
|
|
+ exchange.sendResponseHeaders(200, response.length);
|
|
|
|
|
+ exchange.getResponseBody().write(response);
|
|
|
|
|
+ } catch (Throwable failure) {
|
|
|
|
|
+ handlerFailure = failure;
|
|
|
|
|
+ exchange.sendResponseHeaders(500, -1);
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ exchange.close();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void handleHuifu(HttpExchange exchange) throws IOException {
|
|
private void handleHuifu(HttpExchange exchange) throws IOException {
|
|
|
int status = 200;
|
|
int status = 200;
|
|
|
byte[] response;
|
|
byte[] response;
|
|
@@ -269,10 +302,26 @@ public class ReceiptBillGatewayTest {
|
|
|
assertEquals(bill.getMessage(), "READY", bill.getStatus()); assertEquals(1, bill.getEntries().size());
|
|
assertEquals(bill.getMessage(), "READY", bill.getStatus()); assertEquals(1, bill.getEntries().size());
|
|
|
assertEquals("order", bill.getEntries().get(0).getOrderNo()); assertEquals(channel, bill.getEntries().get(0).getChannel());
|
|
assertEquals("order", bill.getEntries().get(0).getOrderNo()); assertEquals(channel, bill.getEntries().get(0).getChannel());
|
|
|
assertEquals(DATE, bill.getEntries().get(0).getTime()); assertEquals(new BigDecimal("12.34"), bill.getEntries().get(0).getAmount());
|
|
assertEquals(DATE, bill.getEntries().get(0).getTime()); assertEquals(new BigDecimal("12.34"), bill.getEntries().get(0).getAmount());
|
|
|
- if ("WECHAT".equals(channel)) { assertEquals(new BigDecimal("12.34"), bill.getAvailableBalance()); assertNotNull(bill.getBalanceTime()); }
|
|
|
|
|
|
|
+ if (!"ALIPAY".equals(channel)) { assertEquals(new BigDecimal("12.34"), bill.getAvailableBalance()); assertNotNull(bill.getBalanceTime()); }
|
|
|
else { assertNull(bill.getAvailableBalance()); assertNull(bill.getBalanceTime()); assertTrue(bill.getMessage().contains("可提现")); }
|
|
else { assertNull(bill.getAvailableBalance()); assertNull(bill.getBalanceTime()); assertTrue(bill.getMessage().contains("可提现")); }
|
|
|
}
|
|
}
|
|
|
- assertEquals(3, downloads); assertEquals(7, requests);
|
|
|
|
|
|
|
+ assertEquals(3, downloads); assertEquals(8, requests);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test public void huifuStoresZeroSnapshotAndKeepsReadyBillWhenBalanceIsUnavailable() throws Exception {
|
|
|
|
|
+ mode = "zeroBalance";
|
|
|
|
|
+ ReceiptBillDto bill = fetch("101", "HUIFU", DAY);
|
|
|
|
|
+ assertEquals(new BigDecimal("0.00"), bill.getAvailableBalance());
|
|
|
|
|
+ assertNotNull(bill.getBalanceTime());
|
|
|
|
|
+ for (String scenario : Arrays.asList("foreignBalance", "badBalanceSignature", "missingBalance", "invalidBalance")) {
|
|
|
|
|
+ mode = scenario;
|
|
|
|
|
+ bill = fetch("101", "HUIFU", DAY);
|
|
|
|
|
+ assertEquals(scenario, "READY", bill.getStatus());
|
|
|
|
|
+ assertEquals(1, bill.getEntries().size());
|
|
|
|
|
+ assertNull(scenario, bill.getAvailableBalance());
|
|
|
|
|
+ assertNull(scenario, bill.getBalanceTime());
|
|
|
|
|
+ assertTrue(bill.getMessage().contains("实时可提现余额不可用"));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test public void huifuUsesFinanceExportMerchantWithoutPaymentPlugin() throws Exception {
|
|
@Test public void huifuUsesFinanceExportMerchantWithoutPaymentPlugin() throws Exception {
|
|
@@ -310,6 +359,7 @@ public class ReceiptBillGatewayTest {
|
|
|
bill = fetch("101", "HUIFU", DAY);
|
|
bill = fetch("101", "HUIFU", DAY);
|
|
|
assertEquals("ERROR", bill.getStatus());
|
|
assertEquals("ERROR", bill.getStatus());
|
|
|
assertTrue(bill.getMessage(), bill.getMessage().contains("下载账单文件失败:HTTP 401,下载地址已过期(AccessDenied)"));
|
|
assertTrue(bill.getMessage(), bill.getMessage().contains("下载账单文件失败:HTTP 401,下载地址已过期(AccessDenied)"));
|
|
|
|
|
+ assertEquals(new BigDecimal("12.34"), bill.getAvailableBalance());
|
|
|
assertFalse(bill.getMessage().contains("private-file"));
|
|
assertFalse(bill.getMessage().contains("private-file"));
|
|
|
assertEquals(4, tickets);
|
|
assertEquals(4, tickets);
|
|
|
assertEquals(1, downloads);
|
|
assertEquals(1, downloads);
|
|
@@ -322,7 +372,7 @@ public class ReceiptBillGatewayTest {
|
|
|
assertEquals(1, downloads);
|
|
assertEquals(1, downloads);
|
|
|
assertEquals(1, bill.getEntries().size());
|
|
assertEquals(1, bill.getEntries().size());
|
|
|
assertEquals("order", bill.getEntries().get(0).getOrderNo());
|
|
assertEquals("order", bill.getEntries().get(0).getOrderNo());
|
|
|
- assertNull(bill.getAvailableBalance());
|
|
|
|
|
|
|
+ assertEquals(new BigDecimal("12.34"), bill.getAvailableBalance());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test public void huifuIdentifiesUnconfirmedDownloadDomainWithoutExposingSignedUrl() throws Exception {
|
|
@Test public void huifuIdentifiesUnconfirmedDownloadDomainWithoutExposingSignedUrl() throws Exception {
|