36 lines
1.2 KiB
Go
36 lines
1.2 KiB
Go
package handler
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
|
||
|
|
"apskel-pos-be/internal/contract"
|
||
|
|
"apskel-pos-be/internal/service"
|
||
|
|
"apskel-pos-be/internal/util"
|
||
|
|
)
|
||
|
|
|
||
|
|
// CustomerOrderPaymentHandler serves POST /customer/orders/:id/pay-with-points
|
||
|
|
// (docs/prd-point-coin.md F9). The body holds the PIN, so it is never logged.
|
||
|
|
type CustomerOrderPaymentHandler struct {
|
||
|
|
payments service.CustomerOrderPaymentService
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewCustomerOrderPaymentHandler(payments service.CustomerOrderPaymentService) *CustomerOrderPaymentHandler {
|
||
|
|
return &CustomerOrderPaymentHandler{payments: payments}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (h *CustomerOrderPaymentHandler) PayWithPoints(c *gin.Context) {
|
||
|
|
customerID, ok := customerIDFromGin(c, "CustomerOrderPaymentHandler::PayWithPoints")
|
||
|
|
if !ok {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
orderID, ok := parseUUIDParam(c, "id", "CustomerOrderPaymentHandler::PayWithPoints")
|
||
|
|
if !ok {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
var req contract.PayWithPointsRequest
|
||
|
|
if !bindPinRequest(c, &req, "CustomerOrderPaymentHandler::PayWithPoints") {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
util.HandleResponse(c.Writer, c.Request, h.payments.PayWithPoints(c.Request.Context(), customerID, orderID, &req, pinRequestInfo(c)), "CustomerOrderPaymentHandler::PayWithPoints")
|
||
|
|
}
|