PayRefundServiceImpl implements PayRefundService { @Override public CommonResult<PayRefundSubmitBO> submitRefund(PayRefundSubmitDTO payRefundSubmitDTO) { PayAppDO payAppDO = payAppService.validPayApp(payRefundSubmitDTO.getAppId()); PayTransactionDO payTransaction = payTransactionService.getTransaction(payRefundSubmitDTO.getAppId(), payRefundSubmitDTO.getOrderId()); if (payTransaction == null) { return ServiceExceptionUtil.error(PayErrorCodeEnum.PAY_TRANSACTION_NOT_FOUND.getCode()); } if (!PayTransactionStatusEnum.SUCCESS.getValue().equals(payTransaction.getStatus())) { return ServiceExceptionUtil.error(PayErrorCodeEnum.PAY_TRANSACTION_STATUS_IS_NOT_SUCCESS.getCode()); } if (payRefundSubmitDTO.getPrice() > payTransaction.getPrice() - payTransaction.getRefundTotal()) { return ServiceExceptionUtil.error(PayErrorCodeEnum.PAY_REFUND_PRICE_EXCEED.getCode()); } PayTransactionExtensionDO payTransactionExtension = payTransactionService.getPayTransactionExtension(payTransaction.getExtensionId()); if (payTransactionExtension == null) { return ServiceExceptionUtil.error(PayErrorCodeEnum.PAY_TRANSACTION_EXTENSION_NOT_FOUND.getCode()); } if (!PayTransactionStatusEnum.SUCCESS.getValue().equals(payTransactionExtension.getStatus())) { return ServiceExceptionUtil.error(PayErrorCodeEnum.PAY_TRANSACTION_EXTENSION_STATUS_IS_NOT_SUCCESS.getCode()); } PayRefundDO payRefundDO = PayRefundConvert.INSTANCE.convert(payRefundSubmitDTO) .setTransactionId(payTransaction.getId()) .setRefundCode(generateTransactionCode()) .setStatus(PayRefundStatus.WAITING.getValue()) .setNotifyUrl(payAppDO.getRefundNotifyUrl()) .setRefundChannel(payTransaction.getPayChannel()); payRefundDO.setCreateTime(new Date()); payRefundMapper.insert(payRefundDO); AbstractPaySDK paySDK = PaySDKFactory.getSDK(payTransaction.getPayChannel()); CommonResult<String> invokeResult = paySDK.submitRefund(payRefundDO, payTransactionExtension, null); if (invokeResult.isError()) { return CommonResult.error(invokeResult); } PayRefundSubmitBO payRefundSubmitBO = new PayRefundSubmitBO() .setId(payRefundDO.getId()); return CommonResult.success(payRefundSubmitBO); }  @Override CommonResult<PayRefundSubmitBO> submitRefund(PayRefundSubmitDTO payRefundSubmitDTO); @Override @Transactional CommonResult<Boolean> updateRefundSuccess(Integer payChannel, String params); @Override PayRefundPageBO getRefundPage(PayRefundPageDTO payRefundPageDTO);  }
@Test public void testSubmitRefund() { PayRefundSubmitDTO payRefundSubmitDTO = new PayRefundSubmitDTO() .setAppId("POd4RC6a") .setCreateIp("127.0.0.1") .setOrderId("13500000") .setOrderDescription("测试下退款") .setPrice(1); payRefundService.submitRefund(payRefundSubmitDTO); }