zhuyifan

支付回调对接

......@@ -42,8 +42,8 @@ public class PayController {
@ApiOperation(value = "支付通知")
@PostMapping(value = "/pay/callback")
@ResponseStatus(HttpStatus.OK)
public void callback(@Valid @RequestBody PaymentCallbackDTO paymentCallbackDTO) {
payServiceClient.callback(paymentCallbackDTO);
public boolean callback(@Valid @RequestBody PaymentCallbackDTO paymentCallbackDTO) {
return payServiceClient.callback(paymentCallbackDTO);
}
}
\ No newline at end of file
......
......@@ -105,7 +105,7 @@ public class PayServiceClient {
}
}
public void callback(PaymentCallbackDTO paymentCallbackDTO) {
public boolean callback(PaymentCallbackDTO paymentCallbackDTO) {
log.info("callback request received: {}", paymentCallbackDTO);
try {
final var paymentCallbackResult = xmlMapper.readValue(paymentCallbackDTO.getPayResult(), PaymentCallbackResult.class);
......@@ -114,11 +114,11 @@ public class PayServiceClient {
final var orderById = orderServiceRpcClient.getOrderById(orderId);
if (orderById == null) {
log.error("Order not found, orderId: {}", orderId);
return;
return false;
}
if (orderById.getPayStatus() == PayStatusEnum.SUCCEED || orderById.getPayStatus() == PayStatusEnum.FAILED) {
log.info("Order {} already processed, skipping.", orderId);
return;
return true;
}
long payTime;
try {
......@@ -146,6 +146,7 @@ public class PayServiceClient {
.build();
final var updateResponse = orderServiceRpcClient.updateClientCustomerOrderPaymentResult(orderById, build);
log.info("callback updateClientCustomerOrder result: {}", updateResponse.getIsUpdated());
return updateResponse.getIsUpdated();
} catch (JsonProcessingException e) {
log.error("Failed to parse XML response, raw XML: {}", paymentCallbackDTO.getPayResult(), e);
throw new RuntimeException("支付通知结果解析失败", e);
......