Files
apskel-pos-backend/internal/mappers/payment_method_mapper.go
T
efrilmandClaude Opus 5.5 2c9753fae7 feat(loyalty): remove paying with EnakPoint
EnakPoint can only be redeemed for vouchers now: it can no longer pay for
orders and is never cashed out (docs/enakgame-prd.md §3.2, EG-001,
EG-002). No order was ever paid with EnakPoint, so there is no data to
move.

Removed:
- POST /customer/wallet/payment-code, POST /customer/orders/:id/pay-with-points
  and GET /orders/:id/point-payment/preview, with their processors,
  repositories, services, handlers and tests.
- The point payment method type: paying, splitting and refunding with it,
  the outlet filter on the method list, and the system-method guard.
- points and payment_code on CreatePayment; points_used and point_value
  on payments; accepts_point_payment on the customer outlets.
- The outlet point_payment settings. A PUT that still sends them is
  rejected as an unknown field.
- The EnakPoint split in the payment method analytics.
- PAYMENT and PAYMENT_REFUND from the wallet type rules. Tests that used
  them as a generic EnakPoint debit use REWARD_REDEEM.
- The EnakPoint-paid part from the earning basis, which is
  subtotal − discount again.

Migration 000102 drops the trigger, the point methods and their index,
the payments columns, and the outlet settings, and restores the method
type CHECK without point. payments.payment_method_id is ON DELETE
RESTRICT, so it fails rather than lose a payment made with EnakPoint.

The integration docs list the removed endpoints and fields, and the
EnakPoint & EnakCoin PRD and tasks note what is superseded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 13:48:29 +07:00

181 lines
5.2 KiB
Go

package mappers
import (
"apskel-pos-be/internal/constants"
"apskel-pos-be/internal/contract"
"apskel-pos-be/internal/entities"
"apskel-pos-be/internal/models"
)
func CreatePaymentMethodRequestToEntity(req *models.CreatePaymentMethodRequest) *entities.PaymentMethod {
paymentMethod := &entities.PaymentMethod{
OrganizationID: req.OrganizationID,
Name: req.Name,
Type: entities.PaymentMethodType(req.Type),
Processor: req.Processor,
Configuration: entities.Metadata(req.Configuration),
IsActive: true, // Default to active
}
if req.IsActive != nil {
paymentMethod.IsActive = *req.IsActive
}
return paymentMethod
}
func UpdatePaymentMethodEntityFromRequest(entity *entities.PaymentMethod, req *models.UpdatePaymentMethodRequest) {
if req.Name != nil {
entity.Name = *req.Name
}
if req.Type != nil {
entity.Type = entities.PaymentMethodType(*req.Type)
}
if req.Processor != nil {
entity.Processor = req.Processor
}
if req.Configuration != nil {
entity.Configuration = entities.Metadata(req.Configuration)
}
if req.IsActive != nil {
entity.IsActive = *req.IsActive
}
}
func PaymentMethodEntityToResponse(entity *entities.PaymentMethod) *models.PaymentMethodResponse {
if entity == nil {
return nil
}
return &models.PaymentMethodResponse{
ID: entity.ID,
OrganizationID: entity.OrganizationID,
Name: entity.Name,
Type: constants.PaymentMethodType(entity.Type),
Processor: entity.Processor,
Configuration: map[string]interface{}(entity.Configuration),
IsActive: entity.IsActive,
CreatedAt: entity.CreatedAt,
UpdatedAt: entity.UpdatedAt,
}
}
func PaymentMethodEntityToModel(entity *entities.PaymentMethod) *models.PaymentMethod {
if entity == nil {
return nil
}
return &models.PaymentMethod{
ID: entity.ID,
OrganizationID: entity.OrganizationID,
Name: entity.Name,
Type: constants.PaymentMethodType(entity.Type),
Processor: entity.Processor,
Configuration: map[string]interface{}(entity.Configuration),
IsActive: entity.IsActive,
CreatedAt: entity.CreatedAt,
UpdatedAt: entity.UpdatedAt,
}
}
func PaymentMethodModelToEntity(model *models.PaymentMethod) *entities.PaymentMethod {
if model == nil {
return nil
}
return &entities.PaymentMethod{
ID: model.ID,
OrganizationID: model.OrganizationID,
Name: model.Name,
Type: entities.PaymentMethodType(model.Type),
Processor: model.Processor,
Configuration: entities.Metadata(model.Configuration),
IsActive: model.IsActive,
CreatedAt: model.CreatedAt,
UpdatedAt: model.UpdatedAt,
}
}
// Contract to Model mappers
func CreatePaymentMethodContractToModel(req *contract.CreatePaymentMethodRequest) *models.CreatePaymentMethodRequest {
return &models.CreatePaymentMethodRequest{
OrganizationID: req.OrganizationID,
OutletID: req.OutletID,
Name: req.Name,
Type: constants.PaymentMethodType(req.Type),
Processor: req.Processor,
Configuration: req.Configuration,
IsActive: req.IsActive,
}
}
func UpdatePaymentMethodContractToModel(req *contract.UpdatePaymentMethodRequest) *models.UpdatePaymentMethodRequest {
var paymentMethodType *constants.PaymentMethodType
if req.Type != nil {
pmt := constants.PaymentMethodType(*req.Type)
paymentMethodType = &pmt
}
return &models.UpdatePaymentMethodRequest{
Name: req.Name,
Type: paymentMethodType,
Processor: req.Processor,
Configuration: req.Configuration,
IsActive: req.IsActive,
}
}
func ListPaymentMethodsContractToModel(req *contract.ListPaymentMethodsRequest) *models.ListPaymentMethodsRequest {
var paymentMethodType *constants.PaymentMethodType
if req.Type != nil {
pmt := constants.PaymentMethodType(*req.Type)
paymentMethodType = &pmt
}
return &models.ListPaymentMethodsRequest{
OrganizationID: req.OrganizationID,
Type: paymentMethodType,
IsActive: req.IsActive,
Search: req.Search,
Page: req.Page,
Limit: req.Limit,
}
}
// Model to Contract mappers
func PaymentMethodResponseToContract(response *models.PaymentMethodResponse) *contract.PaymentMethodResponse {
if response == nil {
return nil
}
return &contract.PaymentMethodResponse{
ID: response.ID,
OrganizationID: response.OrganizationID,
Name: response.Name,
Type: string(response.Type),
Processor: response.Processor,
Configuration: response.Configuration,
IsActive: response.IsActive,
CreatedAt: response.CreatedAt,
UpdatedAt: response.UpdatedAt,
}
}
func ListPaymentMethodsResponseToContract(response *models.ListPaymentMethodsResponse) *contract.ListPaymentMethodsResponse {
paymentMethods := make([]contract.PaymentMethodResponse, len(response.PaymentMethods))
for i, pm := range response.PaymentMethods {
contractPM := PaymentMethodResponseToContract(&pm)
if contractPM != nil {
paymentMethods[i] = *contractPM
}
}
return &contract.ListPaymentMethodsResponse{
PaymentMethods: paymentMethods,
TotalCount: response.TotalCount,
Page: response.Page,
Limit: response.Limit,
TotalPages: response.TotalPages,
}
}