83 lines
2.1 KiB
Go
83 lines
2.1 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
|
|
//
|
|
// @Router /v1/orders [post]
|
|
// @Summary Create Order
|
|
// @Description Create Order
|
|
// @Tags Transaction
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param form body dto.OrderCreateForm true "Create form"
|
|
// @Success 200 {object} dto.OrderCreateResponse
|
|
// @Bind form body
|
|
func (t *Transaction) Create(ctx fiber.Ctx, form *dto.OrderCreateForm) (*dto.OrderCreateResponse, error) {
|
|
return services.Order.Create(ctx.Context(), form)
|
|
}
|
|
|
|
// Pay for order
|
|
//
|
|
// @Router /v1/orders/:id/pay [post]
|
|
// @Summary Pay for order
|
|
// @Description Pay for order
|
|
// @Tags Transaction
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path string true "Order ID"
|
|
// @Param form body dto.OrderPayForm true "Pay form"
|
|
// @Success 200 {object} dto.OrderPayResponse
|
|
// @Bind id path
|
|
// @Bind form body
|
|
func (t *Transaction) Pay(ctx fiber.Ctx, id string, form *dto.OrderPayForm) (*dto.OrderPayResponse, error) {
|
|
return services.Order.Pay(ctx.Context(), id, form)
|
|
}
|
|
|
|
// Check order payment status
|
|
//
|
|
// @Router /v1/orders/:id/status [get]
|
|
// @Summary Check order status
|
|
// @Description Check order payment status
|
|
// @Tags Transaction
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path string true "Order ID"
|
|
// @Success 200 {object} dto.OrderStatusResponse
|
|
// @Bind id path
|
|
func (t *Transaction) Status(ctx fiber.Ctx, id string) (*dto.OrderStatusResponse, error) {
|
|
return services.Order.Status(ctx.Context(), id)
|
|
}
|
|
|
|
type WebhookForm struct {
|
|
OrderID string `json:"order_id"`
|
|
ExternalID string `json:"external_id"`
|
|
}
|
|
|
|
// Payment Webhook
|
|
//
|
|
// @Router /v1/webhook/payment/notify [post]
|
|
// @Summary Payment Webhook
|
|
// @Description Payment Webhook
|
|
// @Tags Transaction
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param form body WebhookForm true "Webhook Data"
|
|
// @Success 200 {string} string "success"
|
|
// @Bind form body
|
|
func (t *Transaction) Webhook(ctx fiber.Ctx, form *WebhookForm) (string, error) {
|
|
err := services.Order.ProcessExternalPayment(ctx.Context(), form.OrderID, form.ExternalID)
|
|
if err != nil {
|
|
return "fail", err
|
|
}
|
|
return "success", nil
|
|
}
|