satellite/payments: add cents values to transaction info (#3614)
This commit is contained in:
parent
2030d67650
commit
c72c443564
@ -9,16 +9,15 @@ import (
|
||||
|
||||
// BillingHistoryItem holds all public information about billing history line.
|
||||
type BillingHistoryItem struct {
|
||||
ID string `json:"id"`
|
||||
Description string `json:"description"`
|
||||
Amount int64 `json:"amount"`
|
||||
TokenAmount string `json:"tokenAmount"`
|
||||
TokenReceived string `json:"tokenReceived"`
|
||||
Status string `json:"status"`
|
||||
Link string `json:"link"`
|
||||
Start time.Time `json:"start"`
|
||||
End time.Time `json:"end"`
|
||||
Type BillingHistoryItemType `json:"type"`
|
||||
ID string `json:"id"`
|
||||
Description string `json:"description"`
|
||||
Amount int64 `json:"amount"`
|
||||
Received int64 `json:"received"`
|
||||
Status string `json:"status"`
|
||||
Link string `json:"link"`
|
||||
Start time.Time `json:"start"`
|
||||
End time.Time `json:"end"`
|
||||
Type BillingHistoryItemType `json:"type"`
|
||||
}
|
||||
|
||||
// BillingHistoryItemType indicates type of billing history item.
|
||||
|
@ -231,18 +231,18 @@ func (payments PaymentsService) BillingHistory(ctx context.Context) (billingHist
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, tx := range txsInfos {
|
||||
for _, info := range txsInfos {
|
||||
billingHistory = append(billingHistory,
|
||||
&BillingHistoryItem{
|
||||
ID: tx.ID.String(),
|
||||
Description: "STORJ Token Deposit",
|
||||
TokenAmount: tx.Amount.String(),
|
||||
TokenReceived: tx.Received.String(),
|
||||
Status: tx.Status.String(),
|
||||
Link: tx.Link,
|
||||
Start: tx.CreatedAt,
|
||||
End: tx.ExpiresAt,
|
||||
Type: Transaction,
|
||||
ID: info.ID.String(),
|
||||
Description: "STORJ Token Deposit",
|
||||
Amount: info.AmountCents,
|
||||
Received: info.ReceivedCents,
|
||||
Status: info.Status.String(),
|
||||
Link: info.Link,
|
||||
Start: info.CreatedAt,
|
||||
End: info.ExpiresAt,
|
||||
Type: Transaction,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
15
satellite/payments/stripecoinpayments/conversion.go
Normal file
15
satellite/payments/stripecoinpayments/conversion.go
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright (C) 2019 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package stripecoinpayments
|
||||
|
||||
import (
|
||||
"math"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// convertToCents convert amount to cents with with given rate.
|
||||
func convertToCents(rate, amount *big.Float) int64 {
|
||||
f, _ := new(big.Float).Mul(amount, rate).Float64()
|
||||
return int64(math.Floor(f * 100))
|
||||
}
|
@ -6,7 +6,6 @@ package stripecoinpayments
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
"sync"
|
||||
"time"
|
||||
@ -237,10 +236,7 @@ func (service *Service) applyTransactionBalance(ctx context.Context, tx Transact
|
||||
return err
|
||||
}
|
||||
|
||||
amount := new(big.Float).Mul(rate, &tx.Amount)
|
||||
|
||||
f, _ := amount.Float64()
|
||||
cents := int64(math.Floor(f * 100))
|
||||
cents := convertToCents(rate, &tx.Received)
|
||||
|
||||
params := &stripe.CustomerBalanceTransactionParams{
|
||||
Amount: stripe.Int64(-cents),
|
||||
|
@ -116,16 +116,23 @@ func (tokens *storjTokens) ListTransactionInfos(ctx context.Context, userID uuid
|
||||
status = payments.TransactionStatus(tx.Status.String())
|
||||
}
|
||||
|
||||
rate, err := tokens.service.db.Transactions().GetLockedRate(ctx, tx.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
infos = append(infos,
|
||||
payments.TransactionInfo{
|
||||
ID: []byte(tx.ID),
|
||||
Amount: *payments.TokenAmountFromBigFloat(&tx.Amount),
|
||||
Received: *payments.TokenAmountFromBigFloat(&tx.Received),
|
||||
Address: tx.Address,
|
||||
Status: status,
|
||||
Link: link,
|
||||
ExpiresAt: tx.CreatedAt.Add(tx.Timeout),
|
||||
CreatedAt: tx.CreatedAt,
|
||||
ID: []byte(tx.ID),
|
||||
Amount: *payments.TokenAmountFromBigFloat(&tx.Amount),
|
||||
Received: *payments.TokenAmountFromBigFloat(&tx.Received),
|
||||
AmountCents: convertToCents(rate, &tx.Amount),
|
||||
ReceivedCents: convertToCents(rate, &tx.Received),
|
||||
Address: tx.Address,
|
||||
Status: status,
|
||||
Link: link,
|
||||
ExpiresAt: tx.CreatedAt.Add(tx.Timeout),
|
||||
CreatedAt: tx.CreatedAt,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -61,14 +61,16 @@ type Transaction struct {
|
||||
// TransactionInfo holds transaction data with additional information
|
||||
// such as links and expiration time.
|
||||
type TransactionInfo struct {
|
||||
ID TransactionID
|
||||
Amount TokenAmount
|
||||
Received TokenAmount
|
||||
Address string
|
||||
Status TransactionStatus
|
||||
Link string
|
||||
ExpiresAt time.Time
|
||||
CreatedAt time.Time
|
||||
ID TransactionID
|
||||
Amount TokenAmount
|
||||
Received TokenAmount
|
||||
AmountCents int64
|
||||
ReceivedCents int64
|
||||
Address string
|
||||
Status TransactionStatus
|
||||
Link string
|
||||
ExpiresAt time.Time
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
// TokenAmount is a wrapper type for STORJ token amount.
|
||||
|
Loading…
Reference in New Issue
Block a user