支付
This commit is contained in:
@@ -6,8 +6,6 @@ import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 退款记录表
|
||||
*/
|
||||
@@ -46,13 +44,13 @@ public class PaymentRefundRecord extends BaseModel {
|
||||
|
||||
@Column
|
||||
@Comment("本次退款金额")
|
||||
@ColDefine(customType = "decimal")
|
||||
private BigDecimal refundAmount;
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer refundAmount;
|
||||
|
||||
@Column
|
||||
@Comment("原订单金额")
|
||||
@ColDefine(customType = "decimal")
|
||||
private BigDecimal total;
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer total;
|
||||
|
||||
@Column
|
||||
@Comment("交易返回数据")
|
||||
|
||||
@@ -6,8 +6,6 @@ import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 交易单表
|
||||
*/
|
||||
@@ -37,7 +35,7 @@ public class PaymentTransaction extends BaseModel {
|
||||
@Column
|
||||
@Comment("交易系统交易号")
|
||||
@ColDefine(type = ColType.VARCHAR,width = 128)
|
||||
private String tradingOrderNo;
|
||||
private String transactionId;
|
||||
|
||||
@Column
|
||||
@Comment("交易渠道")
|
||||
@@ -81,8 +79,8 @@ public class PaymentTransaction extends BaseModel {
|
||||
|
||||
@Column
|
||||
@Comment("交易金额")
|
||||
@ColDefine(customType = "decimal")
|
||||
private BigDecimal tradingAmount;
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer tradingAmount;
|
||||
|
||||
@Column
|
||||
@Comment("是否退款")
|
||||
@@ -91,8 +89,8 @@ public class PaymentTransaction extends BaseModel {
|
||||
|
||||
@Column
|
||||
@Comment("退款金额")
|
||||
@ColDefine(customType = "decimal")
|
||||
private BigDecimal refundAmount;
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer refundAmount;
|
||||
|
||||
@Column
|
||||
@Comment("订单描述")
|
||||
@@ -113,4 +111,9 @@ public class PaymentTransaction extends BaseModel {
|
||||
@Comment("交易返回数据")
|
||||
@ColDefine(type = ColType.MYSQL_JSON)
|
||||
private String resultJson;
|
||||
|
||||
@Column
|
||||
@Comment("交易名单的主键id")
|
||||
@ColDefine(type = ColType.MYSQL_JSON)
|
||||
private String memberPaymentInfoId;
|
||||
}
|
||||
|
||||
@@ -67,11 +67,4 @@ public interface WxPayCommonService {
|
||||
*/
|
||||
void refundNotify(HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
|
||||
/**
|
||||
* 获取openId
|
||||
* @param code 用户授权后的Code,可以获取用户信息
|
||||
* @return
|
||||
*/
|
||||
String getOpenId(String code);
|
||||
}
|
||||
|
||||
+45
-40
@@ -19,14 +19,11 @@ import com.ijpay.wxpay.WxPayApi;
|
||||
import com.ijpay.wxpay.enums.WxDomainEnum;
|
||||
import com.ijpay.wxpay.enums.v3.BasePayApiEnum;
|
||||
import com.ijpay.wxpay.model.v3.*;
|
||||
import io.v.nutz.base.payment.enums.TradingChannelEnum;
|
||||
import io.v.nutz.base.payment.enums.TradingStateEnum;
|
||||
import io.v.nutz.base.payment.enums.TradingTypeEnum;
|
||||
import io.v.nutz.base.payment.enums.WxPayResultCode;
|
||||
import io.v.nutz.base.payment.enums.*;
|
||||
import io.v.nutz.base.payment.model.PaymentRefundRecord;
|
||||
import io.v.nutz.base.payment.model.PaymentTransaction;
|
||||
import io.v.nutz.base.payment.wxpay.bean.WxPayV3Bean;
|
||||
import io.v.nutz.base.payment.wxpay.service.WxPayCommonService;
|
||||
import io.v.nutz.base.payment.wxpay.util.WeChatUtils;
|
||||
import io.v.nutz.base.payment.wxpay.vo.WxPayNeedParamVo;
|
||||
import io.v.nutz.base.result.Result;
|
||||
import io.v.nutz.sys.models.User;
|
||||
@@ -37,6 +34,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
@@ -46,13 +44,9 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -90,9 +84,9 @@ public class WxPayCommonServiceImpl implements WxPayCommonService {
|
||||
private final String payNotifyUrl = WX_PAY_V3_BEAN.getDomain().concat("/wxPay/notifyMessage");
|
||||
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
private Dao dao;
|
||||
@Inject
|
||||
private WeChatUtils weChatUtils;
|
||||
private SysUserService sysUserService;
|
||||
|
||||
/**
|
||||
* 微信扫描二维码支付
|
||||
@@ -294,12 +288,12 @@ public class WxPayCommonServiceImpl implements WxPayCommonService {
|
||||
// 获取缴费记录,并修改缴费结果
|
||||
PaymentTransaction transaction = sysUserService.dao().fetch(PaymentTransaction.class, Cnd.where("outTradeNo", "=", jsonResult.getStr("out_trade_no")));
|
||||
transaction.setTradingState(TradingStateEnum.PAY_SUCCESS.getTrdingStateName());
|
||||
transaction.setTradingOrderNo(jsonResult.getStr("transaction_id"));
|
||||
transaction.setTransactionId(jsonResult.getStr("transaction_id"));
|
||||
sysUserService.dao().update(transaction);
|
||||
|
||||
sysUserService.dao().update(MemberPaymentInfo.class,
|
||||
Chain.make("isPayment", true).add("paymentTime", DateUtil.date(jsonResult.getLong("success_time")))
|
||||
.add("paymentMoney", String.valueOf(transaction.getTradingOrderNo())),
|
||||
.add("paymentMoney", String.valueOf(transaction.getTransactionId())),
|
||||
Cnd.where("payId", "=", transaction.getId())
|
||||
);
|
||||
|
||||
@@ -332,24 +326,27 @@ public class WxPayCommonServiceImpl implements WxPayCommonService {
|
||||
@Override
|
||||
public Result refund(String transactionId, String outTradeNo) {
|
||||
try {
|
||||
// 查询商户订单
|
||||
PaymentTransaction transaction = sysUserService.dao().fetch(PaymentTransaction.class, Cnd.where("outTradeNo", "=", outTradeNo));
|
||||
Integer tradingAmount = transaction.getTradingAmount();
|
||||
String outRefundNo = PayKit.generateStr();
|
||||
log.info("商户退款单号: {}", outRefundNo);
|
||||
|
||||
List<RefundGoodsDetail> list = new ArrayList<>();
|
||||
RefundGoodsDetail refundGoodsDetail = new RefundGoodsDetail()
|
||||
.setMerchant_goods_id("123")
|
||||
.setGoods_name("IJPay 测试")
|
||||
.setUnit_price(1)
|
||||
.setRefund_amount(1)
|
||||
.setRefund_quantity(1);
|
||||
list.add(refundGoodsDetail);
|
||||
// List<RefundGoodsDetail> list = new ArrayList<>();
|
||||
// RefundGoodsDetail refundGoodsDetail = new RefundGoodsDetail()
|
||||
// .setMerchant_goods_id("123")
|
||||
// .setGoods_name("IJPay 测试")
|
||||
// .setUnit_price(1)
|
||||
// .setRefund_amount(1)
|
||||
// .setRefund_quantity(1);
|
||||
// list.add(refundGoodsDetail);
|
||||
|
||||
RefundModel refundModel = new RefundModel()
|
||||
.setOut_refund_no(outRefundNo)
|
||||
.setReason("IJPay 测试退款")
|
||||
.setNotify_url(WX_PAY_V3_BEAN.getDomain().concat("/v3/refundNotify"))
|
||||
.setAmount(new RefundAmount().setRefund(1).setTotal(1).setCurrency("CNY"))
|
||||
.setGoods_detail(list);
|
||||
.setReason("用户发起退款")
|
||||
.setNotify_url(payNotifyUrl)
|
||||
.setAmount(new RefundAmount().setRefund(tradingAmount).setTotal(tradingAmount).setCurrency("CNY"));
|
||||
// .setGoods_detail(list);
|
||||
|
||||
if (StrUtil.isNotEmpty(transactionId)) {
|
||||
refundModel.setTransaction_id(transactionId);
|
||||
@@ -376,7 +373,20 @@ public class WxPayCommonServiceImpl implements WxPayCommonService {
|
||||
log.info("退款响应 {}", response);
|
||||
|
||||
if (verifySignature) {
|
||||
return Result.success(response.getBody());
|
||||
// 用户发起退款,存一个退款记录
|
||||
PaymentRefundRecord record = new PaymentRefundRecord();
|
||||
record.setId(R.UU32());
|
||||
record.setPaymentTransactionId(transaction.getId());
|
||||
record.setOutRefundTradeNo(outRefundNo);
|
||||
record.setRefundNo(null);
|
||||
record.setRefundState(RefundStateEnum.REFUNDING.getRefundStateName());
|
||||
record.setRefundAmount(tradingAmount);
|
||||
record.setTotal(tradingAmount);
|
||||
record.setResultJson(response.getBody());
|
||||
sysUserService.dao().insert(record);
|
||||
|
||||
// 返回退款下单结果
|
||||
return Result.success().addData(response.getBody());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("系统异常", e);
|
||||
@@ -415,6 +425,12 @@ public class WxPayCommonServiceImpl implements WxPayCommonService {
|
||||
log.info("退款通知明文 {}", plainText);
|
||||
|
||||
if (StrUtil.isNotEmpty(plainText)) {
|
||||
// 取出明文,修改退款的结果
|
||||
JSONObject jsonObject = JSONUtil.parseObj(plainText);
|
||||
// 查询出退款记录
|
||||
PaymentRefundRecord record = dao.fetch(PaymentRefundRecord.class, Cnd.where("outRefundTradeNo", "=", jsonObject.getStr("out_refund_no")));
|
||||
record.setRefundNo(jsonObject.getStr("refund_id"));
|
||||
|
||||
response.setStatus(200);
|
||||
map.put("code", "SUCCESS");
|
||||
map.put("message", "SUCCESS");
|
||||
@@ -432,12 +448,6 @@ public class WxPayCommonServiceImpl implements WxPayCommonService {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getOpenId(String code) {
|
||||
JSONObject jsonObject = weChatUtils.getWebAccessTokenAndOpenid(code);
|
||||
return jsonObject.getStr("openid");
|
||||
}
|
||||
|
||||
/**
|
||||
* 公共方法,获取证书序列号
|
||||
* @return
|
||||
@@ -548,7 +558,7 @@ public class WxPayCommonServiceImpl implements WxPayCommonService {
|
||||
transaction.setId(R.UU32());
|
||||
transaction.setMchId(WX_PAY_V3_BEAN.getMchId());
|
||||
transaction.setOutTradeNo(outTradeNo);
|
||||
transaction.setTradingOrderNo(null);
|
||||
transaction.setTransactionId(null);
|
||||
transaction.setTradingChannel(TradingChannelEnum.WX_PAY.name());
|
||||
transaction.setTradingType(TradingTypeEnum.PAYMENT.name());
|
||||
transaction.setUserId(user.getId());
|
||||
@@ -558,19 +568,14 @@ public class WxPayCommonServiceImpl implements WxPayCommonService {
|
||||
transaction.setUnionName(user.getUnionname());
|
||||
transaction.setTradingState(TradingStateEnum.WAITING_FOR_PAYMENT.name());
|
||||
// 获取订单金额
|
||||
int total = paramVo.getAmount().getTotal();
|
||||
BigDecimal bigDecimalValue = new BigDecimal(String.valueOf(total));
|
||||
BigDecimal resultTotal = bigDecimalValue.divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP);
|
||||
transaction.setTradingAmount(resultTotal);
|
||||
transaction.setTradingAmount(paramVo.getAmount().getTotal());
|
||||
transaction.setIsRefund(false);
|
||||
transaction.setRefundAmount(null);
|
||||
transaction.setDescription(paramVo.getDescription());
|
||||
transaction.setAttach(paramVo.getAttach());
|
||||
transaction.setOpenId(null);
|
||||
transaction.setResultJson(result);
|
||||
transaction.setMemberPaymentInfoId(paramVo.getMemberPaymentInfoId());
|
||||
sysUserService.dao().insert(transaction);
|
||||
|
||||
sysUserService.dao().update(MemberPaymentInfo.class,
|
||||
Chain.make("payId", transaction.getId()), Cnd.where("id", "=", paramVo.getMemberPaymentInfoId()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user