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
255 lines
6.0 KiB
Go
255 lines
6.0 KiB
Go
package models
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const DefaultConnectorClientTimeout = 10 * time.Second
|
|
|
|
type PluginType int
|
|
|
|
const (
|
|
PluginTypePSP PluginType = iota
|
|
PluginTypeOpenBanking
|
|
PluginTypeBoth
|
|
)
|
|
|
|
//go:generate mockgen -source plugin.go -destination plugin_generated.go -package models . Plugin
|
|
type Plugin interface {
|
|
PSPPlugin
|
|
OpenBankingPlugin
|
|
|
|
// Common methods
|
|
Name() string
|
|
// Config is used to fetch back the validated config struct from a plugin
|
|
Config() PluginInternalConfig
|
|
IsScheduledForDeletion() bool
|
|
ScheduleForDeletion(bool)
|
|
Install(context.Context, InstallRequest) (InstallResponse, error)
|
|
Uninstall(context.Context, UninstallRequest) (UninstallResponse, error)
|
|
|
|
CreateWebhooks(context.Context, CreateWebhooksRequest) (CreateWebhooksResponse, error)
|
|
TrimWebhook(context.Context, TrimWebhookRequest) (TrimWebhookResponse, error)
|
|
VerifyWebhook(context.Context, VerifyWebhookRequest) (VerifyWebhookResponse, error)
|
|
TranslateWebhook(context.Context, TranslateWebhookRequest) (TranslateWebhookResponse, error)
|
|
}
|
|
|
|
type InstallRequest struct {
|
|
ConnectorID string
|
|
}
|
|
|
|
type InstallResponse struct {
|
|
Workflow ConnectorTasksTree
|
|
}
|
|
|
|
type UninstallRequest struct {
|
|
ConnectorID string
|
|
WebhookConfigs []PSPWebhookConfig
|
|
}
|
|
|
|
type UninstallResponse struct{}
|
|
|
|
type CreateWebhooksRequest struct {
|
|
FromPayload json.RawMessage
|
|
ConnectorID string
|
|
WebhookBaseUrl string
|
|
}
|
|
|
|
type CreateWebhooksResponse struct {
|
|
Configs []PSPWebhookConfig
|
|
Others []PSPOther // used by plugin workflow
|
|
}
|
|
|
|
type TrimWebhookRequest struct {
|
|
Webhook PSPWebhook
|
|
Config *WebhookConfig
|
|
}
|
|
|
|
type TrimWebhookResponse struct {
|
|
Webhooks []PSPWebhook
|
|
}
|
|
|
|
type VerifyWebhookRequest struct {
|
|
Webhook PSPWebhook
|
|
Config *WebhookConfig
|
|
}
|
|
|
|
type VerifyWebhookResponse struct {
|
|
WebhookIdempotencyKey *string
|
|
}
|
|
|
|
type TranslateWebhookRequest struct {
|
|
Name string
|
|
Webhook PSPWebhook
|
|
Config *WebhookConfig
|
|
}
|
|
|
|
type TranslateWebhookResponse struct {
|
|
Responses []WebhookResponse
|
|
}
|
|
|
|
type WebhookResponse struct {
|
|
Account *PSPAccount
|
|
ExternalAccount *PSPAccount
|
|
Payment *PSPPayment
|
|
PaymentToDelete *PSPPaymentsToDelete
|
|
PaymentToCancel *PSPPaymentsToCancel
|
|
Balance *PSPBalance
|
|
|
|
OpenBankingAccount *PSPOpenBankingAccount
|
|
OpenBankingPayment *PSPOpenBankingPayment
|
|
|
|
// Webhooks related to open banking
|
|
UserLinkSessionFinished *PSPUserLinkSessionFinished
|
|
DataReadyToFetch *PSPDataReadyToFetch
|
|
UserDisconnected *PSPUserDisconnected
|
|
UserConnectionPendingDisconnect *PSPUserConnectionPendingDisconnect
|
|
UserConnectionDisconnected *PSPUserConnectionDisconnected
|
|
UserConnectionReconnected *PSPUserConnectionReconnected
|
|
}
|
|
|
|
type OpenBankingDataToFetch string
|
|
|
|
const (
|
|
OpenBankingDataToFetchPayments OpenBankingDataToFetch = "payments"
|
|
OpenBankingDataToFetchAccountsAndBalances OpenBankingDataToFetch = "accounts_and_balances"
|
|
)
|
|
|
|
type PSPDataReadyToFetch struct {
|
|
PSUID *uuid.UUID
|
|
ConnectionID *string
|
|
FromPayload json.RawMessage
|
|
DataToFetch []OpenBankingDataToFetch
|
|
}
|
|
|
|
type PSPDataToDelete struct {
|
|
ConnectionID string
|
|
|
|
// If filled, the account and all its data will be deleted. The connection
|
|
// ID will still be available in the database.
|
|
// If not filled, all data associated with the connection will be deleted.
|
|
AccountID *string
|
|
|
|
FromPayload json.RawMessage
|
|
}
|
|
|
|
type PSPUserDisconnected struct {
|
|
PSPUserID string
|
|
}
|
|
|
|
type PSPUserConnectionPendingDisconnect struct {
|
|
ConnectionID string
|
|
At time.Time
|
|
Reason *string
|
|
}
|
|
|
|
type UserConnectionPendingDisconnect struct {
|
|
PsuID uuid.UUID
|
|
ConnectorID ConnectorID
|
|
ConnectionID string
|
|
At time.Time
|
|
Reason *string
|
|
}
|
|
|
|
func (u UserConnectionPendingDisconnect) IdempotencyKey() string {
|
|
return IdempotencyKey(u)
|
|
}
|
|
|
|
type ConnectionDisconnectedErrorType string
|
|
|
|
const (
|
|
ConnectionDisconnectedErrorTypeTemporaryError ConnectionDisconnectedErrorType = "TEMPORARY_ERROR"
|
|
ConnectionDisconnectedErrorTypeNonRecoverable ConnectionDisconnectedErrorType = "NON_RECOVERABLE"
|
|
ConnectionDisconnectedErrorTypeUserActionNeeded ConnectionDisconnectedErrorType = "USER_ACTION_NEEDED"
|
|
)
|
|
|
|
type PSPUserConnectionDisconnected struct {
|
|
PSPUserID string
|
|
ConnectionID string
|
|
At time.Time
|
|
ErrorType ConnectionDisconnectedErrorType
|
|
Reason *string
|
|
}
|
|
|
|
type PSPUserConnectionReconnected struct {
|
|
PSPUserID string
|
|
ConnectionID string
|
|
At time.Time
|
|
}
|
|
|
|
type UserDisconnected struct {
|
|
PsuID uuid.UUID
|
|
ConnectorID ConnectorID
|
|
At time.Time
|
|
Reason *string
|
|
}
|
|
|
|
func (u UserDisconnected) IdempotencyKey() string {
|
|
return IdempotencyKey(u)
|
|
}
|
|
|
|
type UserConnectionDisconnected struct {
|
|
PSPUserID string
|
|
PsuID uuid.UUID
|
|
ConnectorID ConnectorID
|
|
ConnectionID string
|
|
ErrorType ConnectionDisconnectedErrorType
|
|
At time.Time
|
|
Reason *string
|
|
}
|
|
|
|
func (u UserConnectionDisconnected) IdempotencyKey() string {
|
|
return IdempotencyKey(u)
|
|
}
|
|
|
|
type UserConnectionReconnected struct {
|
|
PsuID uuid.UUID
|
|
ConnectorID ConnectorID
|
|
ConnectionID string
|
|
At time.Time
|
|
}
|
|
|
|
func (u UserConnectionReconnected) IdempotencyKey() string {
|
|
return IdempotencyKey(u)
|
|
}
|
|
|
|
type PSPUserLinkSessionFinished struct {
|
|
AttemptID uuid.UUID
|
|
Status OpenBankingConnectionAttemptStatus
|
|
Error *string
|
|
}
|
|
|
|
type UserLinkSessionFinished struct {
|
|
PsuID uuid.UUID
|
|
ConnectorID ConnectorID
|
|
AttemptID uuid.UUID
|
|
Status OpenBankingConnectionAttemptStatus
|
|
Error *string
|
|
}
|
|
|
|
func (u UserLinkSessionFinished) IdempotencyKey() string {
|
|
return IdempotencyKey(u)
|
|
}
|
|
|
|
type UserConnectionDataSynced struct {
|
|
PsuID uuid.UUID
|
|
ConnectorID ConnectorID
|
|
ConnectionID string
|
|
At time.Time
|
|
}
|
|
|
|
func (u UserConnectionDataSynced) IdempotencyKey() string {
|
|
return IdempotencyKey(u)
|
|
}
|
|
|
|
type OpenBankingForwardedUserFromPayload struct {
|
|
PSUID uuid.UUID
|
|
OpenBankingForwardedUser *OpenBankingForwardedUser
|
|
OpenBankingConnection *OpenBankingConnection
|
|
FromPayload json.RawMessage
|
|
}
|