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.
122 lines
2.8 KiB
Go
122 lines
2.8 KiB
Go
package workflow
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hanzo-fi/payments/internal/connectors/engine/activities"
|
|
"github.com/hanzo-fi/payments/internal/connectors/engine/utils"
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
"github.com/pkg/errors"
|
|
"go.temporal.io/sdk/workflow"
|
|
)
|
|
|
|
type CreateWebhooks struct {
|
|
ConnectorID models.ConnectorID
|
|
FromPayload *FromPayload
|
|
}
|
|
|
|
func (w Workflow) runCreateWebhooks(
|
|
ctx workflow.Context,
|
|
createWebhooks CreateWebhooks,
|
|
nextTasks []models.ConnectorTaskTree,
|
|
) error {
|
|
return w.createWebhooks(ctx, createWebhooks, nextTasks)
|
|
}
|
|
|
|
func (w Workflow) createWebhooks(
|
|
ctx workflow.Context,
|
|
createWebhooks CreateWebhooks,
|
|
nextTasks []models.ConnectorTaskTree,
|
|
) error {
|
|
webhookBaseURL, err := utils.GetWebhookBaseURL(w.stackPublicURL, createWebhooks.ConnectorID)
|
|
if err != nil {
|
|
return fmt.Errorf("joining webhook base URL: %w", err)
|
|
}
|
|
|
|
resp, err := activities.PluginCreateWebhooks(
|
|
infiniteRetryContext(ctx),
|
|
createWebhooks.ConnectorID,
|
|
models.CreateWebhooksRequest{
|
|
WebhookBaseUrl: webhookBaseURL,
|
|
ConnectorID: createWebhooks.ConnectorID.String(),
|
|
FromPayload: createWebhooks.FromPayload.GetPayload(),
|
|
},
|
|
)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to create webhooks: %w", err)
|
|
}
|
|
|
|
if len(resp.Configs) > 0 {
|
|
configs := make([]models.WebhookConfig, 0, len(resp.Configs))
|
|
for _, c := range resp.Configs {
|
|
configs = append(configs, models.WebhookConfig{
|
|
Name: c.Name,
|
|
ConnectorID: createWebhooks.ConnectorID,
|
|
URLPath: c.URLPath,
|
|
Metadata: c.Metadata,
|
|
})
|
|
}
|
|
err = activities.StorageWebhooksConfigsStore(
|
|
infiniteRetryContext(ctx),
|
|
configs,
|
|
)
|
|
if err != nil {
|
|
return fmt.Errorf("storing webhooks: %w", err)
|
|
}
|
|
}
|
|
|
|
plugin, err := w.connectors.Get(createWebhooks.ConnectorID)
|
|
if err != nil {
|
|
return fmt.Errorf("getting connector: %w", err)
|
|
}
|
|
|
|
wg := workflow.NewWaitGroup(ctx)
|
|
errChan := make(chan error, len(resp.Others)*2)
|
|
|
|
if !IsRunNextTaskOptimizationsEnabled(ctx) {
|
|
for _, other := range resp.Others {
|
|
o := other
|
|
payload := &FromPayload{
|
|
ID: o.ID,
|
|
Payload: o.Other,
|
|
}
|
|
w.runNextTaskAsChildWorkflow(ctx, createWebhooks.ConnectorID, nextTasks, wg, payload, errChan)
|
|
}
|
|
} else {
|
|
if !plugin.IsScheduledForDeletion() {
|
|
for _, other := range resp.Others {
|
|
o := other
|
|
|
|
wg.Add(1)
|
|
workflow.Go(ctx, func(ctx workflow.Context) {
|
|
defer wg.Done()
|
|
|
|
if err := w.runNextTasksV3_1(
|
|
ctx,
|
|
createWebhooks.ConnectorID,
|
|
&FromPayload{
|
|
ID: o.ID,
|
|
Payload: o.Other,
|
|
},
|
|
nextTasks,
|
|
); err != nil {
|
|
errChan <- errors.Wrap(err, "running next tasks")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
wg.Wait(ctx)
|
|
close(errChan)
|
|
for err := range errChan {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
const RunCreateWebhooks = "RunCreateWebhooks"
|