Reapply "feat(loyalty): EnakPoint & EnakCoin" (#32)

This reverts commit 4e24f9bbb0.
This commit is contained in:
efrilm
2026-09-30 15:31:44 +07:00
parent 4e24f9bbb0
commit 582dc75543
195 changed files with 20058 additions and 2177 deletions
+55
View File
@@ -0,0 +1,55 @@
package service
import (
"context"
"errors"
"github.com/google/uuid"
"apskel-pos-be/internal/appcontext"
"apskel-pos-be/internal/constants"
"apskel-pos-be/internal/contract"
"apskel-pos-be/internal/processor"
"apskel-pos-be/internal/repository"
)
// PointPaymentService serves what the cashier needs before taking EnakPoint
// (docs/prd-point-coin.md F9).
type PointPaymentService interface {
Preview(ctx context.Context, apctx *appcontext.ContextInfo, orderID uuid.UUID) *contract.Response
}
type PointPaymentServiceImpl struct {
payments *processor.PointPaymentProcessor
}
func NewPointPaymentService(payments *processor.PointPaymentProcessor) *PointPaymentServiceImpl {
return &PointPaymentServiceImpl{payments: payments}
}
func (s *PointPaymentServiceImpl) Preview(ctx context.Context, apctx *appcontext.ContextInfo, orderID uuid.UUID) *contract.Response {
preview, err := s.payments.Preview(ctx, apctx.OrganizationID, orderID)
if err != nil {
return PointPaymentErrorResponse(err)
}
return contract.BuildSuccessResponse(preview)
}
// PointPaymentErrorResponse answers a refused EnakPoint payment as a bad request, PIN
// problems with their own codes, and anything else as a server error.
func PointPaymentErrorResponse(err error) *contract.Response {
var pinErr *processor.PinError
if errors.As(err, &pinErr) {
return PinErrorResponse(err)
}
code := constants.InternalServerErrorCode
switch {
case errors.Is(err, repository.ErrPointPaymentOrderNotFound):
code = constants.NotFoundErrorCode
case errors.Is(err, processor.ErrPointPaymentRejected):
code = constants.ValidationErrorCode
}
return contract.BuildErrorResponse([]*contract.ResponseError{
contract.NewResponseError(code, constants.WalletServiceEntity, err.Error()),
})
}