Files
zeekay 7d727874d5 chore: rebrand Formance Payments -> Hanzo Payments (hanzo-fi)
- 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.
2026-07-05 13:08:55 -07:00

77 lines
2.2 KiB
Go

package client
import (
"context"
"fmt"
"net/http"
"time"
"github.com/hanzo-fi/payments/pkg/domain/httpwrapper"
"github.com/hanzo-fi/payments/pkg/domain/metrics"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"golang.org/x/sync/singleflight"
)
//go:generate mockgen -source client.go -destination client_generated.go -package client . Client
type Client interface {
GetAccounts(ctx context.Context, page int, pageSize int) ([]*Account, int, error)
GetBalances(ctx context.Context, page int, pageSize int) ([]*Balance, int, error)
GetBeneficiaries(ctx context.Context, page int, pageSize int) ([]*Beneficiary, int, error)
GetContactID(ctx context.Context, accountID string) (*Contact, error)
GetTransactions(ctx context.Context, page int, pageSize int, updatedAtFrom time.Time) ([]Transaction, int, error)
InitiateTransfer(ctx context.Context, transferRequest *TransferRequest) (*TransferResponse, error)
InitiatePayout(ctx context.Context, payoutRequest *PayoutRequest) (*PayoutResponse, error)
}
type apiTransport struct {
c *client
underlying *otelhttp.Transport
}
func (t *apiTransport) RoundTrip(req *http.Request) (*http.Response, error) {
if t.c.authToken != "" {
req.Header.Add("X-Auth-Token", t.c.authToken)
}
return t.underlying.RoundTrip(req)
}
type client struct {
httpClient httpwrapper.Client
endpoint string
loginID string
apiKey string
singleFlight singleflight.Group
authToken string
}
func (c *client) buildEndpoint(path string, args ...interface{}) string {
return fmt.Sprintf("%s/%s", c.endpoint, fmt.Sprintf(path, args...))
}
const DevAPIEndpoint = "https://devapi.currencycloud.com"
// New creates a new client for the CurrencyCloud API.
func New(connectorName string, loginID, apiKey, endpoint string) Client {
if endpoint == "" {
endpoint = DevAPIEndpoint
}
c := &client{
endpoint: endpoint,
loginID: loginID,
apiKey: apiKey,
}
baseTransport := &apiTransport{
c: c,
underlying: otelhttp.NewTransport(http.DefaultTransport),
}
config := &httpwrapper.Config{
Transport: metrics.NewTransport(connectorName, metrics.TransportOpts{Transport: baseTransport}),
}
c.httpClient = httpwrapper.NewClient(config)
return c
}