| | |
| | | } |
| | | } |
| | | |
| | | return !"1001".equals(trxstatus); |
| | | return !("1001".equals(trxstatus) || StringUtils.isEmpty(trxstatus) |
| | | || "2008".equals(trxstatus) |
| | | || "2000".equals(trxstatus)); |
| | | } |
| | | |
| | | public boolean checkOrderStatusRefund(String outTradeNo) throws Exception { |
| | |
| | | VSP502:微信支付撤销 |
| | | VSP503:微信支付退款 |
| | | */ |
| | | if ("VSP502".equals(trxcode)|| "VSP503".equals(trxcode)){ |
| | | if ("VSP502".equals(trxcode) || "VSP503".equals(trxcode)){ |
| | | String trxid = params.get("trxid"); |
| | | updateOrderRefund(outTradeNo, trxid); |
| | | |
| | |
| | | } |
| | | |
| | | SybPayService service = new SybPayService(); |
| | | Map<String,String> map = service.close(null, orderId); |
| | | log.info("======关闭订单结果" + toJSONString(map)); |
| | | |
| | | String retcode = map.get("retcode"); |
| | | Map<String,String> params = service.query(orderId, up.getTransactionId()); |
| | | String retcode = params.get("retcode"); |
| | | if(!"SUCCESS".equals(retcode)){ |
| | | throw new ValidationException("取消订单失败: " + map.get("retmsg")); |
| | | throw new ValidationException("查询订单交易状态失败: " + params.get("retmsg")); |
| | | } |
| | | String trxstatus = params.get("trxstatus");//支付状态 |
| | | |
| | | if("1001".equals(trxstatus) || "3088".equals(trxstatus)){ |
| | | //3088-交易未支付(在查询时间区间内未成功支付,如已影响资金24小时内会做差错退款处理) |
| | | //1001:交易不存在 |
| | | //直接取消 |
| | | } else if (StringUtils.isEmpty(trxstatus) |
| | | || "2008".equals(trxstatus) |
| | | || "2000".equals(trxstatus)) { |
| | | String trxid = params.get("trxid"); |
| | | //2008或者2000 : 交易处理中,请查询交易,如果是实时交易(例如刷卡支付,交易撤销,退货),建议每隔一段时间(10秒)查询交易 |
| | | Map<String,String> map = service.close(trxid, orderId); |
| | | log.info("======关闭订单结果" + toJSONString(map)); |
| | | |
| | | retcode = map.get("retcode"); |
| | | if(!"SUCCESS".equals(retcode)){ |
| | | throw new ValidationException("调用通联关闭订单失败: " + map.get("retmsg")); |
| | | } |
| | | trxstatus = map.get("trxstatus"); |
| | | if(!"0000".equals(trxstatus)){ |
| | | throw new ValidationException("取消订单失败: " + map.get("errmsg")); |
| | | } |
| | | |
| | | } else { |
| | | throw new ValidationException("订单不可取消"); |
| | | } |
| | | |
| | | Order order = orderMapper.selectById(orderId); |
| | |
| | | throw new ValidationException("订单不可退款"); |
| | | } |
| | | |
| | | long trxamt = up.getPaymentAmount().longValue(); |
| | | long trxamt = prepareAmount(up.getPaymentAmount()); |
| | | String reqsn = orderId; |
| | | String oldtrxid = up.getTransactionId(); |
| | | String oldreqsn = null; |
| | | String oldreqsn = orderId; |
| | | |
| | | SybPayService service = new SybPayService(); |
| | | Map<String,String> map = service.cancel(trxamt, reqsn, oldtrxid, oldreqsn); |
| | | String retcode = map.get("retcode"); |
| | | if(!"SUCCESS".equals(retcode)){ |
| | | throw new ValidationException("订单退款失败: " + map.get("retmsg")); |
| | | throw new ValidationException("调用通联撤销接口失败: " + map.get("retmsg")); |
| | | } |
| | | |
| | | //这个不是订单状态,是通用的,如果是支付查询,代表就是订单状态,如果是退款代表的是退款状态 |
| | | String trxstatus = map.get("trxstatus"); |
| | | if(!"0000".equals(trxstatus)){ |
| | | log.error("通联撤销交易失败:" + map.get("errmsg")); |
| | | throw new ValidationException("订单退款交易失败:" + map.get("errmsg")); |
| | | } |
| | | |
| | | updateOrderRefund(orderId, oldtrxid); |
| | |
| | | throw new ValidationException("订单不可退款"); |
| | | } |
| | | |
| | | long trxamt = up.getPaymentAmount().longValue(); |
| | | long trxamt = prepareAmount(up.getPaymentAmount()); |
| | | String reqsn = orderId; |
| | | String oldtrxid = up.getTransactionId(); |
| | | String oldreqsn = null; |
| | | String oldreqsn = orderId; |
| | | |
| | | SybPayService service = new SybPayService(); |
| | | Map<String,String> map = service.refund(trxamt, reqsn, oldtrxid, oldreqsn); |
| | | String retcode = map.get("retcode"); |
| | | if(!"SUCCESS".equals(retcode)){ |
| | | throw new ValidationException("订单退款失败: " + map.get("retmsg")); |
| | | throw new ValidationException("调用通联退款失败: " + map.get("retmsg")); |
| | | } |
| | | |
| | | //这个不是订单状态,是通用的,如果是支付查询,代表就是订单状态,如果是退款代表的是退款状态 |
| | | String trxstatus = map.get("trxstatus"); |
| | | if(!"0000".equals(trxstatus)){ |
| | | throw new ValidationException("订单退款交易失败:" + map.get("errmsg")); |
| | | } |
| | | |
| | | updateOrderRefund(orderId, oldtrxid); |
| | |
| | | Map<String,String> map = service.refund(trxamt, reqsn, oldtrxid, oldreqsn); |
| | | String retcode = map.get("retcode"); |
| | | if(!"SUCCESS".equals(retcode)){ |
| | | throw new ValidationException("订单退款失败: " + map.get("retmsg")); |
| | | throw new ValidationException("调用通联退款失败: " + map.get("retmsg")); |
| | | } |
| | | |
| | | //这个不是订单状态,是通用的,如果是支付查询,代表就是订单状态,如果是退款代表的是退款状态 |
| | | String trxstatus = map.get("trxstatus"); |
| | | if(!"0000".equals(trxstatus)){ |
| | | throw new ValidationException("订单退款交易失败:" + map.get("errmsg")); |
| | | } |
| | | |
| | | re.setRequest(toJSONString(map)); |
| | | re.create(SecurityUtils.getUserId()); |
| | | |
| | | re.setStatus(retcode); |
| | | re.setNotification(retcode); |
| | | re.setNotifyTime(LocalDateTime.now()); |
| | | |
| | | orderRefundMapper.insert(re); |
| | | |
| | | return re.getId(); |