创建代金券批次API

This commit is contained in:
xiafang
2020-11-24 15:18:52 +08:00
parent c324f636d5
commit 623e80ada1
10 changed files with 267 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package com.enongm.dianji.payment.wechat.enumeration;
/**
* 优惠券背景色
* <p>
* https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/marketing/convention/chapter3_1.shtml#menu1
*
* @author Dax
* @since 14:50
*/
public enum CouponBgColor {
COLOR010("#63B359"),
COLOR020("#2C9F67"),
COLOR030("#509FC9"),
COLOR040("#5885CF"),
COLOR050("#9062C0"),
COLOR060("#D09A45"),
COLOR070("#E4B138"),
COLOR080("#EE903C"),
COLOR090("#DD6549"),
COLOR100("#CC463D");
private final String color;
CouponBgColor(String color) {
this.color = color;
}
public String color() {
return this.color;
}
}

View File

@@ -35,6 +35,10 @@ public enum WechatPayV3Type {
MWEB(HttpMethod.POST, "%s/v3/pay/transactions/h5"),
/**
* 创建代金券批次API.
*/
MARKETING_FAVOR_STOCKS_COUPON_STOCKS(HttpMethod.POST,"%s/v3/marketing/favor/coupon-stocks"),
/**
* 激活代金券批次API
*/

View File

@@ -6,6 +6,7 @@ import com.enongm.dianji.payment.wechat.enumeration.StockStatus;
import com.enongm.dianji.payment.wechat.enumeration.WeChatServer;
import com.enongm.dianji.payment.wechat.enumeration.WechatPayV3Type;
import com.enongm.dianji.payment.wechat.v3.model.AppPayParams;
import com.enongm.dianji.payment.wechat.v3.model.StocksCreateParams;
import com.enongm.dianji.payment.wechat.v3.model.StocksQueryParams;
import com.enongm.dianji.payment.wechat.v3.model.StocksSendParams;
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -57,6 +58,36 @@ public class WechatPayV3Api {
}
/**
* 创建代金券批次API.
*
* @param params the params
* @return the wechat response entity
*/
public WechatResponseEntity<ObjectNode> createStocks(StocksCreateParams params) {
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
wechatPayV3Client.withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_COUPON_STOCKS, params)
.function(this::createStocksFunction)
.consumer(wechatResponseEntity::convert)
.request();
return wechatResponseEntity;
}
private RequestEntity<?> createStocksFunction(WechatPayV3Type type, StocksCreateParams params) {
WechatPayProperties.V3 v3 = wechatMetaBean.getWechatPayProperties().getV3();
String mchId = v3.getMchId();
String httpUrl = type.uri(WeChatServer.CHINA);
URI uri = UriComponentsBuilder.fromHttpUrl(httpUrl).build().toUri();
params.setBelongMerchant(mchId);
try {
return RequestEntity.post(uri)
.body(MAPPER.writeValueAsString(params));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
throw new PayException("wechat app pay json failed");
}
/**
* 激活代金券批次API
*

View File

@@ -0,0 +1,11 @@
package com.enongm.dianji.payment.wechat.v3.model;
import lombok.Data;
@Data
public class CouponAvailableTime {
private Long availableTimeAfterReceive;
private FixAvailableTime fixAvailableTime;
private Boolean secondDayAvailable;
}

View File

@@ -0,0 +1,28 @@
package com.enongm.dianji.payment.wechat.v3.model;
import lombok.Data;
import java.util.List;
/**
* 核销规则.
*/
@Data
public class CouponUseRule {
private List<String> availableItems;
private List<String> availableMerchants;
private Boolean combineUse;
private CouponAvailableTime couponAvailableTime;
private FixedNormalCoupon fixedNormalCoupon;
private List<String> goodsTag;
private String tradeType;
}

View File

@@ -0,0 +1,15 @@
package com.enongm.dianji.payment.wechat.v3.model;
import lombok.Data;
import java.util.List;
@Data
public class FixAvailableTime {
private List<Long> availableWeekDay;
private Long beginTime;
private Long endTime;
}

View File

@@ -0,0 +1,13 @@
package com.enongm.dianji.payment.wechat.v3.model;
import lombok.Data;
@Data
public class FixedNormalCoupon {
private Long couponAmount;
private Long transactionMinimum;
}

View File

@@ -0,0 +1,34 @@
package com.enongm.dianji.payment.wechat.v3.model;
import com.enongm.dianji.payment.wechat.enumeration.CouponBgColor;
/**
* 优惠券样式
*
* @author Dax
* @since 15:09
*/
public class PatternInfo {
/**
* 背景色
*/
private CouponBgColor backgroundColor;
/**
* 券详情图片
*/
private String couponImage;
/**
* 使用说明
*/
private String description;
/**
* 商户logo
*/
private String merchantLogo;
/**
* 商户名称
*/
private String merchantName;
}

View File

@@ -0,0 +1,39 @@
package com.enongm.dianji.payment.wechat.v3.model;
import lombok.Data;
/**
* 批次使用规则
*
* @author Dax
* @since 15:08
*/
@Data
public class StockUseRule {
/**
* 总消耗金额,单位:分。
* max_amount需要等于coupon_amount面额 * max_coupons发放总上限
*/
private Long maxAmount;
/**
* 单天最高消耗金额,单位:分
*/
private Long maxAmountByDay;
/**
* 最大发券数
*/
private Long maxCoupons;
/**
* 单个用户可领个数每个用户最多60张券
*/
private Long maxCouponsPerUser;
/**
* 是否开启自然人限制
*/
private Boolean naturalPersonLimit;
/**
* api发券防刷
*/
private Boolean preventApiAbuse;
}

View File

@@ -0,0 +1,60 @@
package com.enongm.dianji.payment.wechat.v3.model;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 创建优惠券批次参数.
*
* @author Dax
* @since 14 :19
*/
@Data
public class StocksCreateParams {
/**
* 批次名称
*/
private String stockName;
/**
* 仅配置商户可见,用于自定义信息
*/
private String comment;
/**
* 批次归属商户号
*/
private String belongMerchant;
/**
* 批次开始时间
*/
private LocalDateTime availableBeginTime;
/**
* 批次结束时间
*/
private LocalDateTime availableEndTime;
/**
* 是否无资金流
*/
private Boolean noCash;
/**
* 批次类型
*/
private String stockType = "NORMAL";
/**
* 商户单据号
*/
private String outRequestNo;
/**
* 扩展属性
*/
private String ext_info;
/**
* 批次使用规则
*/
private StockUseRule stockUseRule;
/**
* 核销规则
*/
private CouponUseRule couponUseRule;
}