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

91 lines
2.9 KiB
Go

package client
import (
"context"
"fmt"
"net/http"
"strings"
"time"
"github.com/hanzo-fi/payments/pkg/domain/httpwrapper"
"github.com/hanzo-fi/payments/pkg/domain/metrics"
"github.com/hanzo-fi/payments/ce/plugins/modulr/client/hmac"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)
//go:generate mockgen -source client.go -destination client_generated.go -package client . Client
type Client interface {
GetAccounts(ctx context.Context, page, pageSize int, fromCreatedAt time.Time) ([]Account, error)
GetAccount(ctx context.Context, accountID string) (*Account, error)
GetBeneficiaries(ctx context.Context, page, pageSize int, modifiedSince time.Time) ([]Beneficiary, error)
GetPayments(ctx context.Context, paymentType PaymentType, page, pageSize int, modifiedSince time.Time) ([]Payment, error)
InitiatePayout(ctx context.Context, payoutRequest *PayoutRequest) (*PayoutResponse, error)
GetPayout(ctx context.Context, payoutID string) (PayoutResponse, error)
GetTransactions(ctx context.Context, accountID string, page, pageSize int, fromTransactionDate, toTransactionDate time.Time) ([]Transaction, int, error)
InitiateTransfer(ctx context.Context, transferRequest *TransferRequest) (*TransferResponse, error)
GetTransfer(ctx context.Context, transferID string) (TransferResponse, error)
}
type apiTransport struct {
apiKey string
headers map[string]string
underlying http.RoundTripper
}
func (t *apiTransport) RoundTrip(req *http.Request) (*http.Response, error) {
req.Header.Add("Authorization", t.apiKey)
return t.underlying.RoundTrip(req)
}
type responseWrapper[t any] struct {
Content t `json:"content"`
Size int `json:"size"`
TotalSize int `json:"totalSize"`
Page int `json:"page"`
TotalPages int `json:"totalPages"`
}
type client struct {
httpClient httpwrapper.Client
endpoint string
}
func (m *client) buildEndpoint(path string, args ...interface{}) string {
endpoint := strings.TrimSuffix(m.endpoint, "/")
return fmt.Sprintf("%s/%s", endpoint, fmt.Sprintf(path, args...))
}
const SandboxAPIEndpoint = "https://api-sandbox.modulrfinance.com/api-sandbox-token"
func New(connectorName, apiKey, apiSecret, endpoint string) (Client, error) {
if endpoint == "" {
endpoint = SandboxAPIEndpoint
}
headers, err := hmac.GenerateHeaders(apiKey, apiSecret, "", false)
if err != nil {
return nil, fmt.Errorf("failed to generate headers: %w", err)
}
config := &httpwrapper.Config{
Transport: metrics.NewTransport(connectorName, metrics.TransportOpts{Transport: &apiTransport{
headers: headers,
apiKey: apiKey,
underlying: otelhttp.NewTransport(http.DefaultTransport),
}}),
}
return &client{
httpClient: httpwrapper.NewClient(config),
endpoint: endpoint,
}, nil
}
type ErrorResponse struct {
Field string `json:"field"`
Code string `json:"code"`
Message string `json:"message"`
ErrorCode string `json:"errorCode"`
SourceService string `json:"sourceService"`
}