Compare commits
2 Commits
bfdeef1255
...
45469d4ba3
| Author | SHA1 | Date | |
|---|---|---|---|
| 45469d4ba3 | |||
| ea659ec25e |
@ -29,6 +29,7 @@ const (
|
|||||||
CreditSendPrefix = "/api/v1/credit-send"
|
CreditSendPrefix = "/api/v1/credit-send"
|
||||||
CreditSendReverseQuotePrefix = "/api/v1/pool/reverse-quote"
|
CreditSendReverseQuotePrefix = "/api/v1/pool/reverse-quote"
|
||||||
MpesaOnrampPath = "/api/v1/trigger-onramp"
|
MpesaOnrampPath = "/api/v1/trigger-onramp"
|
||||||
|
MpesaOnrampRatesPath = "/api/v1/rates"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -65,6 +66,7 @@ var (
|
|||||||
CreditSendURL string
|
CreditSendURL string
|
||||||
CreditSendReverseQuoteURL string
|
CreditSendReverseQuoteURL string
|
||||||
MpesaOnrampURL string
|
MpesaOnrampURL string
|
||||||
|
MpresaOnrampRatesURL string
|
||||||
)
|
)
|
||||||
|
|
||||||
func setBase() error {
|
func setBase() error {
|
||||||
@ -118,6 +120,7 @@ func LoadConfig() error {
|
|||||||
CreditSendURL, _ = url.JoinPath(dataURLBase, CreditSendPrefix)
|
CreditSendURL, _ = url.JoinPath(dataURLBase, CreditSendPrefix)
|
||||||
CreditSendReverseQuoteURL, _ = url.JoinPath(dataURLBase, CreditSendReverseQuotePrefix)
|
CreditSendReverseQuoteURL, _ = url.JoinPath(dataURLBase, CreditSendReverseQuotePrefix)
|
||||||
MpesaOnrampURL, _ = url.JoinPath(mpesaOnrampBase, MpesaOnrampPath)
|
MpesaOnrampURL, _ = url.JoinPath(mpesaOnrampBase, MpesaOnrampPath)
|
||||||
|
MpresaOnrampRatesURL, _ = url.JoinPath(mpesaOnrampBase, MpesaOnrampRatesPath)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -929,3 +929,10 @@ func (das *DevAccountService) MpesaTriggerOnramp(ctx context.Context, address, p
|
|||||||
TransactionCode: "ae6fb33b-4653-4f38-a3b6-85dfea7a1e99",
|
TransactionCode: "ae6fb33b-4653-4f38-a3b6-85dfea7a1e99",
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (das *DevAccountService) GetMpesaOnrampRates(ctx context.Context) (*models.MpesaOnrampRatesResponse, error) {
|
||||||
|
return &models.MpesaOnrampRatesResponse{
|
||||||
|
Buy: 128.15,
|
||||||
|
Sell: 130.06,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -5,3 +5,8 @@ type MpesaOnrampResponse struct {
|
|||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
TransactionCode string `json:"transactionCode"`
|
TransactionCode string `json:"transactionCode"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MpesaOnrampRatesResponse struct {
|
||||||
|
Buy float64 `json:"buy"`
|
||||||
|
Sell float64 `json:"sell"`
|
||||||
|
}
|
||||||
|
|||||||
@ -33,4 +33,5 @@ type AccountService interface {
|
|||||||
GetCreditSendMaxLimit(ctx context.Context, poolAddress, fromTokenAddress, toTokenAddress, publicKey string) (*models.CreditSendLimitsResult, error)
|
GetCreditSendMaxLimit(ctx context.Context, poolAddress, fromTokenAddress, toTokenAddress, publicKey string) (*models.CreditSendLimitsResult, error)
|
||||||
GetCreditSendReverseQuote(ctx context.Context, poolAddress, fromTokenAddress, toTokenAddress, toTokenAMount string) (*models.CreditSendReverseQouteResult, error)
|
GetCreditSendReverseQuote(ctx context.Context, poolAddress, fromTokenAddress, toTokenAddress, toTokenAMount string) (*models.CreditSendReverseQouteResult, error)
|
||||||
MpesaTriggerOnramp(ctx context.Context, address, phoneNumber, asset string, amount int) (*models.MpesaOnrampResponse, error)
|
MpesaTriggerOnramp(ctx context.Context, address, phoneNumber, asset string, amount int) (*models.MpesaOnrampResponse, error)
|
||||||
|
GetMpesaOnrampRates(ctx context.Context) (*models.MpesaOnrampRatesResponse, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -825,6 +825,24 @@ func (as *HTTPAccountService) MpesaTriggerOnramp(ctx context.Context, address, p
|
|||||||
return &r, nil
|
return &r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMpesaOnrampRates calls the API to fetch the buying and selling rates for KSH.
|
||||||
|
func (as *HTTPAccountService) GetMpesaOnrampRates(ctx context.Context) (*models.MpesaOnrampRatesResponse, error) {
|
||||||
|
var r models.MpesaOnrampRatesResponse
|
||||||
|
|
||||||
|
ctx = context.WithValue(ctx, ctxKeyAuthToken, config.MpesaOnrampBearerToken)
|
||||||
|
|
||||||
|
req, err := http.NewRequest("GET", config.MpresaOnrampRatesURL, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := doRequest(ctx, req, &r); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &r, nil
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: remove eth-custodial api dependency
|
// TODO: remove eth-custodial api dependency
|
||||||
func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
|
func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
|
||||||
var okResponse api.OKResponse
|
var okResponse api.OKResponse
|
||||||
|
|||||||
@ -135,3 +135,8 @@ func (m MockAccountService) MpesaTriggerOnramp(ctx context.Context, address, pho
|
|||||||
args := m.Called(address, phoneNumber, asset, amount)
|
args := m.Called(address, phoneNumber, asset, amount)
|
||||||
return args.Get(0).(*models.MpesaOnrampResponse), args.Error(1)
|
return args.Get(0).(*models.MpesaOnrampResponse), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m MockAccountService) GetMpesaOnrampRates(ctx context.Context) (*models.MpesaOnrampRatesResponse, error) {
|
||||||
|
args := m.Called()
|
||||||
|
return args.Get(0).(*models.MpesaOnrampRatesResponse), args.Error(1)
|
||||||
|
}
|
||||||
|
|||||||
@ -136,3 +136,7 @@ func (m TestAccountService) GetCreditSendReverseQuote(ctx context.Context, poolA
|
|||||||
func (m TestAccountService) MpesaTriggerOnramp(ctx context.Context, address, phoneNumber, asset string, amount int) (*models.MpesaOnrampResponse, error) {
|
func (m TestAccountService) MpesaTriggerOnramp(ctx context.Context, address, phoneNumber, asset string, amount int) (*models.MpesaOnrampResponse, error) {
|
||||||
return &models.MpesaOnrampResponse{}, nil
|
return &models.MpesaOnrampResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m TestAccountService) GetMpesaOnrampRates(ctx context.Context) (*models.MpesaOnrampRatesResponse, error) {
|
||||||
|
return &models.MpesaOnrampRatesResponse{}, nil
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user