package cn.ysk.cashier.controller;

import cn.ysk.cashier.annotation.AnonymousAccess;
import cn.ysk.cashier.annotation.rest.AnonymousGetMapping;
import cn.ysk.cashier.annotation.rest.AnonymousPostMapping;
import cn.ysk.cashier.service.order.TbOrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 回调接口
 */
@Slf4j
@RestController

@RequestMapping("/notify")
public class NotifyController {

    private final TbOrderInfoService orderInfoService;

    public NotifyController(TbOrderInfoService orderInfoService) {
        this.orderInfoService = orderInfoService;
    }

    @AnonymousAccess
    @RequestMapping("/fstPay")
    public Object fstPay(@RequestBody Map<String, String> req) {
        log.info("接收到福商通支付回调: {}", req);
        orderInfoService.successPay(req);
        return "SUCCESS";
    }

    @AnonymousAccess
    @RequestMapping("/fstReturn")
    public Object fstReturn(@RequestBody Map<String, String> req) {
        log.info("接收到福商通退款回调: {}", req);
        orderInfoService.successReturn(req);
        return "SUCCESS";
    }
}
