commit c8dcd347e240bd64b884bd618aaaf804266d83db
parent 1c0d2d4c00c208a222fe231889311587bd0124a5
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date: Sat, 16 Dec 2023 13:17:23 +0100
Get currency spec and config from merchant
Diffstat:
2 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/go.mod b/go.mod
@@ -5,7 +5,7 @@ go 1.18
require (
github.com/google/uuid v1.4.0
github.com/gorilla/mux v1.8.1
- github.com/schanzen/taler-go v1.0.0
+ github.com/schanzen/taler-go v1.0.3
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
gopkg.in/ini.v1 v1.67.0
)
diff --git a/pkg/rest/gnsregistrar.go b/pkg/rest/gnsregistrar.go
@@ -152,6 +152,9 @@ type Registrar struct {
// Cost for a registration
RegistrationCost *talerutil.Amount
+ // Cost for a registration
+ CurrencySpec talerutil.CurrencySpecification
+
}
type VersionResponse struct {
@@ -439,7 +442,7 @@ func (t *Registrar) editRegistration(w http.ResponseWriter, r *http.Request) {
registeredUntilStr := registeredUntil.Format(time.DateTime)
remainingDays := int64(time.Until(registeredUntil).Hours() / 24)
extendedExpiration := time.UnixMicro(int64(regMetadata.Expiration)).Add(t.RelativeRegistrationExpiration).Format(time.DateTime)
- cost, _ := t.RegistrationCost.Format()
+ cost, _ := t.RegistrationCost.FormatWithCurrencySpecification(t.CurrencySpec)
fullData := map[string]interface{}{
"label": vars["label"],
"zkey": value,
@@ -562,7 +565,7 @@ func (t *Registrar) buyPage(w http.ResponseWriter, r *http.Request) {
}
}
encodedPng := base64.StdEncoding.EncodeToString(qrPng)
- cost, _ := t.RegistrationCost.Format()
+ cost, _ := t.RegistrationCost.FormatWithCurrencySpecification(t.CurrencySpec)
fullData := map[string]interface{}{
"qrCode": template.URL("data:image/png;base64," + encodedPng),
"payto": template.URL(payto),
@@ -727,7 +730,7 @@ func (t *Registrar) namePage(w http.ResponseWriter, r *http.Request) {
remainingDays = int64(time.Until(registeredUntil).Hours() / 24)
}
}
- cost, _ := t.RegistrationCost.Format()
+ cost, _ := t.RegistrationCost.FormatWithCurrencySpecification(t.CurrencySpec)
fullData := map[string]interface{}{
"label": vars["label"],
"error": r.URL.Query().Get("error"),
@@ -768,7 +771,7 @@ func (t *Registrar) setupHandlers() {
// Initialize the gnsregistrar instance with cfgfile
func (t *Registrar) Initialize(cfgfile string) {
var identityResponse IdentityInfo
- _cfg, err := ini.Load(cfgfile)
+ _cfg, err := ini.LooseLoad(cfgfile)
if err != nil {
fmt.Printf("Failed to read config: %v", err)
os.Exit(1)
@@ -850,5 +853,16 @@ func (t *Registrar) Initialize(cfgfile string) {
merchURL := t.Cfg.Section("gns-registrar").Key("base_url_merchant").MustString("https://backend.demo.taler.net")
merchToken := t.Cfg.Section("gns-registrar").Key("merchant_token").MustString("sandbox")
t.Merchant = merchant.NewMerchant(merchURL, merchToken)
+ merchConfig, err := t.Merchant.GetConfig()
+ if nil != err {
+ fmt.Printf("Failed to get merchant config")
+ os.Exit(1)
+ }
+ currencySpec, currencySupported := merchConfig.Currencies[t.RegistrationCost.Currency]
+ for !currencySupported {
+ fmt.Printf("Currency `%s' not supported by merchant!\n", t.RegistrationCost.Currency)
+ os.Exit(1)
+ }
+ t.CurrencySpec = currencySpec
t.setupHandlers()
}