WIP: sms-api #10
@ -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
|
||||
}
|
||||
|
5
models/send_sms_response.go
Normal file
5
models/send_sms_response.go
Normal file
@ -0,0 +1,5 @@
|
||||
package models
|
||||
|
||||
type SendSMSResponse struct {
|
||||
Invitee string `json:"invitee"`
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user