Files
CrimsonandGitHub db0561d07e fix(column): Various fixes for Column Payments (#431)
* Set webhook ID as payment adjustment ID when adjustment created via webhook

* Fetch Column payments oldest to newest

* Ensure that webhook secrets are fetched when containers restart

* Regenerate plugin code for tests

* Add paging to fetch webhook request

* Add WorkerPool unit test to increase test coverage

* Guard against unhandled webhooks in Column plugin initiation

* Rename Timeline.LatestID to Timeline.LastSeenID for clarity

* Add metadata column to webhooks_configs table

* Persist webhook_configs.metadata

* Persist Column webhook secrets as metadata in webhooks_configs

* Remove PSPWebhookConfig from InstallResponse

* Stop passing context to initWebhookConfig()

* Don't pass context to RegisterPlugin func

* Don't pass context to plugins.RegisterPlugin
2025-05-12 09:24:59 +00:00

91 lines
2.6 KiB
Go

package generic
import (
"context"
"encoding/json"
"github.com/formancehq/go-libs/v3/logging"
"github.com/formancehq/payments/internal/connectors/plugins"
"github.com/formancehq/payments/internal/connectors/plugins/public/generic/client"
"github.com/formancehq/payments/internal/connectors/plugins/registry"
"github.com/formancehq/payments/internal/models"
)
const ProviderName = "generic"
func init() {
registry.RegisterPlugin(ProviderName, func(_ models.ConnectorID, name string, logger logging.Logger, rm json.RawMessage) (models.Plugin, error) {
return New(name, logger, rm)
}, capabilities, Config{})
}
type Plugin struct {
models.Plugin
name string
logger logging.Logger
client client.Client
}
func New(name string, logger logging.Logger, rawConfig json.RawMessage) (*Plugin, error) {
config, err := unmarshalAndValidateConfig(rawConfig)
if err != nil {
return nil, err
}
client := client.New(ProviderName, config.APIKey, config.Endpoint)
return &Plugin{
Plugin: plugins.NewBasePlugin(),
name: name,
logger: logger,
client: client,
}, nil
}
func (p *Plugin) Name() string {
return p.name
}
func (p *Plugin) Install(ctx context.Context, req models.InstallRequest) (models.InstallResponse, error) {
return models.InstallResponse{
Workflow: workflow(),
}, nil
}
func (p *Plugin) Uninstall(ctx context.Context, req models.UninstallRequest) (models.UninstallResponse, error) {
return models.UninstallResponse{}, nil
}
func (p *Plugin) FetchNextAccounts(ctx context.Context, req models.FetchNextAccountsRequest) (models.FetchNextAccountsResponse, error) {
if p.client == nil {
return models.FetchNextAccountsResponse{}, plugins.ErrNotYetInstalled
}
return p.fetchNextAccounts(ctx, req)
}
func (p *Plugin) FetchNextBalances(ctx context.Context, req models.FetchNextBalancesRequest) (models.FetchNextBalancesResponse, error) {
if p.client == nil {
return models.FetchNextBalancesResponse{}, plugins.ErrNotYetInstalled
}
return p.fetchNextBalances(ctx, req)
}
func (p *Plugin) FetchNextExternalAccounts(ctx context.Context, req models.FetchNextExternalAccountsRequest) (models.FetchNextExternalAccountsResponse, error) {
if p.client == nil {
return models.FetchNextExternalAccountsResponse{}, plugins.ErrNotYetInstalled
}
return p.fetchExternalAccounts(ctx, req)
}
func (p *Plugin) FetchNextPayments(ctx context.Context, req models.FetchNextPaymentsRequest) (models.FetchNextPaymentsResponse, error) {
if p.client == nil {
return models.FetchNextPaymentsResponse{}, plugins.ErrNotYetInstalled
}
return p.fetchNextPayments(ctx, req)
}
var _ models.Plugin = &Plugin{}