From 7280784ee1968b27f05c40d3c7e9c797de36c528 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 6 Mar 2025 09:05:01 +0300 Subject: [PATCH 1/6] added the send sms endpoint configs --- config/config.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/config.go b/config/config.go index 6ebb5bc..6610c87 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" ) var ( @@ -34,6 +35,7 @@ var ( VoucherTransfersURL string VoucherDataURL string CheckAliasURL string + SendSMSURL string ) func setBase() error { @@ -69,5 +71,6 @@ func LoadConfig() error { VoucherTransfersURL, _ = url.JoinPath(dataURLBase, voucherTransfersPathPrefix) VoucherDataURL, _ = url.JoinPath(dataURLBase, voucherDataPathPrefix) CheckAliasURL, _ = url.JoinPath(dataURLBase, AliasPrefix) + SendSMSURL, _ = url.JoinPath(dataURLBase, SendSMSPrefix) return nil } -- 2.45.2 From 6c4702e2baccb4ec5b7dcfe17ff9519cd7ee701b Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 6 Mar 2025 09:05:39 +0300 Subject: [PATCH 2/6] added the send sms response model --- models/send_sms_response.go | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 models/send_sms_response.go 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"` +} -- 2.45.2 From 4a5de68a8c1f380f0064e1741217241ce139e6ac Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 6 Mar 2025 09:06:45 +0300 Subject: [PATCH 3/6] added the SendSMS func to the httpAccount service --- remote/account_service.go | 1 + remote/http/service.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/remote/account_service.go b/remote/account_service.go index 2c67b12..33a6380 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) + SendSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.TokenTransferResponse, error) } diff --git a/remote/http/service.go b/remote/http/service.go index aca8ae0..e398011 100644 --- a/remote/http/service.go +++ b/remote/http/service.go @@ -248,6 +248,37 @@ func (as *HTTPAccountService) RequestAlias(ctx context.Context, publicKey string return svc.RequestAlias(ctx, publicKey, hint) } +// 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) SendSMS(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 -- 2.45.2 From 417e7f0179e59058527f1e3485fa1104c651f3e1 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Tue, 1 Apr 2025 14:53:30 +0300 Subject: [PATCH 4/6] fix: correct sendSms response --- remote/account_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote/account_service.go b/remote/account_service.go index 33a6380..74f388e 100644 --- a/remote/account_service.go +++ b/remote/account_service.go @@ -17,5 +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) - SendSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.TokenTransferResponse, error) + SendSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) } -- 2.45.2 From 5b41c8dc6440d8561cdd03814c082a6a87b48a7e Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Tue, 1 Apr 2025 14:55:03 +0300 Subject: [PATCH 5/6] chore: rename SendSMS to SendUpsellSMS --- remote/account_service.go | 2 +- remote/http/service.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/remote/account_service.go b/remote/account_service.go index 74f388e..07e697e 100644 --- a/remote/account_service.go +++ b/remote/account_service.go @@ -17,5 +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) - SendSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) + SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) } diff --git a/remote/http/service.go b/remote/http/service.go index f58a7ba..7ddccde 100644 --- a/remote/http/service.go +++ b/remote/http/service.go @@ -317,7 +317,7 @@ func requestEnsAlias(ctx context.Context, publicKey string, hint string) (*model // Parameters: // - inviterPhone: The user initiating the SMS. // - inviteePhone: The number being invited to Sarafu. -func (as *HTTPAccountService) SendSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) { +func (as *HTTPAccountService) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) { var r models.SendSMSResponse // Create request payload -- 2.45.2 From 441e289854add7fefe5ce27b9707de355d3a0c43 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Tue, 1 Apr 2025 15:25:10 +0300 Subject: [PATCH 6/6] implement SendUpsellSMs --- testutil/mocks/service_mock.go | 7 ++++++- testutil/testservice/account_service.go | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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 +} -- 2.45.2