|
|
|
@@ -478,7 +478,14 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
public ResultData createMicroPayOrder(WxMerchantBUser user, WxPayOrder record, EnumPayWay payWay,PayExtraParam params) { |
|
|
|
final IdWorker idworker = IdWorker.get(); |
|
|
|
|
|
|
|
WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(user.getTenantId(),payWay.getPlat()); |
|
|
|
WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(record.getTenantId(), payWay.getPlat()); |
|
|
|
if(cAppInfo == null){ |
|
|
|
throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); |
|
|
|
} |
|
|
|
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); |
|
|
|
if(payAccount == null){ |
|
|
|
throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); |
|
|
|
} |
|
|
|
if (null == params) { |
|
|
|
params = new PayExtraParam(); |
|
|
|
} |
|
|
|
@@ -488,7 +495,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
try { |
|
|
|
// 1. check 订单 |
|
|
|
OrderAdapterService orderAdapterService = orderFactory.getOrderAdapterService(EnumComposeOrder.SINGLE.getCode()); |
|
|
|
WxComposeOrder composeOrder = orderAdapterService.getComposeOrder(record.getOrderId(), appInfo.getTenantId()); |
|
|
|
WxComposeOrder composeOrder = orderAdapterService.getComposeOrder(record.getOrderId(), cAppInfo.getTenantId()); |
|
|
|
WxOrder singleOrder = composeOrder.getSingleOrder(); |
|
|
|
if (composeOrder == null) { |
|
|
|
logger.error("pay order, order not allow, repaymentReq: " + record.toString() + ", payWay: " + payWay.toString()); |
|
|
|
@@ -506,7 +513,6 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
if (order.getPaymentType() != EnumPayType.PAY_PAYMENT.getCode()) { |
|
|
|
return new ResultData(ErrorCode.PAY_ORDER_IS_NOT_PAYMENT); |
|
|
|
} |
|
|
|
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); |
|
|
|
PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); |
|
|
|
EnumPayShare paySHareEnum = EnumPayShare.getEnum(payAccount.getShare()); |
|
|
|
if (paySHareEnum != null) { |
|
|
|
@@ -566,9 +572,9 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
|
|
|
|
logger.debug("wxPayRecord md5 before:"+record.toString()); |
|
|
|
String beforemd5 = HashUtil.md5(record.toString()); |
|
|
|
List<WxOrder> orderList = orderAdapterService.getChildOrders(composeOrder, appInfo.getTenantId()); |
|
|
|
List<WxOrder> orderList = orderAdapterService.getChildOrders(composeOrder, cAppInfo.getTenantId()); |
|
|
|
PayAdapterResult payResult = payServiceFactory.getPayAdapterService(payWay.getCode(),payAccount.getPayVersion()).pay(payAccount, record,composeOrder,orderList, |
|
|
|
"付款码支付",isShare,appInfo, currentDate, params); |
|
|
|
"付款码支付",isShare,cAppInfo, currentDate, params); |
|
|
|
String aftermd5 = HashUtil.md5(record.toString()); |
|
|
|
if (beforemd5.equals(aftermd5)) { |
|
|
|
logger.error("支付方式["+payWay.getCode()+"]支付接口【pay】过程中 WxPayOrder 未做更新.record:"+record.toString()); |
|
|
|
@@ -578,7 +584,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
//支付失败,更新record,支付成功,则调用 |
|
|
|
if (payResult.isSuccess()) { |
|
|
|
try { |
|
|
|
handleMicroOrderPaySuccess(payResult.getData(), payResult.getTransactionId(),payWay,payAccount,record,user, appInfo, params); |
|
|
|
handleMicroOrderPaySuccess(payResult.getData(), payResult.getTransactionId(),payWay,payAccount,record,user, cAppInfo, params); |
|
|
|
}catch(Exception e) { |
|
|
|
logger.error("do handleMicroOrderPaySuccess() error.",e); |
|
|
|
try { |
|
|
|
@@ -630,10 +636,16 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), "payOrder not found"); |
|
|
|
} |
|
|
|
|
|
|
|
WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(record.getTenantId(),payWay.getPlat()); |
|
|
|
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); |
|
|
|
WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(record.getTenantId(), payWay.getPlat()); |
|
|
|
if(cAppInfo == null){ |
|
|
|
throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); |
|
|
|
} |
|
|
|
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); |
|
|
|
if(payAccount == null){ |
|
|
|
throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); |
|
|
|
} |
|
|
|
PayAdapterService payService = payServiceFactory.getPayAdapterService(payWay.getCode(),payAccount.getPayVersion()); |
|
|
|
PayQueryAdapterResult apiResult = payService.queryPayStatus(record, appInfo, payAccount); |
|
|
|
PayQueryAdapterResult apiResult = payService.queryPayStatus(record, cAppInfo, payAccount); |
|
|
|
int status = payServiceFactory.getPayAdapterService(payWay.getCode(),payAccount.getPayVersion()).queryPayStatus(apiResult, record.getPayOrderNo()); |
|
|
|
boolean isSuccess = true; |
|
|
|
String msg = ""; |
|
|
|
@@ -655,7 +667,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
handleOrderPaySuccess(record, apiResult.getTransactionId()); |
|
|
|
//C端被动支付 |
|
|
|
}else if (payService instanceof CPassivePayService) { |
|
|
|
handleMicroOrderPaySuccess(apiResult.getData(),apiResult.getTransactionId(),payWay,payAccount, record,user,appInfo,null); |
|
|
|
handleMicroOrderPaySuccess(apiResult.getData(),apiResult.getTransactionId(),payWay,payAccount, record,user,cAppInfo,null); |
|
|
|
} |
|
|
|
return new ResultData(Result.SUCCESS, "success",apiResult.getData()); |
|
|
|
}else if (status == EnumPayStatus.PAY_STATUS_ORDER_NOT_EXISTS.getCode().intValue()) { |
|
|
|
@@ -736,11 +748,17 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public ResultData payOrderReverse(WxPayOrder record) { |
|
|
|
|
|
|
|
WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(record.getTenantId(),EnumPayWay.getEnum(record.getPayVendor()).getPlat()); |
|
|
|
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); |
|
|
|
EnumAppPlat plat = EnumPayWay.getEnum(record.getPayVendor()).getPlat(); |
|
|
|
WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(record.getTenantId(),plat); |
|
|
|
if(cAppInfo == null){ |
|
|
|
throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); |
|
|
|
} |
|
|
|
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); |
|
|
|
if(payAccount == null){ |
|
|
|
throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); |
|
|
|
} |
|
|
|
try { |
|
|
|
PayAdapterResult result = payServiceFactory.getPayAdapterService(record.getPayVendor(),record.getPayVersion()).payOrderReverse(appInfo, record, payAccount); |
|
|
|
PayAdapterResult result = payServiceFactory.getPayAdapterService(record.getPayVendor(),record.getPayVersion()).payOrderReverse(cAppInfo, record, payAccount); |
|
|
|
if (result.isSuccess()) { |
|
|
|
record.setPayOrderStatus(EnumPayStatus.PAY_STATUS_REVERSE.getCode()); |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
@@ -1010,8 +1028,14 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public PayQueryAdapterResult ttorderQuery(TenantEntity tenantInfo, Long id) { |
|
|
|
WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(tenantInfo.getTenantId(),EnumAppPlat.TOUTIAO); |
|
|
|
WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(tenantInfo.getTenantId(), EnumAppPlat.TOUTIAO); |
|
|
|
if(appInfo == null){ |
|
|
|
throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); |
|
|
|
} |
|
|
|
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); |
|
|
|
if(payAccount == null){ |
|
|
|
throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); |
|
|
|
} |
|
|
|
WxPayOrder payOrder = new WxPayOrder(); |
|
|
|
payOrder.setPayOrderNo(id.toString()); |
|
|
|
try { |
|
|
|
@@ -1301,12 +1325,19 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
// 有价券 |
|
|
|
if (EnumPayStatus.PAY_STATUS_FAIL.getCode() == status) { |
|
|
|
// 1. get appinfo |
|
|
|
WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(record.getTenantId(),EnumPayWay.getEnum(record.getPayVendor()).getPlat()); |
|
|
|
EnumAppPlat plat = EnumPayWay.getEnum(record.getPayVendor()).getPlat(); |
|
|
|
WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(record.getTenantId(),plat); |
|
|
|
if(cAppInfo == null){ |
|
|
|
throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); |
|
|
|
} |
|
|
|
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); |
|
|
|
if(payAccount == null){ |
|
|
|
throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); |
|
|
|
} |
|
|
|
// 前端支付取消, |
|
|
|
// 回调未返回,主动检查支付订单状态 |
|
|
|
try { |
|
|
|
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); |
|
|
|
int payStatus = payServiceFactory.getPayAdapterService(record.getPayVendor(),payAccount.getPayVersion()).queryPayStatusCode(record, appInfo, payAccount); |
|
|
|
int payStatus = payServiceFactory.getPayAdapterService(record.getPayVendor(),payAccount.getPayVersion()).queryPayStatusCode(record, cAppInfo, payAccount); |
|
|
|
if (payStatus!=EnumPayStatus.PAY_STATUS_SUCCESS.getCode().intValue() && payStatus!=EnumPayStatus.PAY_STATUS_WAIT.getCode().intValue()) { |
|
|
|
// 支付订单未成功,返回异常 |
|
|
|
record.setPayOrderStatus(EnumPayStatus.PAY_STATUS_FAIL.getCode()); |
|
|
|
|