package com.kxs.common.pay.handlers;

import com.alipay.api.AlipayApiException;
import com.kxs.common.pay.factory.PaymentFactory;
import com.kxs.common.pay.service.PayService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 支付事件处理程序
 *
 * @author 没秃顶的码农
 * @date 2024-04-28
 */
@RestController
@RequestMapping("/pay")
@RequiredArgsConstructor
public class PayEventHandlers {

    private final PaymentFactory paymentFactory;


    @RequestMapping(value = "payBack/{platform}")
    public String payBack(HttpServletRequest request, @PathVariable String platform) {
        try {
            PayService payService = paymentFactory.getPayService(platform);
            return payService.payBack(request);
        } catch (AlipayApiException e) {
            throw new RuntimeException(e);
        }
    }

}
