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.
94 lines
2.6 KiB
Go
94 lines
2.6 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/hanzo-fi/payments/pkg/domain/metrics"
|
|
errorsutils "github.com/hanzo-fi/payments/pkg/domain/errors"
|
|
)
|
|
|
|
type RecipientAccountsResponse struct {
|
|
Content []*RecipientAccount `json:"content"`
|
|
SeekPositionForCurrent uint64 `json:"seekPositionForCurrent"`
|
|
SeekPositionForNext uint64 `json:"seekPositionForNext"`
|
|
Size int `json:"size"`
|
|
}
|
|
|
|
type Name struct {
|
|
FullName string `json:"fullName"`
|
|
}
|
|
|
|
type RecipientAccount struct {
|
|
ID uint64 `json:"id"`
|
|
Profile uint64 `json:"profileId"`
|
|
Currency string `json:"currency"`
|
|
Name Name `json:"name"`
|
|
}
|
|
|
|
func (c *client) GetRecipientAccounts(ctx context.Context, profileID uint64, pageSize int, seekPositionForNext uint64) (*RecipientAccountsResponse, error) {
|
|
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "list_recipient_accounts")
|
|
|
|
req, err := http.NewRequestWithContext(ctx,
|
|
http.MethodGet, c.endpoint("v2/accounts"), http.NoBody)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
q := req.URL.Query()
|
|
q.Add("profile", fmt.Sprintf("%d", profileID))
|
|
q.Add("size", fmt.Sprintf("%d", pageSize))
|
|
q.Add("sort", "id,asc")
|
|
if seekPositionForNext > 0 {
|
|
q.Add("seekPosition", fmt.Sprintf("%d", seekPositionForNext))
|
|
}
|
|
req.URL.RawQuery = q.Encode()
|
|
|
|
var accounts RecipientAccountsResponse
|
|
var errRes wiseErrors
|
|
statusCode, err := c.httpClient.Do(ctx, req, &accounts, &errRes)
|
|
if err != nil {
|
|
return nil, errorsutils.NewWrappedError(
|
|
fmt.Errorf("failed to get recipient accounts: %v", errRes.Error(statusCode)),
|
|
err,
|
|
)
|
|
}
|
|
return &accounts, nil
|
|
}
|
|
|
|
func (c *client) GetRecipientAccount(ctx context.Context, accountID uint64) (*RecipientAccount, error) {
|
|
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "get_recipient_accounts")
|
|
|
|
c.mux.Lock()
|
|
defer c.mux.Unlock()
|
|
if rc, ok := c.recipientAccountsCache.Get(accountID); ok {
|
|
return rc, nil
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(ctx,
|
|
http.MethodGet, c.endpoint(fmt.Sprintf("v1/accounts/%d", accountID)), http.NoBody)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var res RecipientAccount
|
|
var errRes wiseErrors
|
|
statusCode, err := c.httpClient.Do(ctx, req, &res, &errRes)
|
|
if err != nil {
|
|
e := errRes.Error(statusCode)
|
|
if e.Code == "RECIPIENT_MISSING" {
|
|
// This is a valid response, we just don't have the account amongst
|
|
// our recipients.
|
|
return &RecipientAccount{}, nil
|
|
}
|
|
return nil, errorsutils.NewWrappedError(
|
|
fmt.Errorf("failed to get recipient account: %v", e.Error()),
|
|
err,
|
|
)
|
|
}
|
|
|
|
c.recipientAccountsCache.Add(accountID, &res)
|
|
return &res, nil
|
|
}
|