diff --git a/config/config.go b/config/config.go index d1af7e8..1a44d2a 100644 --- a/config/config.go +++ b/config/config.go @@ -18,6 +18,7 @@ const ( AliasPrefix = "api/v1/alias" SendSMSPrefix = "api/v1/external/upsell" AliasEnsPrefix = "/api/v1/bypass" + ExternalSMSPrefix = "/api/v1/external" ) var ( @@ -25,6 +26,7 @@ var ( dataURLBase string BearerToken string aliasEnsURLBase string + externalSMSBase string ) var ( @@ -39,6 +41,7 @@ var ( CheckAliasURL string SendSMSURL string AliasEnsURL string + ExternalSMSURL string ) func setBase() error { @@ -47,6 +50,7 @@ func setBase() error { custodialURLBase = env.GetEnv("CUSTODIAL_URL_BASE", "http://localhost:5003") dataURLBase = env.GetEnv("DATA_URL_BASE", "http://localhost:5006") aliasEnsURLBase = env.GetEnv("ALIAS_ENS_BASE", "http://localhost:5015") + externalSMSBase = env.GetEnv("EXTERNAL_SMS_BASE", "http://localhost:5035") BearerToken = env.GetEnv("BEARER_TOKEN", "") _, err = url.Parse(custodialURLBase) @@ -77,5 +81,7 @@ func LoadConfig() error { CheckAliasURL, _ = url.JoinPath(dataURLBase, AliasPrefix) SendSMSURL, _ = url.JoinPath(dataURLBase, SendSMSPrefix) AliasEnsURL, _ = url.JoinPath(aliasEnsURLBase, AliasEnsPrefix) + ExternalSMSURL, _ = url.JoinPath(externalSMSBase, ExternalSMSPrefix) + return nil } diff --git a/dev/api.go b/dev/api.go index f2e0a45..8c7ef90 100644 --- a/dev/api.go +++ b/dev/api.go @@ -660,3 +660,11 @@ func (das *DevAccountService) SendUpsellSMS(ctx context.Context, inviterPhone, i Invitee: inviteePhone, }, nil } + +func (das *DevAccountService) SendPINResetSMS(ctx context.Context, admin, phone string) error { + return fmt.Errorf("unimplemented") +} + +func (das *DevAccountService) SendAddressSMS(ctx context.Context, publicKey, originPhone string) error { + return fmt.Errorf("unimplemented") +} diff --git a/remote/account_service.go b/remote/account_service.go index 07e697e..3a1b3ab 100644 --- a/remote/account_service.go +++ b/remote/account_service.go @@ -18,4 +18,6 @@ type AccountService interface { CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) RequestAlias(ctx context.Context, hint string, publicKey string) (*models.RequestAliasResult, error) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) + SendAddressSMS(ctx context.Context, publicKey, originPhone string) error + SendPINResetSMS(ctx context.Context, admin, phone string) error } diff --git a/remote/http/service.go b/remote/http/service.go index 7ddccde..3810af3 100644 --- a/remote/http/service.go +++ b/remote/http/service.go @@ -344,6 +344,56 @@ func (as *HTTPAccountService) SendUpsellSMS(ctx context.Context, inviterPhone, i return &r, nil } +func (as *HTTPAccountService) SendAddressSMS(ctx context.Context, publicKey, originPhone string) error { + ep, err := url.JoinPath(config.ExternalSMSURL, "address") + if err != nil { + return err + } + logg.InfoCtxf(ctx, "sending an address sms", "endpoint", ep, "address", publicKey, "origin-phone", originPhone) + payload := map[string]string{ + "address": publicKey, + "originPhone": originPhone, + } + payloadBytes, err := json.Marshal(payload) + if err != nil { + return err + } + req, err := http.NewRequest("POST", ep, bytes.NewBuffer(payloadBytes)) + if err != nil { + return err + } + _, err = doRequest(ctx, req, nil) + if err != nil { + return err + } + return nil +} + +func (as *HTTPAccountService) SendPINResetSMS(ctx context.Context, admin, phone string) error { + ep, err := url.JoinPath(config.ExternalSMSURL, "pinreset") + if err != nil { + return err + } + logg.InfoCtxf(ctx, "sending pin reset sms", "endpoint", ep, "admin", admin, "phone", phone) + payload := map[string]string{ + "admin": admin, + "phone": phone, + } + payloadBytes, err := json.Marshal(payload) + if err != nil { + return err + } + req, err := http.NewRequest("POST", ep, bytes.NewBuffer(payloadBytes)) + if err != nil { + return err + } + _, err = doRequest(ctx, req, nil) + if err != nil { + return err + } + return nil +} + // TODO: remove eth-custodial api dependency func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) { var okResponse api.OKResponse diff --git a/testutil/mocks/service_mock.go b/testutil/mocks/service_mock.go index b2cc015..e6bdd5e 100644 --- a/testutil/mocks/service_mock.go +++ b/testutil/mocks/service_mock.go @@ -62,3 +62,11 @@ func (m *MockAccountService) SendUpsellSMS(ctx context.Context, inviterPhone, in args := m.Called(inviterPhone, inviteePhone) return args.Get(0).(*models.SendSMSResponse), args.Error(1) } + +func (m *MockAccountService) SendPINResetSMS(ctx context.Context, admin, phone string) error { + return nil +} + +func (m *MockAccountService) SendAddressSMS(ctx context.Context, publicKey, originPhone string) error { + return nil +} diff --git a/testutil/testservice/account_service.go b/testutil/testservice/account_service.go index 1d1e9f3..abb7c92 100644 --- a/testutil/testservice/account_service.go +++ b/testutil/testservice/account_service.go @@ -57,14 +57,22 @@ func (tas *TestAccountService) TokenTransfer(ctx context.Context, amount, from, }, nil } -func (m TestAccountService) CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) { +func (m *TestAccountService) CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) { return &models.AliasAddress{}, nil } -func (m TestAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) { +func (m *TestAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) { return &models.RequestAliasResult{}, nil } -func (m TestAccountService) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) { +func (m *TestAccountService) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) { return &models.SendSMSResponse{}, nil } + +func (m *TestAccountService) SendAddressSMS(ctx context.Context, publicKey, originPhone string) error { + return nil +} + +func (m *TestAccountService) SendPINResetSMS(ctx context.Context, admin, phone string) error { + return nil +}