39 lines
740 B
Go
39 lines
740 B
Go
package voucher
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"git.tornberg.me/go-cart-actor/pkg/messages"
|
|
)
|
|
|
|
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) (*messages.AddVoucher, error) {
|
|
if code == "" {
|
|
return nil, ErrInvalidCode
|
|
}
|
|
value := int64(250_00)
|
|
return &messages.AddVoucher{
|
|
Code: code,
|
|
Value: value,
|
|
VoucherRules: make([]*messages.VoucherRule, 0),
|
|
}, nil
|
|
}
|