LinePayCancellationCompensationService.java 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. package com.ruoyi.app.pay;
  2. import com.ruoyi.system.domain.PosOrderLinePayment;
  3. import com.ruoyi.system.service.IPosOrderLinePaymentService;
  4. import com.ruoyi.system.service.IPosOrderLineRefundService;
  5. import org.springframework.stereotype.Service;
  6. import java.util.List;
  7. /** Repairs a cancellation crash gap by creating any missing refund intent for captured payments. */
  8. @Service
  9. public class LinePayCancellationCompensationService {
  10. private final IPosOrderLinePaymentService paymentService;
  11. private final IPosOrderLineRefundService refundService;
  12. public LinePayCancellationCompensationService(IPosOrderLinePaymentService paymentService,
  13. IPosOrderLineRefundService refundService) {
  14. this.paymentService = paymentService;
  15. this.refundService = refundService;
  16. }
  17. public void createMissingRefundIntents(List<PosOrderLinePayment> payments) {
  18. if (payments == null) {
  19. return;
  20. }
  21. payments.stream().filter(payment -> "PAID".equals(payment.getStatus()))
  22. .forEach(payment -> refundService.createIfAbsent(payment, "CANCEL_SCAN"));
  23. }
  24. public void createMissingRefundIntent(String ddId) {
  25. createMissingRefundIntents(paymentService.getByDdId(ddId));
  26. }
  27. }