Compare commits

...

21 Commits

Author SHA1 Message Date
Carlosokumu
341901ec83 match new external sms endpoint 2025-04-28 11:26:13 +03:00
Carlosokumu
ed416c57c7 chore: rename EXTRA_SMS_BASE to EXTERNAL_SMS_BASE 2025-04-28 11:15:11 +03:00
Carlosokumu
6fc99661f7 chore: remove extra underscore in EXTRA_SMS_BASE env identifier 2025-04-28 11:08:39 +03:00
Carlosokumu
d509477de3 remove accidentallypushed bearer token 2025-04-28 11:03:34 +03:00
Carlosokumu
4ea8fd1f04 chore: rename extrasms prefixes to external sms 2025-04-28 10:56:05 +03:00
Carlosokumu
5c0ed48e67 add required sms methods 2025-04-17 23:14:42 +03:00
Carlosokumu
5ff139b649 add expected accountservice methods 2025-04-17 23:07:33 +03:00
Carlosokumu
86cfb9c020 match expected method signature 2025-04-17 22:18:30 +03:00
Carlosokumu
58366274c3 add required AccountService methods 2025-04-17 18:58:12 +03:00
Carlosokumu
b85511e436 implement SendPINResetSMS and SendAddressSMS 2025-04-17 18:57:24 +03:00
Carlosokumu
a243fe8c29 add SendAddressSMS and SendPINResetSMS 2025-04-17 18:57:02 +03:00
Carlosokumu
492b101aa4 setup extra sms api endpoints 2025-04-17 18:56:20 +03:00
34957e5b6f Merge pull request 'sms-upsell-api' (#10) from sms-api into master
Reviewed-on: #10
2025-04-11 10:06:08 +02:00
alfred-mk
6597d6b6a2 added the SendUpsellSMS to DevAccountService and MockApi 2025-04-11 11:02:23 +03:00
Carlosokumu
441e289854 implement SendUpsellSMs 2025-04-01 15:25:10 +03:00
Carlosokumu
5b41c8dc64 chore: rename SendSMS to SendUpsellSMS 2025-04-01 14:55:03 +03:00
Carlosokumu
417e7f0179 fix: correct sendSms response 2025-04-01 14:53:30 +03:00
Carlosokumu
2eed990921 Merge branch 'master' into sms-api 2025-04-01 14:18:04 +03:00
alfred-mk
4a5de68a8c added the SendSMS func to the httpAccount service 2025-03-06 09:06:45 +03:00
alfred-mk
6c4702e2ba added the send sms response model 2025-03-06 09:05:39 +03:00
alfred-mk
7280784ee1 added the send sms endpoint configs 2025-03-06 09:05:01 +03:00
8 changed files with 145 additions and 3 deletions

View File

@@ -16,7 +16,9 @@ const (
voucherTransfersPathPrefix = "/api/v1/transfers/last10"
voucherDataPathPrefix = "/api/v1/token"
AliasPrefix = "api/v1/alias"
SendSMSPrefix = "api/v1/external/upsell"
AliasEnsPrefix = "/api/v1/bypass"
ExternalSMSPrefix = "/api/v1/external"
)
var (
@@ -24,6 +26,7 @@ var (
dataURLBase string
BearerToken string
aliasEnsURLBase string
externalSMSBase string
)
var (
@@ -36,7 +39,9 @@ var (
VoucherTransfersURL string
VoucherDataURL string
CheckAliasURL string
SendSMSURL string
AliasEnsURL string
ExternalSMSURL string
)
func setBase() error {
@@ -45,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)
@@ -73,6 +79,9 @@ func LoadConfig() error {
VoucherTransfersURL, _ = url.JoinPath(dataURLBase, voucherTransfersPathPrefix)
VoucherDataURL, _ = url.JoinPath(dataURLBase, voucherDataPathPrefix)
CheckAliasURL, _ = url.JoinPath(dataURLBase, AliasPrefix)
SendSMSURL, _ = url.JoinPath(dataURLBase, SendSMSPrefix)
AliasEnsURL, _ = url.JoinPath(aliasEnsURLBase, AliasEnsPrefix)
ExternalSMSURL, _ = url.JoinPath(externalSMSBase, ExternalSMSPrefix)
return nil
}

View File

@@ -653,3 +653,18 @@ func (das *DevAccountService) RequestAlias(ctx context.Context, publicKey string
Alias: alias,
}, nil
}
func (das *DevAccountService) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) {
logg.DebugCtxf(ctx, "sent an SMS", "inviterPhone", inviterPhone, "inviteePhone", inviteePhone)
return &models.SendSMSResponse{
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")
}

View File

@@ -0,0 +1,5 @@
package models
type SendSMSResponse struct {
Invitee string `json:"invitee"`
}

View File

@@ -17,4 +17,7 @@ type AccountService interface {
TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error)
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
}

View File

@@ -313,6 +313,87 @@ func requestEnsAlias(ctx context.Context, publicKey string, hint string) (*model
return &r, nil
}
// SendSMS calls the API to send out an SMS.
// Parameters:
// - inviterPhone: The user initiating the SMS.
// - inviteePhone: The number being invited to Sarafu.
func (as *HTTPAccountService) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) {
var r models.SendSMSResponse
// Create request payload
payload := map[string]string{
"inviterPhone": inviterPhone,
"inviteePhone": inviteePhone,
}
payloadBytes, err := json.Marshal(payload)
if err != nil {
return nil, err
}
// Create a new request
req, err := http.NewRequest("POST", config.SendSMSURL, bytes.NewBuffer(payloadBytes))
if err != nil {
return nil, err
}
_, err = doRequest(ctx, req, &r)
if err != nil {
return nil, err
}
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

View File

@@ -61,3 +61,7 @@ func (m MockApi) RequestAlias(ctx context.Context, publicKey string, hint string
func (m MockApi) TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error) {
return nil, nil
}
func (m MockApi) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) {
return nil, nil
}

View File

@@ -53,7 +53,20 @@ func (m *MockAccountService) CheckAliasAddress(ctx context.Context, alias string
return args.Get(0).(*models.AliasAddress), args.Error(1)
}
func (m MockAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
func (m *MockAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
args := m.Called(publicKey, hint)
return args.Get(0).(*models.RequestAliasResult), args.Error(1)
}
func (m *MockAccountService) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) {
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
}

View File

@@ -57,10 +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) {
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
}