Files
CrimsonandGitHub 538a2d0de2 chore: Refactor models and other shareable packages into importable pkg (#762)
* Move models and other shareable code to pkg/domain and add own go.mod

* Update all references to use pkg/domain paths

* Fix generated file

* Ensure pkg/domain tests are run by just tests

* Use new models path in connector templates

* Copy local pkg/domain in dockerfile

* Ensure pkg/domain is subject to go generate
2026-06-23 13:08:32 +00:00

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
}