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

97 lines
3.0 KiB
Go

package client
import (
"context"
"fmt"
"net/http"
"github.com/adyen/adyen-go-api-library/v7/src/adyen"
"github.com/adyen/adyen-go-api-library/v7/src/common"
"github.com/adyen/adyen-go-api-library/v7/src/management"
"github.com/adyen/adyen-go-api-library/v7/src/webhook"
"github.com/hanzo-fi/payments/pkg/domain/httpwrapper"
"github.com/hanzo-fi/payments/pkg/domain/metrics"
"github.com/hanzo-fi/payments/pkg/domain/models"
errorsutils "github.com/hanzo-fi/payments/pkg/domain/errors"
)
//go:generate mockgen -source client.go -destination client_generated.go -package client . Client
type Client interface {
GetMerchantAccounts(ctx context.Context, pageNumber, pageSize int32) ([]management.Merchant, error)
CreateWebhook(ctx context.Context, url string, connectorID string) (CreateWebhookResponse, error)
VerifyWebhookBasicAuth(basicAuth *models.BasicAuth) bool
VerifyWebhookHMAC(item webhook.NotificationItem, hmacKey string) bool
DeleteWebhook(ctx context.Context, connectorID string) error
TranslateWebhook(req string) (*webhook.Webhook, error)
}
type client struct {
client *adyen.APIClient
webhookUsername string
webhookPassword string
companyID string
standardWebhook *management.Webhook
}
func New(
provider string,
apiKey string,
username string,
password string,
companyID string,
liveEndpointPrefix string,
) Client {
adyenConfig := &common.Config{
ApiKey: apiKey,
Environment: common.TestEnv,
Debug: true,
HTTPClient: metrics.NewHTTPClient(provider, models.DefaultConnectorClientTimeout),
}
if liveEndpointPrefix != "" {
adyenConfig.Environment = common.LiveEnv
adyenConfig.LiveEndpointURLPrefix = liveEndpointPrefix
adyenConfig.Debug = false
}
c := adyen.NewClient(adyenConfig)
return &client{
client: c,
webhookUsername: username,
webhookPassword: password,
companyID: companyID,
}
}
// wrap a public error for cases that we don't want to retry
// so that activities can classify this error for temporal
func (c *client) wrapSDKError(err error, statusCode int) error {
switch statusCode {
case http.StatusTooManyRequests:
return errorsutils.NewWrappedError(err, httpwrapper.ErrStatusCodeTooManyRequests)
case http.StatusRequestTimeout:
return errorsutils.NewWrappedError(err, httpwrapper.ErrStatusCodeRequestTimeout)
case http.StatusMisdirectedRequest:
return errorsutils.NewWrappedError(err, httpwrapper.ErrStatusCodeMisdirectedRequest)
case http.StatusLocked:
return errorsutils.NewWrappedError(err, httpwrapper.ErrStatusCodeLocked)
case http.StatusTooEarly:
return errorsutils.NewWrappedError(err, httpwrapper.ErrStatusCodeTooEarly)
}
if statusCode >= http.StatusBadRequest && statusCode < http.StatusInternalServerError {
return errorsutils.NewWrappedError(err, httpwrapper.ErrStatusCodeClientError)
}
// Adyen SDK doesn't appear to catch anything above 500
// let's return an error here too even if it was nil
if statusCode >= http.StatusInternalServerError {
return fmt.Errorf("unexpected status code %d: %w", statusCode, err)
}
return err
}