zhuyifan

支付中

......@@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
......@@ -31,7 +32,7 @@ public class PayController {
private final PayServiceClient payServiceClient;
@SaIgnore
@ApiOperation(value = "支付")
@ApiOperation(value = "支付信息")
@PostMapping("/pay/inform")
@ResponseStatus(HttpStatus.OK)
public PayResponseDto pay(@Valid @RequestBody PayDTO.PayInformRequestDto payInformRequestDto) {
......@@ -39,6 +40,14 @@ public class PayController {
}
@SaIgnore
@ApiOperation(value = "支付中")
@PostMapping("/order/{orderId}/pay/waiting")
@ResponseStatus(HttpStatus.OK)
public boolean waiting(@PathVariable("orderId")Integer orderId) {
return payServiceClient.waiting(orderId);
}
@SaIgnore
@ApiOperation(value = "支付通知")
@PostMapping(value = "/pay/callback")
@ResponseStatus(HttpStatus.OK)
......
......@@ -116,7 +116,7 @@ public class PayServiceClient {
log.error("Order not found, orderId: {}", orderId);
return false;
}
if (orderById.getPayStatus() == PayStatusEnum.SUCCEED || orderById.getPayStatus() == PayStatusEnum.FAILED) {
if (orderById.getPayStatus() != PayStatusEnum.IN_PROGRESS) {
log.info("Order {} already processed, skipping.", orderId);
return true;
}
......@@ -155,4 +155,23 @@ public class PayServiceClient {
throw new RuntimeException("支付通知处理失败", e);
}
}
public boolean waiting(Integer orderId) {
final var orderById = orderServiceRpcClient.getOrderById(orderId);
if (orderById == null) {
log.error("waiting Order not found, orderId: {}", orderId);
return false;
}
if (orderById.getPayStatus() != PayStatusEnum.TO_PAY) {
log.info("waiting Order {} already processed, skipping.", orderId);
return false;
}
final var build = ClientCustomerOrderModification.newBuilder()
.setId(orderId)
.setShouldUpdatePayStatus(true).setPayStatus(PayStatusEnum.IN_PROGRESS)
.build();
final var updateResponse = orderServiceRpcClient.updateClientCustomerOrderPaymentResult(orderById, build);
log.info("waiting updateClientCustomerOrder result: {}", updateResponse.getIsUpdated());
return updateResponse.getIsUpdated();
}
}
......