Skip to content

Commit

Permalink
Added "Get Fiat Payments History"
Browse files Browse the repository at this point in the history
  • Loading branch information
pcasteran committed Jan 9, 2022
1 parent 89b3352 commit 54c8faf
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 1 deletion.
7 changes: 6 additions & 1 deletion v2/client.go
Expand Up @@ -686,7 +686,12 @@ func (c *Client) NewGetAllMarginAssetsService() *GetAllMarginAssetsService {
return &GetAllMarginAssetsService{c: c}
}

// NewFiatDepositWithdrawHistoryService init get the fiat deposit/withdraw history service
// NewFiatDepositWithdrawHistoryService init the fiat deposit/withdraw history service
func (c *Client) NewFiatDepositWithdrawHistoryService() *FiatDepositWithdrawHistoryService {
return &FiatDepositWithdrawHistoryService{c: c}
}

// NewFiatPaymentsHistoryService init the fiat payments history service
func (c *Client) NewFiatPaymentsHistoryService() *FiatPaymentsHistoryService {
return &FiatPaymentsHistoryService{c: c}
}
94 changes: 94 additions & 0 deletions v2/fiat_service.go
Expand Up @@ -98,3 +98,97 @@ type FiatDepositWithdrawHistoryItem struct {
CreateTime int64 `json:"createTime"`
UpdateTime int64 `json:"updateTime"`
}

// FiatPaymentsHistoryService retrieve the fiat payments history
type FiatPaymentsHistoryService struct {
c *Client
transactionType TransactionType
beginTime *int64
endTime *int64
page *int32
rows *int32
}

// TransactionType set transactionType
func (s *FiatPaymentsHistoryService) TransactionType(transactionType TransactionType) *FiatPaymentsHistoryService {
s.transactionType = transactionType
return s
}

// BeginTime set beginTime
func (s *FiatPaymentsHistoryService) BeginTime(beginTime int64) *FiatPaymentsHistoryService {
s.beginTime = &beginTime
return s
}

// EndTime set endTime
func (s *FiatPaymentsHistoryService) EndTime(endTime int64) *FiatPaymentsHistoryService {
s.endTime = &endTime
return s
}

// Page set page
func (s *FiatPaymentsHistoryService) Page(page int32) *FiatPaymentsHistoryService {
s.page = &page
return s
}

// Rows set rows
func (s *FiatPaymentsHistoryService) Rows(rows int32) *FiatPaymentsHistoryService {
s.rows = &rows
return s
}

// Do send request
func (s *FiatPaymentsHistoryService) Do(ctx context.Context, opts ...RequestOption) (*FiatPaymentsHistory, error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/fiat/payments",
secType: secTypeSigned,
}
r.setParam("transactionType", s.transactionType)
if s.beginTime != nil {
r.setParam("beginTime", *s.beginTime)
}
if s.endTime != nil {
r.setParam("endTime", *s.endTime)
}
if s.page != nil {
r.setParam("page", *s.page)
}
if s.rows != nil {
r.setParam("rows", *s.rows)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res := FiatPaymentsHistory{}
if err = json.Unmarshal(data, &res); err != nil {
return nil, err
}
return &res, nil
}

// FiatPaymentsHistory define the fiat payments history
type FiatPaymentsHistory struct {
Code string `json:"code"`
Message string `json:"message"`
Data []FiatPaymentsHistoryItem `json:"data"`
Total int32 `json:"total"`
Success bool `json:"success"`
}

// FiatPaymentsHistoryItem define a fiat payments history item
type FiatPaymentsHistoryItem struct {
OrderNo string `json:"orderNo"`
SourceAmount string `json:"sourceAmount"`
FiatCurrency string `json:"fiatCurrency"`
ObtainAmount string `json:"obtainAmount"`
CryptoCurrency string `json:"cryptoCurrency"`
TotalFee string `json:"totalFee"`
Price string `json:"price"`
Status string `json:"status"`
CreateTime int64 `json:"createTime"`
UpdateTime int64 `json:"updateTime"`
}
86 changes: 86 additions & 0 deletions v2/fiat_service_test.go
Expand Up @@ -95,3 +95,89 @@ func (s *fiatServiceTestSuite) assertFiatDepositWithdrawHistoryItemEqual(e, a *F
r.Equal(e.CreateTime, a.CreateTime, "CreateTime")
r.Equal(e.UpdateTime, a.UpdateTime, "UpdateTime")
}

func (s *fiatServiceTestSuite) TestFiatPaymentsHistory() {
data := []byte(`{
"code": "000000",
"message": "success",
"data": [
{
"orderNo": "353fca443f06466db0c4dc89f94f027a",
"sourceAmount": "20.0",
"fiatCurrency": "EUR",
"obtainAmount": "4.462",
"cryptoCurrency": "LUNA",
"totalFee": "0.2",
"price": "4.437472",
"status": "Failed",
"createTime": 1624529919000,
"updateTime": 1624529919000
}
],
"total": 1,
"success": true
}`)
s.mockDo(data, nil)
defer s.assertDo()

transactionType := TransactionTypeBuy
s.assertReq(func(r *request) {
e := newSignedRequest().setParams(params{
"transactionType": transactionType,
})
s.assertRequestEqual(e, r)
})

res, err := s.client.NewFiatPaymentsHistoryService().
TransactionType(transactionType).
Do(newContext())
s.r().NoError(err)
e := &FiatPaymentsHistory{
Code: "000000",
Message: "success",
Data: []FiatPaymentsHistoryItem{
{
OrderNo: "353fca443f06466db0c4dc89f94f027a",
SourceAmount: "20.0",
FiatCurrency: "EUR",
ObtainAmount: "4.462",
CryptoCurrency: "LUNA",
TotalFee: "0.2",
Price: "4.437472",
Status: "Failed",
CreateTime: 1624529919000,
UpdateTime: 1624529919000,
},
},
Total: 1,
Success: true,
}
s.assertFiatPaymentsHistoryEqual(e, res)
}

func (s *fiatServiceTestSuite) assertFiatPaymentsHistoryEqual(e, a *FiatPaymentsHistory) {
r := s.r()
r.Equal(e.Code, a.Code, "Code")
r.Equal(e.Message, a.Message, "Message")
r.Equal(e.Total, a.Total, "Total")
r.Equal(e.Success, a.Success, "Success")

r.Len(a.Data, len(e.Data))
for i := 0; i < len(a.Data); i++ {
s.assertFiatPaymentsHistoryItemEqual(&e.Data[i], &a.Data[i])
}
}

func (s *fiatServiceTestSuite) assertFiatPaymentsHistoryItemEqual(e, a *FiatPaymentsHistoryItem) {
r := s.r()
r.Equal(e.OrderNo, a.OrderNo, "OrderNo")
r.Equal(e.SourceAmount, a.SourceAmount, "SourceAmount")
r.Equal(e.FiatCurrency, a.FiatCurrency, "FiatCurrency")
r.Equal(e.ObtainAmount, a.ObtainAmount, "ObtainAmount")
r.Equal(e.CryptoCurrency, a.CryptoCurrency, "CryptoCurrency")
r.Equal(e.TotalFee, a.TotalFee, "TotalFee")
r.Equal(e.Price, a.Price, "Price")
r.Equal(e.Status, a.Status, "Status")
r.Equal(e.CreateTime, a.CreateTime, "CreateTime")
r.Equal(e.UpdateTime, a.UpdateTime, "UpdateTime")
}

0 comments on commit 54c8faf

Please sign in to comment.