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.
82 lines
2.2 KiB
Go
82 lines
2.2 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"
|
|
)
|
|
|
|
//go:generate mockgen -source client.go -destination client_generated.go -package client . Client
|
|
type Client interface {
|
|
GetOrganization(ctx context.Context) (*Organization, error)
|
|
GetBeneficiaries(ctx context.Context, updatedAtFrom time.Time, page, pageSize int) ([]Beneficiary, error)
|
|
GetTransactions(ctx context.Context, bankAccountId string, updatedAtFrom time.Time, transactionStatusToFetch string, page, pageSize int) ([]Transactions, error)
|
|
}
|
|
|
|
type client struct {
|
|
httpClient httpwrapper.Client
|
|
endpoint string
|
|
}
|
|
|
|
type apiTransport struct {
|
|
clientID string
|
|
underlying http.RoundTripper
|
|
apiKey string
|
|
stagingToken string
|
|
}
|
|
|
|
type MetaPagination struct {
|
|
CurrentPage int `json:"current_page"`
|
|
PrevPage any `json:"prev_page"`
|
|
NextPage any `json:"next_page"`
|
|
TotalPages int `json:"total_pages"`
|
|
PerPage int `json:"per_page"`
|
|
TotalCount int `json:"total_count"`
|
|
}
|
|
|
|
const QontoTimeformat = "2006-01-02T15:04:05.999Z"
|
|
const QontoMaxPageSize = 100
|
|
|
|
func (t *apiTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
auth := fmt.Sprintf("%s:%s", t.clientID, t.apiKey)
|
|
|
|
req.Header.Set("Authorization", auth)
|
|
req.Header.Set("Content-Type", "application/json")
|
|
if t.stagingToken != "" {
|
|
req.Header.Set("X-Qonto-Staging-Token", t.stagingToken)
|
|
}
|
|
return t.underlying.RoundTrip(req)
|
|
}
|
|
|
|
func New(connectorName, clientID, apiKey, endpoint, stagingToken string) Client {
|
|
endpoint = strings.TrimSuffix(endpoint, "/")
|
|
|
|
client := &client{
|
|
endpoint: endpoint,
|
|
}
|
|
|
|
apiTransport := &apiTransport{
|
|
clientID: clientID,
|
|
apiKey: apiKey,
|
|
stagingToken: stagingToken,
|
|
underlying: http.DefaultTransport,
|
|
}
|
|
config := &httpwrapper.Config{
|
|
Transport: metrics.NewTransport(connectorName, metrics.TransportOpts{
|
|
Transport: apiTransport,
|
|
}),
|
|
}
|
|
client.httpClient = httpwrapper.NewClient(config)
|
|
|
|
return client
|
|
}
|
|
|
|
func (c *client) buildEndpoint(path string, args ...interface{}) string {
|
|
return fmt.Sprintf("%s/%s", c.endpoint, fmt.Sprintf(path, args...))
|
|
}
|