|
@@ -77,6 +77,8 @@ class AlipayBatchPayServiceTest {
|
|
|
EnterpriseEntity ent = new EnterpriseEntity();
|
|
EnterpriseEntity ent = new EnterpriseEntity();
|
|
|
ent.setEnterpriseId("E100");
|
|
ent.setEnterpriseId("E100");
|
|
|
lenient().when(enterpriseMapper.selectByEnterpriseIdIgnoreTenant("E100")).thenReturn(ent);
|
|
lenient().when(enterpriseMapper.selectByEnterpriseIdIgnoreTenant("E100")).thenReturn(ent);
|
|
|
|
|
+ // 反馈轮 5: 制单预检 — 默认该付款方已有 AUTHED 授权记录(无授权用例单独 stub 0)
|
|
|
|
|
+ lenient().when(batchAuthorizeMapper.selectCount(any())).thenReturn(1L);
|
|
|
// 初始化 MyBatis-Plus lambda 元数据缓存,使 LambdaQueryWrapper.getSqlSegment() 可在无 Spring 上下文的单测中工作
|
|
// 初始化 MyBatis-Plus lambda 元数据缓存,使 LambdaQueryWrapper.getSqlSegment() 可在无 Spring 上下文的单测中工作
|
|
|
MybatisConfiguration configuration = new MybatisConfiguration();
|
|
MybatisConfiguration configuration = new MybatisConfiguration();
|
|
|
TableInfoHelper.initTableInfo(new MapperBuilderAssistant(configuration, ""), BatchOrderEntity.class);
|
|
TableInfoHelper.initTableInfo(new MapperBuilderAssistant(configuration, ""), BatchOrderEntity.class);
|
|
@@ -903,6 +905,66 @@ class AlipayBatchPayServiceTest {
|
|
|
assertEquals("E100", order.getValue().getPayerUid());
|
|
assertEquals("E100", order.getValue().getPayerUid());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void batchCreate_notAuthorized_throws() throws AlipayApiException {
|
|
|
|
|
+ // 反馈轮 5: 未完成授权不允许制单 — 该付款方无 AUTHED 授权记录 → 本地预检拦截,不调支付宝
|
|
|
|
|
+ when(batchAuthorizeMapper.selectCount(any())).thenReturn(0L);
|
|
|
|
|
+
|
|
|
|
|
+ BatchCreateDTO dto = new BatchCreateDTO();
|
|
|
|
|
+ dto.setEnterpriseId("E100");
|
|
|
|
|
+ dto.setOutBatchNo("B1");
|
|
|
|
|
+ dto.setOrderTitle("t");
|
|
|
|
|
+ BatchCreateDTO.BatchDetailDTO detail = new BatchCreateDTO.BatchDetailDTO();
|
|
|
|
|
+ detail.setOutBizNo("D1");
|
|
|
|
|
+ detail.setAmount(new BigDecimal("10"));
|
|
|
|
|
+ detail.setPayeeIdentity("a@b.com");
|
|
|
|
|
+ detail.setPayeeIdentityType("ALIPAY_LOGON_ID");
|
|
|
|
|
+ detail.setPayeeName("张三");
|
|
|
|
|
+ dto.setDetails(List.of(detail));
|
|
|
|
|
+
|
|
|
|
|
+ BusinessException ex = assertThrows(BusinessException.class, () -> service.batchCreate(dto));
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(400, ex.getCode());
|
|
|
|
|
+ assertTrue(ex.getMessage().contains("尚未完成制单授权"), ex.getMessage());
|
|
|
|
|
+ verify(alipayClient, never()).certificateExecute(any());
|
|
|
|
|
+ verify(batchOrderMapper, never()).insert(any());
|
|
|
|
|
+ verify(batchDetailMapper, never()).insert(any());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void batchCreate_authorizedIdentity_proceedsWithIdentityAsPayer() throws AlipayApiException {
|
|
|
|
|
+ // 反馈轮 4/5 协同: identity 有值时预检与付款方均用 identity(而非 enterprise_id)
|
|
|
|
|
+ EnterpriseEntity ent = new EnterpriseEntity();
|
|
|
|
|
+ ent.setEnterpriseId("E100");
|
|
|
|
|
+ ent.setIdentity("2088IDENTITY");
|
|
|
|
|
+ ent.setIdentityType("ALIPAY_OPEN_ID");
|
|
|
|
|
+ when(enterpriseMapper.selectByEnterpriseIdIgnoreTenant("E100")).thenReturn(ent);
|
|
|
|
|
+ AlipayFundBatchCreateResponse resp = new AlipayFundBatchCreateResponse();
|
|
|
|
|
+ resp.setOutBatchNo("B1");
|
|
|
|
|
+ when(alipayClient.certificateExecute(any(AlipayFundBatchCreateRequest.class))).thenReturn(resp);
|
|
|
|
|
+
|
|
|
|
|
+ BatchCreateDTO dto = new BatchCreateDTO();
|
|
|
|
|
+ dto.setEnterpriseId("E100");
|
|
|
|
|
+ dto.setOutBatchNo("B1");
|
|
|
|
|
+ dto.setOrderTitle("t");
|
|
|
|
|
+ BatchCreateDTO.BatchDetailDTO detail = new BatchCreateDTO.BatchDetailDTO();
|
|
|
|
|
+ detail.setOutBizNo("D1");
|
|
|
|
|
+ detail.setAmount(new BigDecimal("10"));
|
|
|
|
|
+ detail.setPayeeIdentity("a@b.com");
|
|
|
|
|
+ detail.setPayeeIdentityType("ALIPAY_LOGON_ID");
|
|
|
|
|
+ detail.setPayeeName("张三");
|
|
|
|
|
+ dto.setDetails(List.of(detail));
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> result = service.batchCreate(dto);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals("B1", result.get("out_batch_no"));
|
|
|
|
|
+ ArgumentCaptor<AlipayFundBatchCreateRequest> cap = ArgumentCaptor.forClass(AlipayFundBatchCreateRequest.class);
|
|
|
|
|
+ verify(alipayClient).certificateExecute(cap.capture());
|
|
|
|
|
+ AlipayFundBatchCreateModel m = (AlipayFundBatchCreateModel) cap.getValue().getBizModel();
|
|
|
|
|
+ assertEquals("2088IDENTITY", m.getPayerInfo().getIdentity());
|
|
|
|
|
+ assertEquals("ALIPAY_OPEN_ID", m.getPayerInfo().getIdentityType());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// ==================== M3: batchClose INIT 守卫 ====================
|
|
// ==================== M3: batchClose INIT 守卫 ====================
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|