| | |
| | | |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.utils.ID; |
| | | import com.wechat.pay.java.core.notification.RequestParam; |
| | | import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest; |
| | | import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse; |
| | | import com.wechat.pay.java.service.refund.model.AmountReq; |
| | | import com.wechat.pay.java.service.refund.model.CreateRequest; |
| | | import com.wechat.pay.java.service.refund.model.QueryByOutRefundNoRequest; |
| | | import com.wechat.pay.java.service.refund.model.Refund; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | com.wechat.pay.java.service.payments.jsapi.model.Amount amount = |
| | | new com.wechat.pay.java.service.payments.jsapi.model.Amount(); |
| | | amount.setTotal(1);//totalCents.intValue()); |
| | | amount.setTotal(totalCents.intValue()); |
| | | amount.setCurrency("CNY"); |
| | | request.setAmount(amount); |
| | | |
| | |
| | | /** |
| | | * V3退款 |
| | | * |
| | | * @param outRefundNo 商户退款单号(由调用方生成) |
| | | * @param outTradeNo 商户订单号 |
| | | * @param totalCents 原订单金额(分) |
| | | * @param refundCents 退款金额(分) |
| | |
| | | * @param notifyUrl 退款回调地址 |
| | | * @return Refund 退款结果(包含 outRefundNo、status 等) |
| | | */ |
| | | public Refund refund(String outTradeNo, Long totalCents, Long refundCents, |
| | | public Refund refund(String outRefundNo, String outTradeNo, Long totalCents, Long refundCents, |
| | | String reason, String notifyUrl) { |
| | | if (WxMiniConfig.v3RefundService == null) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "微信支付V3未初始化"); |
| | | } |
| | | try { |
| | | String outRefundNo = ID.nextGUID(); |
| | | |
| | | CreateRequest request = new CreateRequest(); |
| | | request.setOutTradeNo(outTradeNo); |
| | | request.setOutRefundNo(outRefundNo); |
| | |
| | | request.setNotifyUrl(notifyUrl); |
| | | |
| | | AmountReq amount = new AmountReq(); |
| | | amount.setRefund(1L);//refundCents); |
| | | amount.setTotal(1L);//totalCents); |
| | | amount.setRefund(refundCents); |
| | | amount.setTotal(totalCents); |
| | | amount.setCurrency("CNY"); |
| | | request.setAmount(amount); |
| | | |
| | |
| | | return result; |
| | | } catch (Exception e) { |
| | | log.error("微信支付V3退款失败: {}", e.getMessage(), e); |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "退款失败:" + e.getMessage()); |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "退款失败:请联系管理员"); |
| | | } |
| | | } |
| | | |
| | |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "退款回调验签失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询单笔退款 |
| | | * |
| | | * @param outRefundNo 商户退款单号 |
| | | * @return Refund 退款结果 |
| | | */ |
| | | public Refund queryRefund(String outRefundNo) { |
| | | if (WxMiniConfig.v3RefundService == null) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "微信支付V3未初始化"); |
| | | } |
| | | try { |
| | | QueryByOutRefundNoRequest request = new QueryByOutRefundNoRequest(); |
| | | request.setOutRefundNo(outRefundNo); |
| | | Refund result = WxMiniConfig.v3RefundService.queryByOutRefundNo(request); |
| | | log.info("微信支付V3查询单笔退款, outRefundNo={}, status={}", outRefundNo, result.getStatus()); |
| | | return result; |
| | | } catch (Exception e) { |
| | | log.error("微信支付V3查询退款失败: {}", e.getMessage(), e); |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "查询退款失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | } |