mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* chore: rename RunNextTasks workflow * feat: added a trimmed down type for connector only containing the id * feat: make runNextTask use connectorIdOnly * feat: added isScheduledForDeletion to plugin interface * feat: add scheduledForDeletion at plugin level * feat: refactor manager.Load to take a connector instead of parts of it * feat: saves the connector's scheduledFOrDeletion into the plugin * feat: use plugin.IsScheduledForDeletion instead of loading connector * fix: make e2e tests less flaky * fix: remove config from most request types * feat: (WIP) remove config from runNextTask * fix: remove unneeded method definitions in each plugin * fix: simplify RunNextFlow as anyway we need to change the parameters * fix: add a workflow compatible with previous version for runNextTasks * fix(EN-577): added back RunSendEvents as a deprecated workflow * fix(EN-577): added back RunUpdatePaymentInitiationFromPayment as a deprecated workflow * fix: fix linting directives * fix: replace old usage with refactored one * fix: added back missing deprecated activities * fix: ensure fetch_next_balance works with v3.0 code * fix: simplify a bit the versionning etc * fix: quick refactor before applying solution elsewhere * fix: add back RunSendEvents and RunNextTask child workflows where necessary for backward compatibility * fix: add back missing activity, seems like it's mandatory? * fix: run payment initiation update as child workflow when necessary * fix: missing activy call in test, refine some todos * fix: lint * fix: ensure we always reload plugins into the manager -- so exposing isScheduledForDeletion * fix: ensure we stop storing clear config in temporal * fix: make store config support plain text config * fix: some comments * fix: change runSendEvent workflow to be match what we had in 3.0 * feat: enable worker versionning to avoid workflow from new version to get executed on old code * fix: lint * fix: revert worker versionning * fix: minor code review comments * fix: add context to Encrypt & Decrypt methods * fix: improve lint, add couple tests * fix: use atomic to handle isScheduledForDeletion * fix: make create_events work on migration * fix: avoid returning channel; just send what is needed in runSendEventAsChildWorkflow and runNextTaskAsChildWorkflow * fix: remove extra call to installWorkflow on start plugin * fix: typo in error log line * fix: simplify errChan initialization * fix: clarify feature flag names
196 lines
5.5 KiB
Go
196 lines
5.5 KiB
Go
package tink
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/formancehq/go-libs/v3/logging"
|
|
"github.com/formancehq/payments/internal/connectors/plugins"
|
|
"github.com/formancehq/payments/internal/connectors/plugins/public/tink/client"
|
|
"github.com/formancehq/payments/internal/connectors/plugins/registry"
|
|
"github.com/formancehq/payments/internal/models"
|
|
)
|
|
|
|
const ProviderName = "tink"
|
|
|
|
func init() {
|
|
registry.RegisterPlugin(ProviderName, models.PluginTypeOpenBanking, func(_ models.ConnectorID, name string, logger logging.Logger, rm json.RawMessage) (models.Plugin, error) {
|
|
return New(name, logger, rm)
|
|
}, capabilities, Config{}, PAGE_SIZE)
|
|
}
|
|
|
|
type Plugin struct {
|
|
models.Plugin
|
|
|
|
name string
|
|
logger logging.Logger
|
|
|
|
clientID string
|
|
client client.Client
|
|
config Config
|
|
|
|
supportedWebhooks map[client.WebhookEventType]supportedWebhook
|
|
}
|
|
|
|
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(name, config.ClientID, config.ClientSecret, config.Endpoint)
|
|
|
|
p := &Plugin{
|
|
Plugin: plugins.NewBasePlugin(),
|
|
|
|
name: name,
|
|
logger: logger,
|
|
|
|
clientID: config.ClientID,
|
|
client: client,
|
|
config: config,
|
|
}
|
|
|
|
p.initWebhookConfig()
|
|
|
|
return p, nil
|
|
}
|
|
|
|
func (p *Plugin) Name() string {
|
|
return p.name
|
|
}
|
|
|
|
func (p *Plugin) Config() models.PluginInternalConfig {
|
|
return p.config
|
|
}
|
|
|
|
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) {
|
|
if p.client == nil {
|
|
return models.UninstallResponse{}, plugins.ErrNotYetInstalled
|
|
}
|
|
|
|
err := p.deleteWebhooks(ctx, req)
|
|
if err != nil {
|
|
return models.UninstallResponse{}, err
|
|
}
|
|
|
|
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) FetchNextPayments(ctx context.Context, req models.FetchNextPaymentsRequest) (models.FetchNextPaymentsResponse, error) {
|
|
if p.client == nil {
|
|
return models.FetchNextPaymentsResponse{}, plugins.ErrNotYetInstalled
|
|
}
|
|
return p.fetchNextPayments(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) CreateUser(ctx context.Context, req models.CreateUserRequest) (models.CreateUserResponse, error) {
|
|
if p.client == nil {
|
|
return models.CreateUserResponse{}, plugins.ErrNotYetInstalled
|
|
}
|
|
|
|
return p.createUser(ctx, req)
|
|
}
|
|
|
|
func (p *Plugin) CreateUserLink(ctx context.Context, req models.CreateUserLinkRequest) (models.CreateUserLinkResponse, error) {
|
|
if p.client == nil {
|
|
return models.CreateUserLinkResponse{}, plugins.ErrNotYetInstalled
|
|
}
|
|
|
|
return p.createUserLink(ctx, req)
|
|
}
|
|
|
|
func (p *Plugin) UpdateUserLink(ctx context.Context, req models.UpdateUserLinkRequest) (models.UpdateUserLinkResponse, error) {
|
|
if p.client == nil {
|
|
return models.UpdateUserLinkResponse{}, plugins.ErrNotYetInstalled
|
|
}
|
|
|
|
return p.updateUserLink(ctx, req)
|
|
}
|
|
|
|
func (p *Plugin) CompleteUserLink(ctx context.Context, req models.CompleteUserLinkRequest) (models.CompleteUserLinkResponse, error) {
|
|
if p.client == nil {
|
|
return models.CompleteUserLinkResponse{}, plugins.ErrNotYetInstalled
|
|
}
|
|
|
|
return p.completeUserLink(ctx, req)
|
|
}
|
|
|
|
func (p *Plugin) DeleteUserConnection(ctx context.Context, req models.DeleteUserConnectionRequest) (models.DeleteUserConnectionResponse, error) {
|
|
if p.client == nil {
|
|
return models.DeleteUserConnectionResponse{}, plugins.ErrNotYetInstalled
|
|
}
|
|
|
|
return p.deleteUserConnection(ctx, req)
|
|
}
|
|
|
|
func (p *Plugin) DeleteUser(ctx context.Context, req models.DeleteUserRequest) (models.DeleteUserResponse, error) {
|
|
if p.client == nil {
|
|
return models.DeleteUserResponse{}, plugins.ErrNotYetInstalled
|
|
}
|
|
|
|
return p.deleteUser(ctx, req)
|
|
}
|
|
|
|
func (p *Plugin) CreateWebhooks(ctx context.Context, req models.CreateWebhooksRequest) (models.CreateWebhooksResponse, error) {
|
|
if p.client == nil {
|
|
return models.CreateWebhooksResponse{}, plugins.ErrNotYetInstalled
|
|
}
|
|
|
|
return p.createWebhooks(ctx, req)
|
|
}
|
|
|
|
func (p *Plugin) VerifyWebhook(ctx context.Context, req models.VerifyWebhookRequest) (models.VerifyWebhookResponse, error) {
|
|
if p.client == nil {
|
|
return models.VerifyWebhookResponse{}, plugins.ErrNotYetInstalled
|
|
}
|
|
|
|
return p.verifyWebhook(ctx, req)
|
|
}
|
|
|
|
func (p *Plugin) TranslateWebhook(ctx context.Context, req models.TranslateWebhookRequest) (models.TranslateWebhookResponse, error) {
|
|
if p.client == nil {
|
|
return models.TranslateWebhookResponse{}, plugins.ErrNotYetInstalled
|
|
}
|
|
|
|
if req.Name == "" {
|
|
return models.TranslateWebhookResponse{}, fmt.Errorf("missing webhook name: %w", models.ErrInvalidRequest)
|
|
}
|
|
|
|
webhookTranslator, ok := p.supportedWebhooks[client.WebhookEventType(req.Name)]
|
|
if !ok {
|
|
return models.TranslateWebhookResponse{}, fmt.Errorf("unsupported webhook event type: %s", req.Name)
|
|
}
|
|
|
|
resp, err := webhookTranslator.fn(ctx, req)
|
|
if err != nil {
|
|
return models.TranslateWebhookResponse{}, err
|
|
}
|
|
|
|
return models.TranslateWebhookResponse{
|
|
Responses: resp,
|
|
}, nil
|
|
}
|