ManualHandlerApi.java 2.29 KB
package com.diligrp.cashier.mall.api;

import com.diligrp.cashier.mall.context.MallInitializeContext;
import com.diligrp.cashier.mall.dao.MallBizRefundDao;
import com.diligrp.cashier.mall.model.MallBizPayment;
import com.diligrp.cashier.mall.model.MallBizRefund;
import com.diligrp.cashier.mall.service.biz.MallBizPaymentService;
import com.diligrp.cashier.shared.domain.Message;
import com.diligrp.cashier.shared.spi.IPaymentEventListener;
import com.diligrp.cashier.shared.spi.domain.PaymentResultBO;
import com.diligrp.cashier.shared.spi.domain.RefundResultBO;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName ManualHandlerApi.java
 * @author dengwei
 * @version 1.0.0
 * @Description ManualHandlerApi
 */
@RestController
@RequestMapping(path = "/mall/manual")
@Validated
public class ManualHandlerApi {
    @Resource
    private IPaymentEventListener payNotifyServiceImpl;
    @Resource
    private MallBizPaymentService mallBizPaymentService;
    @Resource
    private MallBizRefundDao mallBizRefundDao;


    @PostMapping("/payment/event")
    public Message<?> handlePaymentEvent(@RequestBody PaymentResultBO payment) {
        payNotifyServiceImpl.onEvent(payment);
        return Message.success();
    }

    @PostMapping("/refund/event")
    public Message<?> handlePaymentEvent(@RequestBody RefundResultBO refund) {
        payNotifyServiceImpl.onEvent(refund);
        return Message.success();
    }

    @PostMapping("/payment/callback/{source}")
    public Message<?> paymentCallback(@RequestBody PaymentResultBO payment, @PathVariable("source") Integer source) {
        String tradeId = payment.getTradeId();
        MallBizPayment mallBizPayment = mallBizPaymentService.getByPayTradeId(tradeId);
        MallInitializeContext.getBySource(source).payCallBack(payment, mallBizPayment);
        return Message.success();
    }

    @PostMapping("/refund/callback/{source}")
    public Message<?> refundCallback(@RequestBody RefundResultBO refund, @PathVariable("source") Integer source) {
        MallBizRefund mallBizRefund = mallBizRefundDao.getByRefundTradeId(refund.getRefundId());
        MallInitializeContext.getBySource(source).refundCallBack(refund, mallBizRefund);
        return Message.success();
    }

}