1. 迁移支付交易的提交 RPC 接口
2. 迁移支付交易的获取 RPC 接口
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package cn.iocoder.mall.shopweb.client.pay;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.PayTransactionRpc;
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionGetReqDTO;
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionRespDTO;
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionSubmitReqDTO;
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionSubmitRespDTO;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class PayTransactionClient {
|
||||
|
||||
@DubboReference(version = "${dubbo.consumer.PayTransactionRpc.version}")
|
||||
private PayTransactionRpc payTransactionRpc;
|
||||
|
||||
public PayTransactionRespDTO getPayTransaction(Integer userId, String appId, String orderId) {
|
||||
CommonResult<PayTransactionRespDTO> getPayTransactionResult = payTransactionRpc.getPayTransaction(new PayTransactionGetReqDTO()
|
||||
.setAppId(appId).setOrderId(orderId));
|
||||
getPayTransactionResult.checkError();
|
||||
if (getPayTransactionResult.getData() == null) {
|
||||
return null;
|
||||
}
|
||||
// 如果用户编号不匹配,则返回 null
|
||||
return Objects.equals(getPayTransactionResult.getData().getUserId(), userId) ?
|
||||
getPayTransactionResult.getData() : null;
|
||||
}
|
||||
|
||||
public PayTransactionSubmitRespDTO submitPayTransaction(PayTransactionSubmitReqDTO submitReqDTO) {
|
||||
CommonResult<PayTransactionSubmitRespDTO> submitPayTransactionResult = payTransactionRpc.submitPayTransaction(submitReqDTO);
|
||||
submitPayTransactionResult.checkError();
|
||||
return submitPayTransactionResult.getData();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package cn.iocoder.mall.shopweb.controller.pay;
|
||||
|
||||
import cn.iocoder.common.framework.util.HttpUtil;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.security.user.core.context.UserSecurityContextHolder;
|
||||
import cn.iocoder.mall.shopweb.controller.pay.vo.transaction.PayTransactionRespVO;
|
||||
import cn.iocoder.mall.shopweb.controller.pay.vo.transaction.PayTransactionSubmitReqVO;
|
||||
import cn.iocoder.mall.shopweb.controller.pay.vo.transaction.PayTransactionSubmitRespVO;
|
||||
import cn.iocoder.mall.shopweb.service.pay.PayTransactionService;
|
||||
import cn.iocoder.security.annotations.RequiresAuthenticate;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@Api("支付交易 API")
|
||||
@RestController
|
||||
@RequestMapping("/pay/transaction")
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class PayTransactionController {
|
||||
|
||||
@Autowired
|
||||
private PayTransactionService payTransactionService;
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得支付交易")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "appId", required = true, value = "应用编号", example = "POd4RC6a"),
|
||||
@ApiImplicitParam(name = "orderId", required = true, value = "订单号", example = "1024"),
|
||||
})
|
||||
@RequiresAuthenticate
|
||||
public CommonResult<PayTransactionRespVO> getPayTransaction(@RequestParam("appId") String appId,
|
||||
@RequestParam("orderId") String orderId) {
|
||||
return success(payTransactionService.getPayTransaction(UserSecurityContextHolder.getUserId(), appId, orderId));
|
||||
}
|
||||
|
||||
@PostMapping("/submit")
|
||||
@ApiOperation("提交支付交易")
|
||||
@RequiresAuthenticate
|
||||
public CommonResult<PayTransactionSubmitRespVO> submitPayTransaction(HttpServletRequest request,
|
||||
PayTransactionSubmitReqVO submitReqVO) {
|
||||
return success(payTransactionService.submitPayTransaction(submitReqVO, HttpUtil.getIp(request)));
|
||||
}
|
||||
|
||||
// @PostMapping(value = "pingxx_pay_success", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
//// @GetMapping(value = "pingxx_pay_success")
|
||||
// public String pingxxPaySuccess(HttpServletRequest request) throws IOException {
|
||||
// logger.info("[pingxxPaySuccess][被回调]");
|
||||
// // 读取 webhook
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// try (BufferedReader reader = request.getReader()) {
|
||||
// String line;
|
||||
// while ((line = reader.readLine()) != null) {
|
||||
// sb.append(line);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//// JSONObject bodyObj = JSON.parseObject(sb.toString());
|
||||
//// bodyObj.put("webhookId", bodyObj.remove("id"));
|
||||
//// String body = bodyObj.toString();
|
||||
// payTransactionService.updateTransactionPaySuccess(PayChannelEnum.PINGXX.getId(), sb.toString());
|
||||
// return "success";
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package cn.iocoder.mall.shopweb.controller.pay.vo.transaction;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ApiModel("支付交易 Response VO")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class PayTransactionRespVO {
|
||||
|
||||
@ApiModelProperty(value = "交易编号", required = true, example = "1")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "应用编号", required = true, example = "POd4RC6a")
|
||||
private String appId;
|
||||
|
||||
@ApiModelProperty(value = "订单号不能为空", required = true, example = "1024")
|
||||
private String orderId;
|
||||
|
||||
@ApiModelProperty(value = "商品名", required = true, example = "芋道源码")
|
||||
private String orderSubject;
|
||||
|
||||
@ApiModelProperty(value = "订单商品描述", required = true, example = "绵啾啾的")
|
||||
private String orderDescription;
|
||||
|
||||
@ApiModelProperty(value = "支付金额,单位:分。", required = true, example = "10")
|
||||
private Integer price;
|
||||
|
||||
@ApiModelProperty(value = "订单状态", required = true, example = "1", notes = "参见 PayTransactionStatusEnum 枚举")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "交易过期时间", required = true)
|
||||
private Date expireTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package cn.iocoder.mall.shopweb.controller.pay.vo.transaction;
|
||||
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import cn.iocoder.mall.payservice.enums.PayChannelEnum;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel("支付交易提交 Request VO")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class PayTransactionSubmitReqVO {
|
||||
|
||||
@ApiModelProperty(value = "应用编号", required = true, example = "POd4RC6a")
|
||||
@NotEmpty(message = "应用编号不能为空")
|
||||
private String appId;
|
||||
|
||||
@ApiModelProperty(value = "订单号", required = true, example = "1024")
|
||||
@NotEmpty(message = "订单号不能为空")
|
||||
private String orderId;
|
||||
|
||||
@ApiModelProperty(value = "支付渠道", required = true, example = "1", notes = "参见 PayChannelEnum 枚举")
|
||||
@InEnum(value = PayChannelEnum.class, message = "支付渠道必须是 {value}")
|
||||
@NotNull(message = "支付渠道")
|
||||
private Integer payChannel;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.iocoder.mall.shopweb.controller.pay.vo.transaction;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@ApiModel("支付交易提交 Response VO")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class PayTransactionSubmitRespVO {
|
||||
|
||||
@ApiModelProperty(value = "支付交易拓展单编号", required = true, example = "1")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "调用三方平台的响应结果", required = true)
|
||||
private String invokeResponse;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.iocoder.mall.shopweb.convert.pay;
|
||||
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionRespDTO;
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionSubmitReqDTO;
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionSubmitRespDTO;
|
||||
import cn.iocoder.mall.shopweb.controller.pay.vo.transaction.PayTransactionRespVO;
|
||||
import cn.iocoder.mall.shopweb.controller.pay.vo.transaction.PayTransactionSubmitReqVO;
|
||||
import cn.iocoder.mall.shopweb.controller.pay.vo.transaction.PayTransactionSubmitRespVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface PayTransactionConvert {
|
||||
|
||||
PayTransactionConvert INSTANCE = Mappers.getMapper(PayTransactionConvert.class);
|
||||
|
||||
PayTransactionSubmitReqDTO convert(PayTransactionSubmitReqVO bean);
|
||||
|
||||
PayTransactionSubmitRespVO convert(PayTransactionSubmitRespDTO bean);
|
||||
|
||||
PayTransactionRespVO convert(PayTransactionRespDTO bean);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.iocoder.mall.shopweb.service.pay;
|
||||
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionSubmitRespDTO;
|
||||
import cn.iocoder.mall.shopweb.client.pay.PayTransactionClient;
|
||||
import cn.iocoder.mall.shopweb.controller.pay.vo.transaction.PayTransactionRespVO;
|
||||
import cn.iocoder.mall.shopweb.controller.pay.vo.transaction.PayTransactionSubmitReqVO;
|
||||
import cn.iocoder.mall.shopweb.controller.pay.vo.transaction.PayTransactionSubmitRespVO;
|
||||
import cn.iocoder.mall.shopweb.convert.pay.PayTransactionConvert;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class PayTransactionService {
|
||||
|
||||
@Autowired
|
||||
private PayTransactionClient payTransactionClient;
|
||||
|
||||
public PayTransactionSubmitRespVO submitPayTransaction(PayTransactionSubmitReqVO submitReqVO, String ip) {
|
||||
PayTransactionSubmitRespDTO submitPayTransaction = payTransactionClient.submitPayTransaction(
|
||||
PayTransactionConvert.INSTANCE.convert(submitReqVO));
|
||||
return PayTransactionConvert.INSTANCE.convert(submitPayTransaction);
|
||||
}
|
||||
|
||||
public PayTransactionRespVO getPayTransaction(Integer userId, String appId, String orderId) {
|
||||
return PayTransactionConvert.INSTANCE.convert(payTransactionClient.getPayTransaction(userId, appId, orderId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,6 +55,8 @@ dubbo:
|
||||
version: 1.0.0
|
||||
TradeOrderRpc:
|
||||
version: 1.0.0
|
||||
PayTransactionRpc:
|
||||
version: 1.0.0
|
||||
|
||||
# Swagger 配置项
|
||||
swagger:
|
||||
|
||||
Reference in New Issue
Block a user