为PayPal添加定时任务

This commit is contained in:
2024-04-10 16:07:52 +08:00
parent 7d967ed41e
commit 1d443b140b
10 changed files with 129 additions and 206 deletions

View File

@@ -40,7 +40,12 @@ public enum OrderStatusEnum {
/**
* 退款异常
*/
REFUND_ABNORMAL("退款异常");
REFUND_ABNORMAL("退款异常"),
/**
* paypal订单状态为 APPROVED
*/
ORDER_PROCESSING("订单处理中");
/**
* 类型

View File

@@ -7,18 +7,24 @@ import lombok.Getter;
@AllArgsConstructor
public enum PayPalOrderStatusEnum {
// The order was created with the specified context.
// 订单已创建并具有指定的上下文。
CREATED("CREATED"),
// The order was saved and persisted. The order status continues to be in progress until a capture is made with final_capture = true for all purchase units within the order.
// 订单已保存并持久化。订单状态仍处于进行中,直到对订单中的所有购买单元进行了 final_capture = true 的捕获为止
SAVED("SAVED"),
// The customer approved the payment through the PayPal wallet or another form of guest or unbranded payment. For example, a card, bank account, or so on.
// 客户通过PayPal钱包或其他形式的游客或非品牌支付批准了付款。例如信用卡、银行账户等。
APPROVED("APPROVED"),
// All purchase units in the order are voided.
// 订单中的所有购买单元都已作废。
VOIDED("VOIDED"),
// The payment was authorized or the authorized payment was captured for the order.
// 订单的支付已被授权或已捕获授权的支付。
COMPLETED("COMPLETED"),
// The order requires an action from the payer (e.g. 3DS authentication). Redirect the payer to the "rel":"payer-action" HATEOAS link returned as part of the response prior to authorizing or capturing the order.
// 订单需要支付者执行某项操作例如3DS身份验证。在授权或捕获订单之前请将支付者重定向到响应中返回的"rel":"payer-action" HATEOAS链接。
PAYER_ACTION_REQUIRED("PAYER_ACTION_REQUIRED");
private final String status;
}

View File

@@ -24,10 +24,10 @@ public class AliPayTask {
/**
* 从第0秒开始每隔30秒执行1次查询创建超过5分钟并且未支付的订单
*/
@Scheduled(cron = "0/30 * * * * ?")
// @Scheduled(cron = "0/30 * * * * ?")
public void orderConfirm(){
log.info("orderConfirm 被执行......");
log.info("Alipay orderConfirm 被执行......");
List<OrderInfo> orderInfoList = orderInfoService.getNoPayOrderByDuration(5, PayTypeEnum.ALIPAY.getType());

View File

@@ -0,0 +1,42 @@
package com.ai.da.common.task;
import com.ai.da.common.enums.PayTypeEnum;
import com.ai.da.mapper.primary.entity.OrderInfo;
import com.ai.da.service.OrderInfoService;
import com.ai.da.service.PayPalCheckoutService;
import com.paypal.http.exceptions.SerializeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Slf4j
@Component
public class PaypalTask {
@Resource
private OrderInfoService orderInfoService;
@Resource
private PayPalCheckoutService payPalCheckoutService;
@Scheduled(cron = "0/30 * * * * ?")
public void orderConfirm() throws SerializeException {
log.info("PayPal orderConfirm 被执行......");
List<OrderInfo> orderInfoList = orderInfoService.getNoPayOrderByDuration(5, PayTypeEnum.PAYPAL.getType());
for (OrderInfo orderInfo : orderInfoList) {
String orderNo = orderInfo.getOrderNo();
log.warn("超时订单 ===> {}", orderNo);
//核实订单状态:调用支付宝查单接口
payPalCheckoutService.checkOrderStatus(orderNo);
}
}
}