|
@@ -5,6 +5,7 @@ import com.ruoyi.app.omgpay.dto.OmgPaymentErrorResponse;
|
|
|
import com.ruoyi.app.omgpay.dto.OmgNotifyRequest;
|
|
import com.ruoyi.app.omgpay.dto.OmgNotifyRequest;
|
|
|
import com.ruoyi.app.omgpay.dto.OmgQueryPaymentRequest;
|
|
import com.ruoyi.app.omgpay.dto.OmgQueryPaymentRequest;
|
|
|
import com.ruoyi.app.omgpay.dto.OmgRefundPaymentRequest;
|
|
import com.ruoyi.app.omgpay.dto.OmgRefundPaymentRequest;
|
|
|
|
|
+import com.ruoyi.app.omgpay.dto.OmgRetryPaymentRequest;
|
|
|
import com.ruoyi.common.annotation.Anonymous;
|
|
import com.ruoyi.common.annotation.Anonymous;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
import com.ruoyi.common.utils.MessageUtils;
|
|
import com.ruoyi.common.utils.MessageUtils;
|
|
@@ -32,6 +33,7 @@ public class OmgPaymentController {
|
|
|
private final OmgPaymentNotifyService notifyService;
|
|
private final OmgPaymentNotifyService notifyService;
|
|
|
private final OmgIpnAuditService ipnAuditService;
|
|
private final OmgIpnAuditService ipnAuditService;
|
|
|
private final OmgPaymentQueryService queryService;
|
|
private final OmgPaymentQueryService queryService;
|
|
|
|
|
+ private final OmgPaymentRetryService retryService;
|
|
|
private final OmgPaymentRefundService refundService;
|
|
private final OmgPaymentRefundService refundService;
|
|
|
|
|
|
|
|
public OmgPaymentController(OmgPaymentTokenUserResolver tokenUserResolver,
|
|
public OmgPaymentController(OmgPaymentTokenUserResolver tokenUserResolver,
|
|
@@ -39,12 +41,14 @@ public class OmgPaymentController {
|
|
|
OmgPaymentNotifyService notifyService,
|
|
OmgPaymentNotifyService notifyService,
|
|
|
OmgIpnAuditService ipnAuditService,
|
|
OmgIpnAuditService ipnAuditService,
|
|
|
OmgPaymentQueryService queryService,
|
|
OmgPaymentQueryService queryService,
|
|
|
|
|
+ OmgPaymentRetryService retryService,
|
|
|
OmgPaymentRefundService refundService) {
|
|
OmgPaymentRefundService refundService) {
|
|
|
this.tokenUserResolver = tokenUserResolver;
|
|
this.tokenUserResolver = tokenUserResolver;
|
|
|
this.createService = createService;
|
|
this.createService = createService;
|
|
|
this.notifyService = notifyService;
|
|
this.notifyService = notifyService;
|
|
|
this.ipnAuditService = ipnAuditService;
|
|
this.ipnAuditService = ipnAuditService;
|
|
|
this.queryService = queryService;
|
|
this.queryService = queryService;
|
|
|
|
|
+ this.retryService = retryService;
|
|
|
this.refundService = refundService;
|
|
this.refundService = refundService;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -133,6 +137,35 @@ public class OmgPaymentController {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Anonymous
|
|
|
|
|
+ @Auth
|
|
|
|
|
+ @PostMapping("/retry")
|
|
|
|
|
+ public AjaxResult retry(@RequestHeader(name = "token") String token,
|
|
|
|
|
+ @RequestBody(required = false) OmgRetryPaymentRequest request) {
|
|
|
|
|
+ String orderId = request == null ? null : request.getOrderId();
|
|
|
|
|
+ String safeOrderId = safeLogOrderId(orderId);
|
|
|
|
|
+ Long safeUserId = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ safeUserId = tokenUserResolver.requireUserId(token);
|
|
|
|
|
+ log.info("OMG payment retry started orderId={}, userId={}", safeOrderId, safeUserId);
|
|
|
|
|
+ OmgPaymentCreateOutcome outcome = retryService.retry(safeUserId, orderId);
|
|
|
|
|
+ log.info("OMG payment retry succeeded orderId={}, userId={}, storeId={}, "
|
|
|
|
|
+ + "attemptId={}, amount={}, status=CREATED, merchantTradeNo={}",
|
|
|
|
|
+ safeLogOrderId(outcome.orderId()), outcome.userId(), outcome.storeId(), outcome.attemptId(),
|
|
|
|
|
+ outcome.amount(), outcome.maskedMerchantTradeNo());
|
|
|
|
|
+ return AjaxResult.success(outcome.response());
|
|
|
|
|
+ } catch (OmgPaymentBusinessException error) {
|
|
|
|
|
+ log.warn("OMG payment retry rejected orderId={}, userId={}, storeId={}, code={}",
|
|
|
|
|
+ safeOrderId, safeUserId, error.getStoreId(), error.getCode());
|
|
|
|
|
+ return AjaxResult.error(MessageUtils.message(error.getMessageKey()),
|
|
|
|
|
+ new OmgPaymentErrorResponse(error.getCode().name()));
|
|
|
|
|
+ } catch (Exception error) {
|
|
|
|
|
+ log.error("OMG payment retry failed orderId={}, userId={}", safeOrderId, safeUserId, error);
|
|
|
|
|
+ return AjaxResult.error(MessageUtils.message("omg.pay.retry.failed"),
|
|
|
|
|
+ new OmgPaymentErrorResponse("PAYMENT_RETRY_FAILED"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Anonymous
|
|
@Anonymous
|
|
|
@Auth
|
|
@Auth
|
|
|
@PostMapping("/refund")
|
|
@PostMapping("/refund")
|