85 lines
2.6 KiB
Go
85 lines
2.6 KiB
Go
package paymenthttp
|
|
|
|
import (
|
|
"git.sendico.io/tech/sxchnge/product/payments"
|
|
factor "git.sendico.io/tech/sxchnge/product/twofactor/model"
|
|
"time"
|
|
)
|
|
|
|
type requestDTO struct {
|
|
Kind string `json:"kind"`
|
|
Source string `json:"source"`
|
|
Destination string `json:"destination"`
|
|
Recipient string `json:"recipient"`
|
|
Amount int64 `json:"amount"`
|
|
}
|
|
|
|
func (d requestDTO) model() payments.Request {
|
|
return payments.Request{Kind: d.Kind, Source: d.Source, Destination: d.Destination, Recipient: d.Recipient, Amount: d.Amount}
|
|
}
|
|
func fromRequest(r payments.Request) requestDTO {
|
|
return requestDTO{r.Kind, r.Source, r.Destination, r.Recipient, r.Amount}
|
|
}
|
|
|
|
type quoteDTO struct {
|
|
ID string `json:"id"`
|
|
Request requestDTO `json:"request"`
|
|
Fee int64 `json:"fee"`
|
|
Debit int64 `json:"debit"`
|
|
Credit int64 `json:"credit"`
|
|
ExpiresAt time.Time `json:"expiresAt"`
|
|
Numerator int64 `json:"rateNumerator"`
|
|
Denominator int64 `json:"rateDenominator"`
|
|
}
|
|
|
|
func fromQuote(q payments.Quote) quoteDTO {
|
|
return quoteDTO{q.ID, fromRequest(q.Request), q.Fee, q.Debit, q.Credit, q.ExpiresAt, q.RateNumerator, q.RateDenominator}
|
|
}
|
|
|
|
type operationDTO struct {
|
|
ID string `json:"id"`
|
|
Quote quoteDTO `json:"quote"`
|
|
Status string `json:"status"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
}
|
|
|
|
func fromOperation(o payments.Operation) operationDTO {
|
|
return operationDTO{o.ID, fromQuote(o.Quote), o.Status, o.CreatedAt}
|
|
}
|
|
|
|
type accountDTO struct {
|
|
ID string `json:"id"`
|
|
Currency string `json:"currency"`
|
|
Precision int `json:"precision"`
|
|
Available int64 `json:"available"`
|
|
PayoutMethod string `json:"payoutMethod"`
|
|
PayoutLabel string `json:"payoutLabel"`
|
|
CanFund bool `json:"canFund"`
|
|
}
|
|
type snapshotDTO struct {
|
|
Accounts []accountDTO `json:"accounts"`
|
|
Operations []operationDTO `json:"operations"`
|
|
}
|
|
|
|
func fromSnapshot(s payments.Snapshot) snapshotDTO {
|
|
v := snapshotDTO{Accounts: []accountDTO{}, Operations: []operationDTO{}}
|
|
for _, a := range s.Accounts {
|
|
v.Accounts = append(v.Accounts, accountDTO{a.ID, a.Currency, a.Precision, a.Available, a.PayoutMethod, a.PayoutLabel, a.FundingMethod != ""})
|
|
}
|
|
for i := len(s.Operations) - 1; i >= 0; i-- {
|
|
v.Operations = append(v.Operations, fromOperation(s.Operations[i]))
|
|
}
|
|
return v
|
|
}
|
|
|
|
type challengeDTO struct {
|
|
ID string `json:"challengeId"`
|
|
Target string `json:"target"`
|
|
ExpiresAt time.Time `json:"expiresAt"`
|
|
ResendAt time.Time `json:"resendAt"`
|
|
}
|
|
|
|
func fromChallenge(c factor.Challenge) challengeDTO {
|
|
return challengeDTO{c.ID, c.Target, c.ExpiresAt, c.ResendAt}
|
|
}
|