added the GetMpesaOnrampRates function
This commit is contained in:
parent
ea659ec25e
commit
45469d4ba3
@ -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