Compare commits

...

3 Commits

4 changed files with 40 additions and 0 deletions

View File

@ -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
}

View File

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

View File

@ -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)
}

View File

@ -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