From 9ea1012f1991eeedcafcb0cc7aecbfa88f29a485 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 29 Jan 2025 19:14:37 +0800 Subject: [PATCH] :sparkles: Configurable discount size --- pkg/internal/services/payment.go | 13 +++++++------ settings.toml | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/internal/services/payment.go b/pkg/internal/services/payment.go index b4076bd..96e8ec3 100644 --- a/pkg/internal/services/payment.go +++ b/pkg/internal/services/payment.go @@ -9,24 +9,25 @@ import ( wproto "git.solsynth.dev/hypernet/wallet/pkg/proto" "github.com/rs/zerolog/log" "github.com/samber/lo" + "github.com/spf13/viper" ) -const DiscountFileSize = 52428800 // 50 MiB - // PlaceOrder create a transaction if needed for user // Pricing according here: https://kb.solsynth.dev/solar-network/wallet#file-uploads func PlaceOrder(user uint, filesize int64, withDiscount bool) error { - if filesize <= DiscountFileSize && withDiscount { + discountFileSize := viper.GetInt64("payment.discount") + + if filesize <= discountFileSize && withDiscount { // Discount included return nil } var amount float64 if withDiscount { - billableSize := filesize - DiscountFileSize + billableSize := filesize - discountFileSize amount = float64(billableSize) / 1024 / 1024 * 1 - } else if filesize > DiscountFileSize { - amount = 50 + float64(filesize-DiscountFileSize)/1024/1024*5 + } else if filesize > discountFileSize { + amount = 50 + float64(filesize-discountFileSize)/1024/1024*5 } else { amount = float64(filesize) / 1024 / 1024 * 1 } diff --git a/settings.toml b/settings.toml index 0207060..3af723e 100644 --- a/settings.toml +++ b/settings.toml @@ -26,3 +26,6 @@ access_baseurl = "http://192.168.50.133:8004" [security] internal_public_key = "keys/internal_public_key.pem" + +[payment] +discount = 52428800