taldir

Directory service to resolve wallet mailboxes by messenger addresses
Log | Files | Refs | Submodules | README | LICENSE

commit 877761d2ef55888e062e08036a3b4ffd9460de92
parent accb3355fcd5b3f5666c13b7ada2cd2e207ed5c2
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Tue, 12 Jul 2022 14:06:44 +0200

add access token and baseurl configuration for merchant API

Diffstat:
Mcmd/taldir-server/testdata/taldir-test.conf | 12+++++++++++-
Mconfig/taldir-example.conf | 3+++
Mpkg/rest/taldir.go | 4+++-
Mpkg/taler/merchant.go | 17+++++++++--------
4 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/cmd/taldir-server/testdata/taldir-test.conf b/cmd/taldir-server/testdata/taldir-test.conf @@ -5,8 +5,18 @@ host = "https://taldir.net" bind_to = "localhost:11000" salt = "ChangeMe" monthly_fee = KUDOS:0 -request_frequency_microseconds = 10 validation_landing = testdata/templates/validation_landing.html +default_doc_filetype = text/markdown +default_doc_lang = en-US +default_tos_path = terms/ +default_pp_path = privacy/ +challenge_bytes = 16 +validation_initiation_max = 3 +solution_attempt_max = 3 +validation_timeframe = 10m +solution_attempt_timeframe = 1h +merchant_baseurl_private = http://merchant.taldir/instances/myInstance +merchant_token = superSecretToken [taldir-test] challenge_fee = KUDOS:0 diff --git a/config/taldir-example.conf b/config/taldir-example.conf @@ -14,6 +14,9 @@ validation_initiation_max = 3 solution_attempt_max = 3 validation_timeframe = 10m solution_attempt_timeframe = 1h +merchant_baseurl_private = http://merchant.taldir/instances/myInstance +merchant_token = superSecretToken +validation_landing = testdata/templates/validation_landing.html [taldir-email] sender = "taldir@taler.net" diff --git a/pkg/rest/taldir.go b/pkg/rest/taldir.go @@ -838,7 +838,9 @@ func (t *Taldir) Initialize(cfgfile string) { if "" == t.Salt { t.Salt = t.Cfg.Section("taldir").Key("salt").MustString("ChangeMe") } - t.Merchant = taler.NewMerchant("http://merchant.taldir", "myInstance") + merchUrl := t.Cfg.Section("taldir").Key("merchant_baseurl_private").MustString("http://merchant.taldir/instances/myInstance") + merchToken := t.Cfg.Section("taldir").Key("merchant_token").MustString("secretAccessToken") + t.Merchant = taler.NewMerchant(merchUrl, merchToken) t.setupHandlers() } diff --git a/pkg/taler/merchant.go b/pkg/taler/merchant.go @@ -95,23 +95,24 @@ type CheckPaymentPaytoResponse struct { type Merchant struct { // The host of this merchant - Host string; + BaseUrlPrivate string + + // The access token to use for the private API + AccessToken string - // The instance of this merchant - Instance string; } -func NewMerchant(merchHost string, merchInstance string) Merchant { +func NewMerchant(merchBaseUrlPrivate string, merchAccessToken string) Merchant { return Merchant{ - Host: merchHost, - Instance: merchInstance, + BaseUrlPrivate: merchBaseUrlPrivate, + AccessToken: merchAccessToken, } } func (m *Merchant) IsOrderPaid(orderId string) (string, error) { var orderPaidResponse CheckPaymentStatusResponse var paytoResponse CheckPaymentPaytoResponse - resp, err := http.Get(m.Host + "/instances/"+ m.Instance + "/private/orders/" + orderId) + resp, err := http.Get(m.BaseUrlPrivate + "/private/orders/" + orderId) if nil != err { return "", err } @@ -144,7 +145,7 @@ func (m *Merchant) AddNewOrder(cost float64, currency string) (string, error) { orderDetail.Summary = "This is an order to a TalDir registration" newOrder.order = orderDetail reqString, _ := json.Marshal(newOrder) - resp, err := http.Post(m.Host + "/instances/"+ m.Instance + "/private/orders", "application/json", bytes.NewBuffer(reqString)) + resp, err := http.Post(m.BaseUrlPrivate + "/private/orders", "application/json", bytes.NewBuffer(reqString)) if nil != err { return "", err