treasurer/internal/utils/yoomoney.go

44 lines
1020 B
Go
Raw Normal View History

2023-06-13 13:22:51 +00:00
package utils
import (
"encoding/base64"
"fmt"
"strings"
2024-12-16 13:47:40 +00:00
"gitea.pena/PenaSide/treasurer/internal/proto/treasurer"
"gitea.pena/PenaSide/treasurer/internal/models/yandex"
2023-06-13 13:22:51 +00:00
)
func ConvertYoomoneySercetsToAuth(authType, storeID, secretKey string) string {
credentials := fmt.Sprintf("%s:%s", storeID, secretKey)
encoded := base64.StdEncoding.EncodeToString([]byte(credentials))
trimedAuthType := strings.TrimSpace(authType)
return fmt.Sprintf("%s %s", trimedAuthType, encoded)
}
func ProtoItem2ReceiptItem(in *treasurer.Item) yandex.Item {
return yandex.Item{
Description: in.Description,
Amount: yandex.ReceiptAmount{
Value: in.Money,
Currency: in.Currency,
},
VatCode: 1,
2024-05-06 19:23:15 +00:00
Quantity: 1,
Measure: in.Measure,
PaymentSubject: "service",
2024-05-03 18:36:34 +00:00
PaymentMode: "full_prepayment",
}
}
func ProtoItems2ReceiptItems(in []*treasurer.Item) []yandex.Item {
length := len(in)
out := make([]yandex.Item, length, length)
for i, item := range in {
out[i] = ProtoItem2ReceiptItem(item)
}
return out
}