mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* feat(plugins): add open banking dummy pay connector * put everything inside dummypay plugin instead * fixes after rebase * add first tests * fix after reviews
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"math/big"
|
|
"time"
|
|
|
|
"github.com/formancehq/payments/internal/models"
|
|
)
|
|
|
|
type Balance struct {
|
|
AccountID string `json:"account_id"`
|
|
AmountInMinors int64 `json:"amount_in_minors"`
|
|
Currency string `json:"currency"`
|
|
}
|
|
|
|
func (c *client) FetchBalance(ctx context.Context, accountID string) (*models.PSPBalance, error) {
|
|
b, err := c.readFile("balances.json")
|
|
if err != nil {
|
|
return &models.PSPBalance{}, fmt.Errorf("failed to fetch balances: %w", err)
|
|
}
|
|
|
|
balances := make([]Balance, 0)
|
|
if len(b) == 0 {
|
|
return nil, nil
|
|
}
|
|
|
|
err = json.Unmarshal(b, &balances)
|
|
if err != nil {
|
|
return &models.PSPBalance{}, fmt.Errorf("failed to unmarshal balances: %w", err)
|
|
}
|
|
|
|
for _, balance := range balances {
|
|
if balance.AccountID != accountID {
|
|
continue
|
|
}
|
|
return &models.PSPBalance{
|
|
AccountReference: balance.AccountID,
|
|
CreatedAt: time.Now().Truncate(time.Second),
|
|
Asset: balance.Currency,
|
|
Amount: big.NewInt(balance.AmountInMinors),
|
|
}, nil
|
|
}
|
|
return &models.PSPBalance{}, nil
|
|
}
|