mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* chore: replace local currency package with go-libs version * Annotate apiRouter to ensure no conflict with other chi.Mux provided by go-libs * Upgrade go-libs to new v3.0.1 tag * Update connector template file to import from go-libs
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package currencycloud
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/formancehq/go-libs/v3/currency"
|
|
"github.com/formancehq/payments/internal/models"
|
|
)
|
|
|
|
func (p *Plugin) fetchNextBalances(ctx context.Context, req models.FetchNextBalancesRequest) (models.FetchNextBalancesResponse, error) {
|
|
page := 1
|
|
balances := make([]models.PSPBalance, 0)
|
|
for {
|
|
if page < 0 {
|
|
break
|
|
}
|
|
|
|
pagedBalances, nextPage, err := p.client.GetBalances(ctx, page, req.PageSize)
|
|
if err != nil {
|
|
return models.FetchNextBalancesResponse{}, err
|
|
}
|
|
|
|
page = nextPage
|
|
|
|
for _, balance := range pagedBalances {
|
|
precision, ok := supportedCurrenciesWithDecimal[balance.Currency]
|
|
if !ok {
|
|
return models.FetchNextBalancesResponse{}, nil
|
|
}
|
|
|
|
amount, err := currency.GetAmountWithPrecisionFromString(balance.Amount.String(), precision)
|
|
if err != nil {
|
|
return models.FetchNextBalancesResponse{}, err
|
|
}
|
|
|
|
balances = append(balances, models.PSPBalance{
|
|
AccountReference: balance.AccountID,
|
|
CreatedAt: balance.UpdatedAt,
|
|
Amount: amount,
|
|
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, balance.Currency),
|
|
})
|
|
}
|
|
}
|
|
|
|
return models.FetchNextBalancesResponse{
|
|
Balances: balances,
|
|
HasMore: false,
|
|
}, nil
|
|
}
|