package com.ai.da.controller;

import com.ai.da.common.response.Response;
import com.ai.da.model.dto.ProductPurchaseDTO;
import com.ai.da.service.AlipayHKService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@CrossOrigin
@RestController
@RequestMapping("/api/alipay-hk")
@Api(tags = "网站支付 香港支付宝")
@Slf4j
public class AlipayHKController {

    @Resource
    private AlipayHKService alipayHKService;

    @ApiOperation(value = "创建订单")
    @PostMapping(value = "/createOrder")
    public Response<String> createOrder(@Valid @RequestBody ProductPurchaseDTO productPurchaseDTO, HttpServletRequest request) {
        String order = alipayHKService.createOrder(productPurchaseDTO, request);
        return Response.success(order);
    }

    @ApiOperation("支付通知")
    @PostMapping("/trade/notify")
    public String callback(@RequestBody String paramString){
        log.info("alipay-hk callback parameter : {}", paramString);
        return alipayHKService.callback(paramString);
    }

    @ApiOperation("订单查询")
    @PostMapping("/trade/query/{orderRef}")
    public Response<String> queryOrder(@PathVariable String orderRef){
        String s = alipayHKService.queryDetail(orderRef);
        return Response.success(s);
    }



}
