package com.tourguide.common.huifu.biz; import com.huifu.bspay.sdk.opps.core.net.BasePayRequest; import com.tourguide.common.huifu.properties.HuiFuProperties; import org.springframework.stereotype.Component; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.HashMap; import java.util.Map; @Component public class DouGongRefundBiz { private final HuiFuProperties huiFuProperties; public DouGongRefundBiz(HuiFuProperties huiFuProperties) { this.huiFuProperties = huiFuProperties; } public Map refund(String reqSeqId, BigDecimal amount, String orgReqDate, String orgReqSeqId) throws Exception { DouGongRequestSupport.initBasePay(huiFuProperties); Map data = new HashMap<>(); data.put("req_date", DouGongRequestSupport.todayForHuiFu()); data.put("req_seq_id", reqSeqId); data.put("huifu_id", huiFuProperties.getHuifuId()); data.put("ord_amt", amount.setScale(2, RoundingMode.HALF_UP).toString()); data.put("org_req_date", orgReqDate); data.put("org_req_seq_id", orgReqSeqId); data.put("notify_url", callbackBaseUrl() + "/base/dougong/refund-notify"); return BasePayRequest.requestBasePay("v4/trade/payment/scanpay/refund", data, null, false); } private String callbackBaseUrl() { String callbackPath = huiFuProperties.getCallbackPath().trim(); while (callbackPath.endsWith("/")) { callbackPath = callbackPath.substring(0, callbackPath.length() - 1); } return callbackPath; } }