35 lines
1.2 KiB
Go
35 lines
1.2 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"apskel-pos-be/internal/contract"
|
|
"apskel-pos-be/internal/models"
|
|
"apskel-pos-be/internal/processor"
|
|
"apskel-pos-be/internal/transformer"
|
|
)
|
|
|
|
// CustomerOrderPaymentService lets customers pay their own orders with EnakPoint in the
|
|
// app or a self-order (docs/prd-point-coin.md F9).
|
|
type CustomerOrderPaymentService interface {
|
|
PayWithPoints(ctx context.Context, customerID, orderID uuid.UUID, req *contract.PayWithPointsRequest, info models.CustomerPinRequestInfo) *contract.Response
|
|
}
|
|
|
|
type CustomerOrderPaymentServiceImpl struct {
|
|
orders processor.OrderProcessor
|
|
}
|
|
|
|
func NewCustomerOrderPaymentService(orders processor.OrderProcessor) *CustomerOrderPaymentServiceImpl {
|
|
return &CustomerOrderPaymentServiceImpl{orders: orders}
|
|
}
|
|
|
|
func (s *CustomerOrderPaymentServiceImpl) PayWithPoints(ctx context.Context, customerID, orderID uuid.UUID, req *contract.PayWithPointsRequest, info models.CustomerPinRequestInfo) *contract.Response {
|
|
payment, err := s.orders.PayWithPointsInApp(ctx, customerID, orderID, req.Points, req.Pin, info)
|
|
if err != nil {
|
|
return PointPaymentErrorResponse(err)
|
|
}
|
|
return contract.BuildSuccessResponse(transformer.PaymentModelToContract(payment))
|
|
}
|