Authored by tanling

支付方式增加花呗和花呗分期

package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.OrdersPayHbfq;
public interface OrdersPayHbfqMapper {
int deleteByPrimaryKey(String fqTradeNo);
int insert(OrdersPayHbfq record);
int insertSelective(OrdersPayHbfq record);
OrdersPayHbfq selectByPrimaryKey(String fqTradeNo);
int updateByPrimaryKeySelective(OrdersPayHbfq record);
int updateByPrimaryKey(OrdersPayHbfq record);
int insertOnDuplicateUpdate(OrdersPayHbfq record);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.order.model;
public class OrdersPayHbfq {
private String fqTradeNo;
private String payOrderCode;
private Integer uid;
private Integer createTime;
private Integer updateTime;
public String getFqTradeNo() {
return fqTradeNo;
}
public void setFqTradeNo(String fqTradeNo) {
this.fqTradeNo = fqTradeNo == null ? null : fqTradeNo.trim();
}
public String getPayOrderCode() {
return payOrderCode;
}
public void setPayOrderCode(String payOrderCode) {
this.payOrderCode = payOrderCode == null ? null : payOrderCode.trim();
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yohoufo.dal.order.OrdersPayHbfqMapper" >
<resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.OrdersPayHbfq" >
<id column="fq_trade_no" property="fqTradeNo" jdbcType="VARCHAR" />
<result column="pay_order_code" property="payOrderCode" jdbcType="VARCHAR" />
<result column="uid" property="uid" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
fq_trade_no, pay_order_code, uid, create_time, update_time
</sql>
<insert id="insertOnDuplicateUpdate" parameterType="com.yoho.yhorder.dal.model.OrdersPayHbfq" >
insert into orders_pay_hbfq (fq_trade_no, pay_order_code, uid, create_time)
values(#{fqTradeNo,jdbcType=VARCHAR}, #{payOrderCode,jdbcType=VARCHAR}, #{uid,jdbcType=INTEGER}, UNIX_TIMESTAMP())
on duplicate key update update_time = UNIX_TIMESTAMP()
</insert>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from orders_pay_hbfq
where fq_trade_no = #{fqTradeNo,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
delete from orders_pay_hbfq
where fq_trade_no = #{fqTradeNo,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.yohoufo.dal.order.model.OrdersPayHbfq" >
insert into orders_pay_hbfq (fq_trade_no, pay_order_code, uid,
create_time, update_time)
values (#{fqTradeNo,jdbcType=VARCHAR}, #{payOrderCode,jdbcType=VARCHAR}, #{uid,jdbcType=INTEGER},
#{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yohoufo.dal.order.model.OrdersPayHbfq" >
insert into orders_pay_hbfq
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="fqTradeNo != null" >
fq_trade_no,
</if>
<if test="payOrderCode != null" >
pay_order_code,
</if>
<if test="uid != null" >
uid,
</if>
<if test="createTime != null" >
create_time,
</if>
<if test="updateTime != null" >
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="fqTradeNo != null" >
#{fqTradeNo,jdbcType=VARCHAR},
</if>
<if test="payOrderCode != null" >
#{payOrderCode,jdbcType=VARCHAR},
</if>
<if test="uid != null" >
#{uid,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=INTEGER},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.OrdersPayHbfq" >
update orders_pay_hbfq
<set >
<if test="payOrderCode != null" >
pay_order_code = #{payOrderCode,jdbcType=VARCHAR},
</if>
<if test="uid != null" >
uid = #{uid,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
</if>
<if test="updateTime != null" >
update_time = #{updateTime,jdbcType=INTEGER},
</if>
</set>
where fq_trade_no = #{fqTradeNo,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.order.model.OrdersPayHbfq" >
update orders_pay_hbfq
set pay_order_code = #{payOrderCode,jdbcType=VARCHAR},
uid = #{uid,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER}
where fq_trade_no = #{fqTradeNo,jdbcType=VARCHAR}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -71,9 +71,11 @@ public class PaymentController {
public ApiResponse pay(@RequestParam(name = "uid") int uid,
@RequestParam(name = "orderCode") long orderCode,
@RequestParam(name = "payment") int payment,
@RequestParam(name = "openid", required = false)String openid){
@RequestParam(name = "openid", required = false)String openid,
@RequestParam(name = "hbfqNums", required = false) int hbfqNums){
PaymentRequest request = PaymentRequest.builder().uid(uid).orderCode(orderCode).payment(payment)
.hbfqNums(hbfqNums)
.openid(openid).build();
logger.info("method com.yohoufo.order.controller.PaymentController.pay in, request is {}", request);
... ...
... ... @@ -24,6 +24,11 @@ public class PaymentRequest {
private int skup;
/**
* 花呗分期期数
*/
private int hbfqNums;
/**
* 退款金额
*/
private double refundAmount;
... ...
... ... @@ -6,11 +6,15 @@ import com.google.common.base.Splitter;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.common.Payment;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.common.utils.HttpClient;
import com.yohoufo.common.utils.MD5Utils;
import com.yohoufo.common.utils.RSAUtils;
import com.yohoufo.common.utils.WXUtil;
import com.yohoufo.dal.order.OrdersPayHbfqMapper;
import com.yohoufo.dal.order.model.OrdersPayHbfq;
import com.yohoufo.order.common.HbfqEnum;
import com.yohoufo.order.config.AlipayConfig;
import com.yohoufo.order.constants.RefundContant;
import com.yohoufo.order.model.*;
... ... @@ -59,6 +63,10 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
}
@Autowired
private OrdersPayHbfqMapper ordersPayHbfqDao;
@Value("${alipay.notifyurl}")
private String notifyURL;
... ... @@ -124,7 +132,8 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
public JSONObject prepayRequest(OrderInfo orderInfo) {
String orderCode = String.valueOf(orderInfo.getOrderCode());
Map<String, String> queryParams = buildOpenApiPayParams(orderCode, orderInfo.getAmount(), orderInfo.getPayExpireTime());
Map<String, String> queryParams = buildOpenApiPayParams(orderCode, orderInfo.getAmount(),
orderInfo.getPayExpireTime(),orderInfo.getPayment(), orderInfo.getHbfqNums(), orderInfo.getUid());
StringBuilder res = new StringBuilder();
for (String key : queryParams.keySet()){
res.append(key);
... ... @@ -414,7 +423,8 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
* @param payExpireTime
* @return
*/
private Map<String, String> buildOpenApiPayParams(String tradeNo, BigDecimal amount, int payExpireTime) {
private Map<String, String> buildOpenApiPayParams(String tradeNo, BigDecimal amount, int payExpireTime,
int payment, int hbfqNums, int uid) {
Map<String, String> params = new HashMap<String, String>();
params.put("app_id", getAppId());
params.put("method", "alipay.trade.app.pay");
... ... @@ -424,6 +434,27 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
params.put("version", "1.0");
params.put("notify_url", notifyURL);
if (Payment.isHB(payment)){
params.put("specified_channel", "pcredit"); // 花呗单渠道
}else if(Payment.isHBFQ(payment)){
params.put("specified_channel", "pcreditpayInstallment"); // 花呗分期
HbfqEnum hbfqEnum = HbfqEnum.getByfqTerms(hbfqNums);
if(hbfqEnum == null) {
logger.warn("fqNums from req invalid, fqNums: {}, orderCode: {}", hbfqNums, tradeNo);
throw new ServiceException(ServiceError.ORDER_FQNUM_INVALID);
}
String outTradeNo = tradeNo + hbfqEnum.getTradeNoPostfix();
params.put("out_trade_no", outTradeNo);
params.put("extend_params", getHbfqParam(hbfqEnum.getFqTerms()).toJSONString());
// 记录分期
recordOrdersPayHbfq(outTradeNo, tradeNo, uid);
}
JSONObject bizJson = new JSONObject(true);
bizJson.put("timeout_express", payExpireTime+"m"); //该订单允许的最晚付款时间
... ... @@ -451,6 +482,37 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
/**
* 花呗分期payOrderCode记录
* @param hbfqRecord
* @return
*/
public boolean recordOrdersPayHbfq(String outTradeNo, String tradeNo, int uid) {
logger.info("recordOrdersPayHbfq outTradeNo: {}, tradeNo: {}, uid: {}", outTradeNo, tradeNo, uid);
OrdersPayHbfq record = new OrdersPayHbfq();
record.setFqTradeNo(outTradeNo);
record.setPayOrderCode(tradeNo);
record.setUid(uid);
try {
ordersPayHbfqDao.insertOnDuplicateUpdate(record);
return true;
} catch (Exception e) {
logger.warn("recordOrdersPayHbfq failed, req: {}, ex: ", record, e);
}
return false;
}
private JSONObject getHbfqParam(int fqNums) {
JSONObject json = new JSONObject();
json.put("hb_fq_num", String.valueOf(fqNums));
json.put("hb_fq_seller_percent", "0"); //用户承担手续费
return json;
}
/**
* 获取openapi支付宝待签名字符串
* @param paramsMap
* @return
... ... @@ -475,12 +537,17 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
}
public PaymentData getPaymentData(Map<String, String> params) {
PaymentData payData = new PaymentData();
try {
String outTradeNo = params.get("out_trade_no");
// 花呗分期,获取订单号
OrdersPayHbfq hbfqRecord = ordersPayHbfqDao.selectByPrimaryKey(outTradeNo);
if(hbfqRecord != null) {
outTradeNo = hbfqRecord.getPayOrderCode();
}
payData.setOrderCode(outTradeNo);
payData.setTotalFee(Double.parseDouble(params.get("total_fee") != null ? params.get("total_fee") : params.get("total_amount")));
payData.setBankCode("");
... ...
... ... @@ -103,6 +103,7 @@ datasources:
- com.yohoufo.dal.order.InviteCodeSequenceRandomMapper
- com.yohoufo.dal.order.SellerGoodsStatusFlowMapper
- com.yohoufo.dal.order.CmsPayMapper
- com.yohoufo.dal.order.OrdersPayHbfqMapper
ufo_promotion:
servers:
... ...
... ... @@ -102,6 +102,7 @@ datasources:
- com.yohoufo.dal.order.InviteCodeSequenceRandomMapper
- com.yohoufo.dal.order.SellerGoodsStatusFlowMapper
- com.yohoufo.dal.order.CmsPayMapper
- com.yohoufo.dal.order.OrdersPayHbfqMapper
ufo_promotion:
servers:
... ...