Files
go-cart-actor/pkg/voucher/service.go
matst80 0b9c14c231
All checks were successful
Build and Publish / Metadata (push) Successful in 8s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 1m12s
Build and Publish / BuildAndDeployArm64 (push) Successful in 4m9s
more
2025-10-14 12:30:12 +02:00

41 lines
723 B
Go

package voucher
import (
"errors"
"math"
)
type Rule struct {
Type string `json:"type"`
Value int64 `json:"value"`
}
type Voucher struct {
Code string `json:"code"`
Value int64 `json:"discount"`
TaxValue int64 `json:"taxValue"`
TaxRate int `json:"taxRate"`
rules []Rule `json:"rules"`
}
type Service struct {
// Add fields here
}
var ErrInvalidCode = errors.New("invalid vouchercode")
func (s *Service) GetVoucher(code string) (*Voucher, error) {
value := int64(math.Round(100 * math.Pow(10, 2)))
if code == "" {
return nil, ErrInvalidCode
}
return &Voucher{
Code: code,
Value: value,
TaxValue: int64(float64(value) * 0.2),
TaxRate: 2500,
rules: nil,
}, nil
}