treasurer/internal/utils/yoomoney.go

44 lines
1.0 KiB
Go

package utils
import (
"encoding/base64"
"fmt"
"strings"
"penahub.gitlab.yandexcloud.net/external/treasurer/internal/proto/treasurer"
"penahub.gitlab.yandexcloud.net/external/treasurer/internal/models/yandex"
)
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,
Quantity: in.Quantity,
Measure: in.Measure,
PaymentSubject: "service",
PaymentMode: "full_payment",
}
}
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
}