|
@@ -4,6 +4,7 @@ import com.ruoyi.app.omgpay.dto.OmgCreatePaymentRequest;
|
|
|
import com.ruoyi.app.omgpay.dto.OmgPaymentErrorResponse;
|
|
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.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;
|
|
@@ -31,17 +32,20 @@ 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 OmgPaymentRefundService refundService;
|
|
|
|
|
|
|
|
public OmgPaymentController(OmgPaymentTokenUserResolver tokenUserResolver,
|
|
public OmgPaymentController(OmgPaymentTokenUserResolver tokenUserResolver,
|
|
|
OmgPaymentCreateService createService,
|
|
OmgPaymentCreateService createService,
|
|
|
OmgPaymentNotifyService notifyService,
|
|
OmgPaymentNotifyService notifyService,
|
|
|
OmgIpnAuditService ipnAuditService,
|
|
OmgIpnAuditService ipnAuditService,
|
|
|
- OmgPaymentQueryService queryService) {
|
|
|
|
|
|
|
+ OmgPaymentQueryService queryService,
|
|
|
|
|
+ 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.refundService = refundService;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** OMG server-to-server final payment notification. */
|
|
/** OMG server-to-server final payment notification. */
|
|
@@ -129,6 +133,30 @@ public class OmgPaymentController {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Anonymous
|
|
|
|
|
+ @Auth
|
|
|
|
|
+ @PostMapping("/refund")
|
|
|
|
|
+ public AjaxResult refund(@RequestHeader(name = "token") String token,
|
|
|
|
|
+ @RequestBody(required = false) OmgRefundPaymentRequest request) {
|
|
|
|
|
+ String orderId = request == null ? null : request.getOrderId();
|
|
|
|
|
+ String safeOrderId = safeLogOrderId(orderId);
|
|
|
|
|
+ Long safeUserId = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ safeUserId = tokenUserResolver.requireUserId(token);
|
|
|
|
|
+ refundService.refund(safeUserId, orderId);
|
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
|
+ } catch (OmgPaymentBusinessException error) {
|
|
|
|
|
+ log.warn("OMG payment refund rejected orderId={}, userId={}, code={}",
|
|
|
|
|
+ safeOrderId, safeUserId, error.getCode());
|
|
|
|
|
+ return AjaxResult.error(MessageUtils.message(error.getMessageKey()),
|
|
|
|
|
+ new OmgPaymentErrorResponse(error.getCode().name()));
|
|
|
|
|
+ } catch (Exception error) {
|
|
|
|
|
+ log.error("OMG payment refund failed orderId={}, userId={}", safeOrderId, safeUserId, error);
|
|
|
|
|
+ return AjaxResult.error(MessageUtils.message("omg.pay.refund.failed"),
|
|
|
|
|
+ new OmgPaymentErrorResponse("PAYMENT_REFUND_FAILED"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
static String safeLogOrderId(String orderId) {
|
|
static String safeLogOrderId(String orderId) {
|
|
|
if (orderId == null) {
|
|
if (orderId == null) {
|
|
|
return "<empty>";
|
|
return "<empty>";
|