Commit 77406c4b by 程裕兵

feat:refund

parent a8af2435
package com.jiejing.fitness.finance.api.merchant.request; package com.jiejing.fitness.finance.api.merchant.request;
import com.alibaba.fastjson.JSONObject;
import com.jiejing.paycenter.common.enums.merchant.SubChannelEnums;
import com.jiejing.paycenter.common.enums.pay.PayTypeEnums;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -24,47 +21,24 @@ import lombok.NoArgsConstructor; ...@@ -24,47 +21,24 @@ import lombok.NoArgsConstructor;
@ApiModel(description = "品牌商户退款Request") @ApiModel(description = "品牌商户退款Request")
public class BrandMerchantRefundRequest { public class BrandMerchantRefundRequest {
@ApiModelProperty(value = "品牌ID", required = true) @ApiModelProperty(value = "场馆ID", required = true)
@NotNull(message = "品牌ID不能为空") @NotNull(message = "场馆ID不能为空")
private Long brandId; private Long studioId;
@ApiModelProperty(name = "支付总金额(元)", required = true) @ApiModelProperty(name = "支付总金额(元)", required = true)
@NotNull(message = "支付总金额不能为空") @NotNull(message = "支付总金额不能为空")
private BigDecimal amount; private BigDecimal transAmount;
@ApiModelProperty(name = "业务订单号", required = true) @ApiModelProperty(name = "上层业务退款单号", required = true)
@NotBlank(message = "业务订单号不能为空") @NotBlank(message = "上层业务退款单号不能为空")
private String orderNo; private String orderNo;
@ApiModelProperty(name = "业务订单类型", required = true) @ApiModelProperty(name = "退款请求对应的支付流水号", required = true)
@NotNull(message = "业务订单类型不能为空") @NotBlank(message = "退款请求对应的支付流水号不能为空")
private Integer orderType; private String payTransNo;
@ApiModelProperty(name = "支付类型", required = true) @ApiModelProperty(name = "退款原因", required = true)
@NotNull(message = "支付类型不能为空") @NotBlank(message = "退款原因不能为空")
private PayTypeEnums payType; private String refundReason;
@ApiModelProperty(name = "正扫:三方支付账户ID", notes = "微信的openId,支付宝的userId,JS、MINI、NATIVE支付必传")
private String openId;
@ApiModelProperty(name = "反扫:支付授权码", notes = "扫码设备读出的条形码或者二维码信息,BARCODE支付必传")
private String authCode;
@ApiModelProperty(name = "支付子渠道", notes = "聚合支付时需要")
private SubChannelEnums subChannel;
@ApiModelProperty(name = "商品名称", required = true)
@NotBlank(message = "商品名称不能为空")
private String goods;
@ApiModelProperty(name = "appId", notes = "指定本次使用的appId")
private String appId;
@ApiModelProperty(name = "过期时间(单位:秒)", required = true)
@NotNull(message = "过期时间不能为空")
private Integer timeExpire;
@ApiModelProperty(name = "业务扩展信息")
private JSONObject extra;
} }
...@@ -6,6 +6,7 @@ import com.jiejing.filecenter.api.common.event.ResourceEvent; ...@@ -6,6 +6,7 @@ import com.jiejing.filecenter.api.common.event.ResourceEvent;
import com.jiejing.fitness.finance.service.event.ListenerService; import com.jiejing.fitness.finance.service.event.ListenerService;
import com.jiejing.paycenter.common.event.MerchantEvent; import com.jiejing.paycenter.common.event.MerchantEvent;
import com.jiejing.paycenter.common.event.PayEvent; import com.jiejing.paycenter.common.event.PayEvent;
import com.jiejing.paycenter.common.event.RefundEvent;
import com.xiaomai.event.annotation.EnableEventBinding; import com.xiaomai.event.annotation.EnableEventBinding;
import com.xiaomai.event.annotation.EventConfig; import com.xiaomai.event.annotation.EventConfig;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -27,8 +28,9 @@ import org.springframework.scheduling.annotation.EnableScheduling; ...@@ -27,8 +28,9 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@MapperScan(value = {"com.jiejing.fitness.finance.repository.mapper"}) @MapperScan(value = {"com.jiejing.fitness.finance.repository.mapper"})
@EnableEventBinding( @EnableEventBinding(
configs = { configs = {
@EventConfig(event = MerchantEvent.class, binder = "biz-kafka"),
@EventConfig(event = PayEvent.class, binder = "biz-kafka"), @EventConfig(event = PayEvent.class, binder = "biz-kafka"),
@EventConfig(event = MerchantEvent.class, binder = "biz-kafka") @EventConfig(event = RefundEvent.class, binder = "biz-kafka")
}, },
listenerClass = {ListenerService.class}) listenerClass = {ListenerService.class})
@EnableFeignClients(basePackages = { @EnableFeignClients(basePackages = {
......
...@@ -8,6 +8,7 @@ import com.jiejing.fitness.finance.service.merchant.BrandMerchantService; ...@@ -8,6 +8,7 @@ import com.jiejing.fitness.finance.service.merchant.BrandMerchantService;
import com.jiejing.fitness.finance.service.pay.PayService; import com.jiejing.fitness.finance.service.pay.PayService;
import com.jiejing.paycenter.common.event.MerchantEvent; import com.jiejing.paycenter.common.event.MerchantEvent;
import com.jiejing.paycenter.common.event.PayEvent; import com.jiejing.paycenter.common.event.PayEvent;
import com.jiejing.paycenter.common.event.RefundEvent;
import com.xiaomai.event.annotation.EventHandler; import com.xiaomai.event.annotation.EventHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Optional; import java.util.Optional;
...@@ -65,4 +66,15 @@ public class ListenerService { ...@@ -65,4 +66,15 @@ public class ListenerService {
} }
} }
@EventHandler(value = RefundEvent.class, binder = "biz-kafka", maxAttempts = MAX_RETRY)
public void refundEventCallback(RefundEvent event, @Header(DELIVERY_ATTEMPT) int retryNum) {
try {
log.info("start process refund event {}", event.getTransNo());
payService.refundCallback(event);
} catch (Exception e) {
log.info("process refund event fail {}", event.getTransNo(), e);
}
}
} }
...@@ -5,6 +5,7 @@ import com.jiejing.fitness.finance.service.pay.params.BrandMerchantRefundParams; ...@@ -5,6 +5,7 @@ import com.jiejing.fitness.finance.service.pay.params.BrandMerchantRefundParams;
import com.jiejing.paycenter.api.pay.vo.PayVO; import com.jiejing.paycenter.api.pay.vo.PayVO;
import com.jiejing.paycenter.api.pay.vo.RefundVO; import com.jiejing.paycenter.api.pay.vo.RefundVO;
import com.jiejing.paycenter.common.event.PayEvent; import com.jiejing.paycenter.common.event.PayEvent;
import com.jiejing.paycenter.common.event.RefundEvent;
/** /**
* @author chengyubing * @author chengyubing
...@@ -35,4 +36,11 @@ public interface PayService { ...@@ -35,4 +36,11 @@ public interface PayService {
*/ */
RefundVO merchantRefund(BrandMerchantRefundParams params); RefundVO merchantRefund(BrandMerchantRefundParams params);
/**
* 退款回调
*
* @param event 事件
*/
void refundCallback(RefundEvent event);
} }
...@@ -25,6 +25,7 @@ import com.jiejing.paycenter.common.enums.merchant.SubChannelOpenTypeEnums; ...@@ -25,6 +25,7 @@ import com.jiejing.paycenter.common.enums.merchant.SubChannelOpenTypeEnums;
import com.jiejing.paycenter.common.enums.pay.PayStateEnums; import com.jiejing.paycenter.common.enums.pay.PayStateEnums;
import com.jiejing.paycenter.common.enums.pay.PayTypeEnums; import com.jiejing.paycenter.common.enums.pay.PayTypeEnums;
import com.jiejing.paycenter.common.event.PayEvent; import com.jiejing.paycenter.common.event.PayEvent;
import com.jiejing.paycenter.common.event.RefundEvent;
import com.jiejing.paycenter.common.model.SubChannelInfo; import com.jiejing.paycenter.common.model.SubChannelInfo;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
...@@ -212,4 +213,15 @@ public class PayConvert { ...@@ -212,4 +213,15 @@ public class PayConvert {
return BrandCashierTransStateEnums.REFUNDING; return BrandCashierTransStateEnums.REFUNDING;
} }
} }
public static BrandCashierRecord convertRefund(BrandCashierRecord record, RefundEvent event) {
return BrandCashierRecord.builder()
.id(record.getId())
.transState(convertTransState(event.getRefundState()))
.failMessage(event.getFailMessage())
.successTime(event.getSuccessTime())
.updateTime(new Date())
.build();
}
} }
...@@ -20,6 +20,7 @@ import com.jiejing.paycenter.api.pay.vo.PayVO; ...@@ -20,6 +20,7 @@ import com.jiejing.paycenter.api.pay.vo.PayVO;
import com.jiejing.paycenter.api.pay.vo.RefundVO; import com.jiejing.paycenter.api.pay.vo.RefundVO;
import com.jiejing.paycenter.common.enums.pay.PayStateEnums; import com.jiejing.paycenter.common.enums.pay.PayStateEnums;
import com.jiejing.paycenter.common.event.PayEvent; import com.jiejing.paycenter.common.event.PayEvent;
import com.jiejing.paycenter.common.event.RefundEvent;
import com.jiejing.studio.api.studio.vo.StudioVO; import com.jiejing.studio.api.studio.vo.StudioVO;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
...@@ -95,4 +96,16 @@ public class PayServiceImpl implements PayService { ...@@ -95,4 +96,16 @@ public class PayServiceImpl implements PayService {
return vo; return vo;
} }
@Override
public void refundCallback(RefundEvent event) {
BrandCashierRecord record = brandCashierRecordRpService.getById(Long.parseLong(event.getTransNo()))
.orElse(null);
if (null == record) {
return;
}
BrandCashierRecord toModify = PayConvert.convertRefund(record, event);
brandCashierRecordRpService.updateById(toModify);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment