|
|
@@ -1,10 +1,12 @@
|
|
|
package com.zhongshu.card.server.core.service.pay;
|
|
|
|
|
|
+import com.github.microservice.core.util.JsonUtil;
|
|
|
import com.github.microservice.core.util.bean.BeanUtil;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
import com.github.microservice.pay.client.model.PayProductParameter;
|
|
|
import com.github.microservice.pay.client.model.ledger.TransactionLogModel;
|
|
|
import com.github.microservice.pay.client.model.ledger.TransferTransactionsModel;
|
|
|
+import com.github.microservice.pay.client.model.weChatMiniApp.WeChatMiniAppRefundRet;
|
|
|
import com.github.microservice.pay.client.ret.ResultState;
|
|
|
import com.github.microservice.pay.client.service.ledger.TransactionLogService;
|
|
|
import com.github.microservice.pay.client.service.product.MiniAppPayService;
|
|
|
@@ -101,7 +103,7 @@ public class WechatPayService extends SuperService {
|
|
|
return transactionLogService.transfer(transferModel);
|
|
|
}
|
|
|
|
|
|
- public com.github.microservice.pay.client.ret.ResultContent refund(WeChatRefundParam param){
|
|
|
+ public ResultContent<WeChatMiniAppRefundRet> refund(WeChatRefundParam param) throws Exception {
|
|
|
|
|
|
//根据项目id和支付渠道获取支付账户名
|
|
|
String accountName = orgPayAccountService.queryOgPayAccount(param.getOid(), PaymentType.WeChatPay);
|
|
|
@@ -111,6 +113,41 @@ public class WechatPayService extends SuperService {
|
|
|
payProductParameter.setMeta(meta);
|
|
|
payProductParameter.setAccountName(accountName);
|
|
|
|
|
|
- return miniAppPayService.refund(payProductParameter);
|
|
|
+ com.github.microservice.pay.client.ret.ResultContent<Object> refundResult = miniAppPayService.refund(payProductParameter);
|
|
|
+ if (refundResult.getState().equals(ResultState.Success)) {
|
|
|
+ WeChatMiniAppRefundRet weChatMiniAppRefundRet = JsonUtil.toObject(JsonUtil.toJson(refundResult.getContent()), WeChatMiniAppRefundRet.class);
|
|
|
+ return ResultContent.buildContent(weChatMiniAppRefundRet);
|
|
|
+ }
|
|
|
+ return ResultContent.buildFail(refundResult.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ public com.github.microservice.pay.client.ret.ResultContent<List<TransactionLogModel>> handleRefundTransactions(String projectOid, String oid, String userId, String refundOrderNo, BigDecimal refundTotal){
|
|
|
+ //获取机构待结算账户
|
|
|
+ PayAccount orgWaitSettle = payAccountService.getOrgChildren(projectOid, oid, PaymentChannelType.WaitSettle);
|
|
|
+ //获取用户余额支付子账
|
|
|
+ PayAccount userPayAccount = payAccountService.getUserChildren(projectOid, userId, PaymentChannelType.WeChatMiniPay);
|
|
|
+ //构建转账参数
|
|
|
+
|
|
|
+ TransferTransactionsModel transferModel = new TransferTransactionsModel();
|
|
|
+ //构建出账账户
|
|
|
+ TransferTransactionsModel.GeneralLedgerTransaction sourceTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
|
|
|
+ sourceTransaction.setGeneralLedgerId(orgWaitSettle.getLedgerId());
|
|
|
+ sourceTransaction.setOrderNumber(refundOrderNo);
|
|
|
+ sourceTransaction.setTransactionType(TransactionType.WeChatMiniAppPay);
|
|
|
+ sourceTransaction.setTransactionStatus(TransactionStatus.Success);
|
|
|
+ sourceTransaction.setAmount(refundTotal.negate().longValue());
|
|
|
+ sourceTransaction.setRemark("微信小程序支付");
|
|
|
+ sourceTransaction.setMeta(Map.of("paymentType",PaymentType.WeChat, "description","微信小程序支付", "summary", "微信小程序支付"));
|
|
|
+ transferModel.setSource(new TransferTransactionsModel.GeneralLedgerTransaction[]{sourceTransaction});
|
|
|
+
|
|
|
+ //构建入账账户
|
|
|
+ TransferTransactionsModel.GeneralLedgerTransaction destinationTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
|
|
|
+ destinationTransaction.setGeneralLedgerId(userPayAccount.getLedgerId());
|
|
|
+ destinationTransaction.setOrderNumber(refundOrderNo);
|
|
|
+ destinationTransaction.setAmount(refundTotal.longValue());
|
|
|
+ destinationTransaction.setRemark("微信小程序支付");
|
|
|
+ destinationTransaction.setMeta(Map.of("paymentType",PaymentType.WeChat, "description","微信小程序支付", "summary", "微信小程序支付"));
|
|
|
+ transferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{destinationTransaction});
|
|
|
+ return transactionLogService.transfer(transferModel);
|
|
|
}
|
|
|
}
|