package api

import (
	"fmt"
	"net/http"

	"github.com/gin-gonic/gin"
)

func PaySingle(r *GinRouter) {
	r.POST("/single/alipay/callback", SingleAliCallBack)
	r.POST("/single/wechat/callback", SingleWechatCallBack)
}

func SingleAliCallBack(c *gin.Context, apictx *ApiSession) (interface{}, error) {

	fmt.Println(c)
	// 默认走阿里支付
	pay := PayMod(ALIPAY, SINGLE)

	res, err := pay.CallBack(c.Request)
	if err != nil {
		return false, NewError(err.Error())
	}
	c.String(http.StatusOK, res.(string))
	return nil, nil
}

func SingleWechatCallBack(c *gin.Context, apictx *ApiSession) (interface{}, error) {

	// 微信回调
	pay := PayMod(WECHATPAY, SINGLE)

	res, err := pay.CallBack(c.Request)
	if err != nil {
		// return false, NewError(err.Error())
		c.JSON(http.StatusOK, gin.H{"code": res, "message": err.Error()})
	}
	c.JSON(http.StatusOK, gin.H{"code": res, "message": "成功"})
	return nil, nil
}
