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.
106 lines
2.8 KiB
Go
106 lines
2.8 KiB
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
"github.com/uptrace/bun"
|
|
)
|
|
|
|
type webhookConfig struct {
|
|
bun.BaseModel `bun:"table:webhooks_configs"`
|
|
|
|
// Mandatory fields
|
|
Name string `bun:"name,pk,type:text,notnull"`
|
|
ConnectorID models.ConnectorID `bun:"connector_id,pk,type:character varying,notnull"`
|
|
URLPath string `bun:"url_path,type:text,notnull"`
|
|
|
|
// Optional fields with default
|
|
// c.f. https://bun.uptrace.dev/guide/models.html#default
|
|
Metadata map[string]string `bun:"metadata,type:jsonb,nullzero,notnull,default:'{}'"`
|
|
}
|
|
|
|
func (s *store) WebhooksConfigsUpsert(ctx context.Context, webhooksConfigs []models.WebhookConfig) error {
|
|
toInsert := fromWebhooksConfigsModels(webhooksConfigs)
|
|
|
|
_, err := s.db.NewInsert().
|
|
Model(&toInsert).
|
|
On("CONFLICT (name, connector_id) DO NOTHING").
|
|
Exec(ctx)
|
|
if err != nil {
|
|
return e("upsert webhook config", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *store) WebhooksConfigsGet(ctx context.Context, name string, connectorID models.ConnectorID) (*models.WebhookConfig, error) {
|
|
var webhookConfig webhookConfig
|
|
err := s.db.NewSelect().
|
|
Model(&webhookConfig).
|
|
Where("name = ? AND connector_id = ?", name, connectorID).
|
|
Scan(ctx)
|
|
if err != nil {
|
|
return nil, e("get webhook config", err)
|
|
}
|
|
|
|
return toWebhookConfigModel(webhookConfig), nil
|
|
}
|
|
|
|
func (s *store) WebhooksConfigsGetFromConnectorID(ctx context.Context, connectorID models.ConnectorID) ([]models.WebhookConfig, error) {
|
|
var webhookConfigs []webhookConfig
|
|
err := s.db.NewSelect().
|
|
Model(&webhookConfigs).
|
|
Where("connector_id = ?", connectorID).
|
|
Scan(ctx)
|
|
if err != nil {
|
|
return nil, e("get webhook configs", err)
|
|
}
|
|
|
|
res := make([]models.WebhookConfig, 0, len(webhookConfigs))
|
|
for _, webhookConfig := range webhookConfigs {
|
|
res = append(res, *toWebhookConfigModel(webhookConfig))
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
func (s *store) WebhooksConfigsDeleteFromConnectorID(ctx context.Context, connectorID models.ConnectorID) error {
|
|
_, err := s.db.NewDelete().
|
|
Model((*webhookConfig)(nil)).
|
|
Where("connector_id = ?", connectorID).
|
|
Exec(ctx)
|
|
if err != nil {
|
|
return e("delete webhook config", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func fromWebhookConfigModels(from models.WebhookConfig) webhookConfig {
|
|
return webhookConfig{
|
|
Name: from.Name,
|
|
ConnectorID: from.ConnectorID,
|
|
URLPath: from.URLPath,
|
|
Metadata: from.Metadata,
|
|
}
|
|
}
|
|
|
|
func fromWebhooksConfigsModels(from []models.WebhookConfig) []webhookConfig {
|
|
to := make([]webhookConfig, 0, len(from))
|
|
for _, webhookConfig := range from {
|
|
to = append(to, fromWebhookConfigModels(webhookConfig))
|
|
}
|
|
|
|
return to
|
|
}
|
|
|
|
func toWebhookConfigModel(from webhookConfig) *models.WebhookConfig {
|
|
return &models.WebhookConfig{
|
|
Name: from.Name,
|
|
ConnectorID: from.ConnectorID,
|
|
URLPath: from.URLPath,
|
|
Metadata: from.Metadata,
|
|
}
|
|
}
|