diff --git a/config/config.go b/config/config.go index f24526c..d1af7e8 100644 --- a/config/config.go +++ b/config/config.go @@ -16,6 +16,7 @@ const ( voucherTransfersPathPrefix = "/api/v1/transfers/last10" voucherDataPathPrefix = "/api/v1/token" AliasPrefix = "api/v1/alias" + SendSMSPrefix = "api/v1/external/upsell" AliasEnsPrefix = "/api/v1/bypass" ) @@ -36,6 +37,7 @@ var ( VoucherTransfersURL string VoucherDataURL string CheckAliasURL string + SendSMSURL string AliasEnsURL string ) @@ -73,6 +75,7 @@ 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) return nil } diff --git a/models/send_sms_response.go b/models/send_sms_response.go new file mode 100644 index 0000000..1f6a70f --- /dev/null +++ b/models/send_sms_response.go @@ -0,0 +1,5 @@ +package models + +type SendSMSResponse struct { + Invitee string `json:"invitee"` +} diff --git a/remote/account_service.go b/remote/account_service.go index 2c67b12..07e697e 100644 --- a/remote/account_service.go +++ b/remote/account_service.go @@ -17,4 +17,5 @@ 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) } diff --git a/remote/http/service.go b/remote/http/service.go index 82a756e..7ddccde 100644 --- a/remote/http/service.go +++ b/remote/http/service.go @@ -313,6 +313,37 @@ 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 +} + // 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 bfa9222..b2cc015 100644 --- a/testutil/mocks/service_mock.go +++ b/testutil/mocks/service_mock.go @@ -53,7 +53,12 @@ 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) +} diff --git a/testutil/testservice/account_service.go b/testutil/testservice/account_service.go index 12b9de4..1d1e9f3 100644 --- a/testutil/testservice/account_service.go +++ b/testutil/testservice/account_service.go @@ -64,3 +64,7 @@ func (m TestAccountService) CheckAliasAddress(ctx context.Context, alias string) 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 +}