Files
d045ece673 feat: add Increase Connector for the Payments Service (#322)
* Reflect new amount for returned/reverted transaction.
* Enhance payout and transfer response structures with transaction IDs and pending transaction IDs;
* Update payment creation logic to utilize new fields.
* Remove periodic execution of fetch_payments

* Update ParentReference and Reference fields in payment model for transfer creation

* Update pkg/client/

* Set return payment to SUCCEEDED, remove adjustment update

* trigger ready for review

* retrigger CI

* Reuse Refund functionality instead of created Returned upsert operation

* fix: ensure PendingTimeline and DeclinedTimeline are preserved in payments state

test: add unit test to preserve timeline states in FetchNextPayments

* Retrigger CI

---------

Co-authored-by: gitstart_bot <[email protected]>
2025-06-09 09:39:24 +00:00

42 lines
1.1 KiB
Go

package client
import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"
"github.com/formancehq/payments/internal/connectors/metrics"
)
type Balance struct {
AccountID string `json:"account_id"`
CurrentBalance json.Number `json:"current_balance"`
AvailableBalance json.Number `json:"available_balance"`
Type string `json:"type"`
}
func (c *client) GetAccountBalance(ctx context.Context, accountID string) (*Balance, time.Time, error) {
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "list_account_balances")
req, err := c.newRequest(ctx, http.MethodGet, fmt.Sprintf("accounts/%s/balance", accountID), http.NoBody)
if err != nil {
return nil, time.Time{}, fmt.Errorf("failed to create account balance request: %w", err)
}
atTime := time.Now().UTC()
q := req.URL.Query()
q.Add("at_time", atTime.Format(time.RFC3339))
req.URL.RawQuery = q.Encode()
var res *Balance
var errRes increaseError
_, err = c.httpClient.Do(ctx, req, &res, &errRes)
if err != nil {
return nil, time.Time{}, fmt.Errorf("failed to get account balance: %w %w", err, errRes.Error())
}
return res, atTime, nil
}