org.yes.tools.pay.module.request.PayRequest Maven / Gradle / Ivy
package org.yes.tools.pay.module.request;
import cn.hutool.core.date.DateUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.yes.tools.pay.config.PayConfig;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
public class PayRequest extends BaseRequest {
private static final long serialVersionUID = 522565152886671848L;
//消息ID
private String msgId;
//请求系统预留字段
private String srcReserve;
//终端号
private String tid;
//商户订单号
private String merOrderId;
//订单过期时间
private String expireTime;
//支付总金额 单位:分 若divisionFlag为true,则:
//totalAmount =subOrders字段中的所有totalAmount值之和
//platformAmount值 =goods中的所有subOrderAmount值之和。
private Integer totalAmount;
//分账标记
private Boolean divisionFlag;
//子订单信息
private List subOrders;
//支付结果通知地址
private String notifyUrl;
//平台商户分账金额,单位:分, 若分账标记传,则分账金额必传
private Integer platformAmount;
private String attachedData;
//交易类型
private String tradeType;
@Override
public void checkAndSign(PayConfig payConfig) {
this.merOrderId = payConfig.getSourceSn() + this.merOrderId;
this.expireTime = DateUtil.formatDateTime(DateUtil.offsetMinute(new Date(), 15));
this.divisionFlag = this.subOrders.size() > 0;
int sum = this.subOrders.stream().mapToInt(SubOrder::getTotalAmount).sum();
this.platformAmount = this.totalAmount - sum;
//只有微信与支付的APP和小程序支付有用
this.attachedData = this.srcReserve;
super.checkAndSign(payConfig);
}
@Data
@NoArgsConstructor
public static class SubOrder implements Serializable {
private static final long serialVersionUID = -1L;
//子商户号
private String mid;
//子商户分账金额
private Integer totalAmount;
}
}