Files
quyun-v2/backend/app/http/v1/transaction.go

83 lines
2.3 KiB
Go

package v1
import (
"quyun/v2/app/http/v1/dto"
"quyun/v2/app/services"
"github.com/gofiber/fiber/v3"
)
// @provider
type Transaction struct{}
// Create Order
//
// @Summary Create Order
// @Description 创建订单
// @Tags Transaction
// @Accept json
// @Produce json
// @Param form body dto.OrderCreateForm true "订单创建参数"
// @Success 200 {object} dto.OrderCreateResponse
// @Router /v1/t/:tenantCode/orders [post]
// @Bind form body
func (t *Transaction) Create(ctx fiber.Ctx, form *dto.OrderCreateForm) (*dto.OrderCreateResponse, error) {
tenantID := getTenantID(ctx)
uid := getUserID(ctx)
return services.Order.Create(ctx, tenantID, uid, form)
}
// Pay Order
//
// @Summary Pay Order
// @Description 支付订单
// @Tags Transaction
// @Accept json
// @Produce json
// @Param id path int64 true "订单ID"
// @Param form body dto.OrderPayForm true "支付参数"
// @Success 200 {object} dto.OrderPayResponse
// @Router /v1/t/:tenantCode/orders/:id<int>/pay [post]
// @Bind id path
// @Bind form body
func (t *Transaction) Pay(ctx fiber.Ctx, id int64, form *dto.OrderPayForm) (*dto.OrderPayResponse, error) {
tenantID := getTenantID(ctx)
uid := getUserID(ctx)
return services.Order.Pay(ctx, tenantID, uid, id, form)
}
// Order Status
//
// @Summary Order Status
// @Description 查询订单状态
// @Tags Transaction
// @Accept json
// @Produce json
// @Param id path int64 true "订单ID"
// @Success 200 {object} dto.OrderStatusResponse
// @Router /v1/t/:tenantCode/orders/:id<int>/status [get]
// @Bind id path
func (t *Transaction) Status(ctx fiber.Ctx, id int64) (*dto.OrderStatusResponse, error) {
tenantID := getTenantID(ctx)
uid := getUserID(ctx)
return services.Order.Status(ctx, tenantID, uid, id)
}
// @Summary Payment Webhook
// @Description Payment Webhook
// @Tags Transaction
// @Accept json
// @Produce json
// @Param form body dto.PaymentWebhookForm true "Webhook Data"
// @Success 200 {string} string "success"
// @Router /v1/t/:tenantCode/webhook/payment/notify [post]
// @Bind form body
func (t *Transaction) Webhook(ctx fiber.Ctx, form *dto.PaymentWebhookForm) (string, error) {
tenantID := getTenantID(ctx)
err := services.Order.ProcessExternalPayment(ctx, tenantID, form.OrderID, form.ExternalID)
if err != nil {
return "fail", err
}
return "success", nil
}