✨ Configurable discount size
This commit is contained in:
parent
80739eab52
commit
9ea1012f19
@ -9,24 +9,25 @@ import (
|
|||||||
wproto "git.solsynth.dev/hypernet/wallet/pkg/proto"
|
wproto "git.solsynth.dev/hypernet/wallet/pkg/proto"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DiscountFileSize = 52428800 // 50 MiB
|
|
||||||
|
|
||||||
// PlaceOrder create a transaction if needed for user
|
// PlaceOrder create a transaction if needed for user
|
||||||
// Pricing according here: https://kb.solsynth.dev/solar-network/wallet#file-uploads
|
// Pricing according here: https://kb.solsynth.dev/solar-network/wallet#file-uploads
|
||||||
func PlaceOrder(user uint, filesize int64, withDiscount bool) error {
|
func PlaceOrder(user uint, filesize int64, withDiscount bool) error {
|
||||||
if filesize <= DiscountFileSize && withDiscount {
|
discountFileSize := viper.GetInt64("payment.discount")
|
||||||
|
|
||||||
|
if filesize <= discountFileSize && withDiscount {
|
||||||
// Discount included
|
// Discount included
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var amount float64
|
var amount float64
|
||||||
if withDiscount {
|
if withDiscount {
|
||||||
billableSize := filesize - DiscountFileSize
|
billableSize := filesize - discountFileSize
|
||||||
amount = float64(billableSize) / 1024 / 1024 * 1
|
amount = float64(billableSize) / 1024 / 1024 * 1
|
||||||
} else if filesize > DiscountFileSize {
|
} else if filesize > discountFileSize {
|
||||||
amount = 50 + float64(filesize-DiscountFileSize)/1024/1024*5
|
amount = 50 + float64(filesize-discountFileSize)/1024/1024*5
|
||||||
} else {
|
} else {
|
||||||
amount = float64(filesize) / 1024 / 1024 * 1
|
amount = float64(filesize) / 1024 / 1024 * 1
|
||||||
}
|
}
|
||||||
|
@ -26,3 +26,6 @@ access_baseurl = "http://192.168.50.133:8004"
|
|||||||
|
|
||||||
[security]
|
[security]
|
||||||
internal_public_key = "keys/internal_public_key.pem"
|
internal_public_key = "keys/internal_public_key.pem"
|
||||||
|
|
||||||
|
[payment]
|
||||||
|
discount = 52428800
|
||||||
|
Loading…
x
Reference in New Issue
Block a user