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.
75 lines
2.9 KiB
Go
75 lines
2.9 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"sync"
|
|
|
|
"github.com/hanzo-fi/payments/pkg/domain/httpwrapper"
|
|
"github.com/hanzo-fi/payments/pkg/domain/metrics"
|
|
lru "github.com/hashicorp/golang-lru/v2"
|
|
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
|
)
|
|
|
|
const apiEndpoint = "https://api.wise.com"
|
|
|
|
type apiTransport struct {
|
|
APIKey string
|
|
underlying http.RoundTripper
|
|
}
|
|
|
|
func (t *apiTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", t.APIKey))
|
|
|
|
return t.underlying.RoundTrip(req)
|
|
}
|
|
|
|
//go:generate mockgen -source client.go -destination client_generated.go -package client . Client
|
|
type Client interface {
|
|
GetBalance(ctx context.Context, profileID uint64, balanceID uint64) (*Balance, error)
|
|
GetBalances(ctx context.Context, profileID uint64) ([]Balance, error)
|
|
GetPayout(ctx context.Context, payoutID string) (*Payout, error)
|
|
CreatePayout(ctx context.Context, quote Quote, targetAccount uint64, transactionID string) (*Payout, error)
|
|
GetProfiles(ctx context.Context) ([]Profile, error)
|
|
CreateQuote(ctx context.Context, profileID, currency string, amount json.Number) (Quote, error)
|
|
GetRecipientAccounts(ctx context.Context, profileID uint64, pageSize int, seekPositionForNext uint64) (*RecipientAccountsResponse, error)
|
|
GetRecipientAccount(ctx context.Context, accountID uint64) (*RecipientAccount, error)
|
|
GetTransfers(ctx context.Context, profileID uint64, offset int, limit int) ([]Transfer, error)
|
|
GetTransfer(ctx context.Context, transferID string) (*Transfer, error)
|
|
CreateTransfer(ctx context.Context, quote Quote, targetAccount uint64, transactionID string) (*Transfer, error)
|
|
CreateWebhook(ctx context.Context, profileID uint64, name, triggerOn, url, version string) (*WebhookSubscriptionResponse, error)
|
|
ListWebhooksSubscription(ctx context.Context, profileID uint64) ([]WebhookSubscriptionResponse, error)
|
|
DeleteWebhooks(ctx context.Context, profileID uint64, subscriptionID string) error
|
|
TranslateTransferStateChangedWebhook(ctx context.Context, payload []byte) (Transfer, error)
|
|
TranslateBalanceUpdateWebhook(ctx context.Context, payload []byte) (BalanceUpdateWebhookPayload, error)
|
|
}
|
|
|
|
type client struct {
|
|
httpClient httpwrapper.Client
|
|
|
|
mux *sync.Mutex
|
|
recipientAccountsCache *lru.Cache[uint64, *RecipientAccount]
|
|
}
|
|
|
|
func (c *client) endpoint(path string) string {
|
|
return fmt.Sprintf("%s/%s", apiEndpoint, path)
|
|
}
|
|
|
|
func New(connectorName string, apiKey string) Client {
|
|
recipientsCache, _ := lru.New[uint64, *RecipientAccount](2048)
|
|
config := &httpwrapper.Config{
|
|
Transport: metrics.NewTransport(connectorName, metrics.TransportOpts{Transport: &apiTransport{
|
|
APIKey: apiKey,
|
|
underlying: otelhttp.NewTransport(http.DefaultTransport),
|
|
}}),
|
|
}
|
|
|
|
return &client{
|
|
httpClient: httpwrapper.NewClient(config),
|
|
mux: &sync.Mutex{},
|
|
recipientAccountsCache: recipientsCache,
|
|
}
|
|
}
|