mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
- go.mod module path + all self-imports: github.com/formancehq/payments -> github.com/hanzo-fi/payments (1590 .go files / 3152 refs; 20 modules: root, pkg/client, pkg/domain, 18 ce/plugins). External dep kept: formancehq/go-libs. - plugins: each ce/plugins/* consumed a *published* pkg/domain; added local 'replace .../pkg/domain => ../../../pkg/domain' (consistent with root) so every standalone plugin module builds in-monorepo. compile-plugin.sh MOD var rebranded too. - branding: README, LICENSE (dual MIT+EE; upstream copyright retained + Hanzo added), goreleaser (release images -> registry.hanzo.ai/hanzo-fi, OCI labels, homepage), proto go_package, renovate, speakeasy gen.yaml, connector-template *.gotpl. - CI: removed Numary/Formance workflows + composite action; added canonical hanzo.yml + cicd.yml (hanzoai/ci, gated HANZO_CI_ENABLED) + secretless ci.yml (go build/vet). - kept as data/compat keys: wire capability enums ALLOW_FORMANCE_*, generated SDK type client.Formance, domain field FormanceRedirectURL, OTEL_SERVICE_NAME, upstream base image. - verified: go build ./... (default + -tags ee) + all 20 nested modules green.
105 lines
3.3 KiB
Go
105 lines
3.3 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/hanzo-fi/payments/pkg/domain/metrics"
|
|
errorsutils "github.com/hanzo-fi/payments/pkg/domain/errors"
|
|
)
|
|
|
|
type Balance struct {
|
|
Type string `json:"type"`
|
|
Currency string `json:"currency"`
|
|
BeginOfDayAmount json.Number `json:"beginOfDayAmount"`
|
|
FinancialDate string `json:"financialDate"`
|
|
IntraDayAmount json.Number `json:"intraDayAmount"`
|
|
LastTransactionTimestamp string `json:"lastTransactionTimestamp"`
|
|
}
|
|
|
|
type AccountIdentifier struct {
|
|
Account string `json:"account"`
|
|
FinancialInstitution string `json:"financialInstitution"`
|
|
Country string `json:"country"`
|
|
}
|
|
|
|
type Account struct {
|
|
AccountID string `json:"accountId"`
|
|
AccountDescription string `json:"accountDescription"`
|
|
AccountIdentifiers []AccountIdentifier `json:"accountIdentifiers"`
|
|
Status string `json:"status"`
|
|
Currency string `json:"currency"`
|
|
OpeningDate string `json:"openingDate"`
|
|
ClosingDate string `json:"closingDate"`
|
|
OwnedByCompanyID string `json:"ownedByCompanyId"`
|
|
ProtectionType string `json:"protectionType"`
|
|
Balances []Balance `json:"balances"`
|
|
}
|
|
|
|
func (c *client) GetAccounts(ctx context.Context, page int, pageSize int, fromOpeningDate time.Time) ([]Account, error) {
|
|
if err := c.ensureAccessTokenIsValid(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "list_accounts")
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.endpoint+"/api/v1/accounts", http.NoBody)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create account request: %w", err)
|
|
}
|
|
|
|
q := req.URL.Query()
|
|
q.Add("PageSize", fmt.Sprint(pageSize))
|
|
q.Add("PageNumber", fmt.Sprint(page))
|
|
if !fromOpeningDate.IsZero() {
|
|
q.Add("OpeningDateFrom", fromOpeningDate.Format(time.DateOnly))
|
|
}
|
|
req.URL.RawQuery = q.Encode()
|
|
|
|
req.Header.Set("Authorization", "Bearer "+c.accessToken)
|
|
|
|
type response struct {
|
|
Result []Account `json:"result"`
|
|
PageInfo struct {
|
|
CurrentPage int `json:"currentPage"`
|
|
PageSize int `json:"pageSize"`
|
|
} `json:"pageInfo"`
|
|
}
|
|
|
|
res := response{Result: make([]Account, 0)}
|
|
statusCode, err := c.httpClient.Do(ctx, req, &res, nil)
|
|
if err != nil {
|
|
return nil, errorsutils.NewWrappedError(
|
|
fmt.Errorf("failed to get accounts: status code %d", statusCode),
|
|
err,
|
|
)
|
|
}
|
|
return res.Result, nil
|
|
}
|
|
|
|
func (c *client) GetAccount(ctx context.Context, accountID string) (*Account, error) {
|
|
if err := c.ensureAccessTokenIsValid(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "get_account")
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("%s/api/v1/accounts/%s", c.endpoint, accountID), http.NoBody)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create account request: %w", err)
|
|
}
|
|
req.Header.Set("Authorization", "Bearer "+c.accessToken)
|
|
|
|
var account Account
|
|
statusCode, err := c.httpClient.Do(ctx, req, &account, nil)
|
|
if err != nil {
|
|
return nil, errorsutils.NewWrappedError(
|
|
fmt.Errorf("failed to get account: status code %d", statusCode),
|
|
err,
|
|
)
|
|
}
|
|
return &account, nil
|
|
}
|