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.
161 lines
4.9 KiB
Go
161 lines
4.9 KiB
Go
package activities
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
"github.com/google/uuid"
|
|
"go.temporal.io/sdk/workflow"
|
|
)
|
|
|
|
type SendEventsPayment struct {
|
|
Payment models.Payment
|
|
Adjustment models.PaymentAdjustment
|
|
}
|
|
|
|
type SendEventsRequest struct {
|
|
ConnectorID *models.ConnectorID
|
|
IdempotencyKey string
|
|
At time.Time
|
|
|
|
Account *models.Account
|
|
Balance *models.Balance
|
|
BankAccount *models.BankAccount
|
|
Payment *SendEventsPayment
|
|
PaymentDeleted *models.PaymentID
|
|
ConnectorReset *models.ConnectorID
|
|
PoolsCreation *models.Pool
|
|
PoolsDeletion *uuid.UUID
|
|
PaymentInitiation *models.PaymentInitiation
|
|
PaymentInitiationAdjustment *models.PaymentInitiationAdjustment
|
|
PaymentInitiationRelatedPayment *models.PaymentInitiationRelatedPayments
|
|
UserPendingDisconnect *models.UserConnectionPendingDisconnect
|
|
UserDisconnected *models.UserDisconnected
|
|
UserConnectionDisconnected *models.UserConnectionDisconnected
|
|
UserConnectionReconnected *models.UserConnectionReconnected
|
|
UserLinkStatus *models.UserLinkSessionFinished
|
|
UserConnectionDataSynced *models.UserConnectionDataSynced
|
|
Task *models.Task
|
|
}
|
|
|
|
// SendEvents
|
|
// Deprecated: from 3.1 we're using outbox pattern, this is kept for backward compatibility
|
|
func (a Activities) SendEvents(ctx context.Context, req SendEventsRequest) error {
|
|
eventID := models.EventID{
|
|
EventIdempotencyKey: req.IdempotencyKey,
|
|
ConnectorID: req.ConnectorID,
|
|
}
|
|
isExisting, err := a.storage.EventsSentExists(ctx, eventID)
|
|
if err != nil {
|
|
return temporalStorageError(err)
|
|
}
|
|
|
|
if isExisting {
|
|
// event was already sent; nothing to do
|
|
return nil
|
|
}
|
|
|
|
// event was not sent yet
|
|
if err := a.sendEvents(ctx, req); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := a.storage.EventsSentUpsert(ctx, models.EventSent{
|
|
ID: eventID,
|
|
ConnectorID: req.ConnectorID,
|
|
SentAt: req.At,
|
|
}); err != nil {
|
|
return temporalStorageError(err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (a Activities) sendEvents(ctx context.Context, req SendEventsRequest) error {
|
|
if req.Account != nil {
|
|
return a.events.Publish(ctx, a.events.NewEventSavedAccounts(*req.Account))
|
|
}
|
|
|
|
if req.Balance != nil {
|
|
return a.events.Publish(ctx, a.events.NewEventSavedBalances(*req.Balance))
|
|
}
|
|
|
|
if req.BankAccount != nil {
|
|
ba, err := a.events.NewEventSavedBankAccounts(*req.BankAccount)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to send bank account: %w", err)
|
|
}
|
|
return a.events.Publish(ctx, ba)
|
|
}
|
|
|
|
if req.Payment != nil {
|
|
return a.events.Publish(ctx, a.events.NewEventSavedPayments(req.Payment.Payment, req.Payment.Adjustment))
|
|
}
|
|
|
|
if req.PaymentDeleted != nil {
|
|
return a.events.Publish(ctx, a.events.NewEventPaymentDeleted(*req.PaymentDeleted))
|
|
}
|
|
|
|
if req.ConnectorReset != nil {
|
|
return a.events.Publish(ctx, a.events.NewEventResetConnector(*req.ConnectorReset, req.At))
|
|
}
|
|
|
|
if req.PoolsCreation != nil {
|
|
return a.events.Publish(ctx, a.events.NewEventSavedPool(*req.PoolsCreation))
|
|
}
|
|
|
|
if req.PoolsDeletion != nil {
|
|
return a.events.Publish(ctx, a.events.NewEventDeletePool(*req.PoolsDeletion))
|
|
}
|
|
|
|
if req.PaymentInitiation != nil {
|
|
return a.events.Publish(ctx, a.events.NewEventSavedPaymentInitiation(*req.PaymentInitiation))
|
|
}
|
|
|
|
if req.PaymentInitiationAdjustment != nil {
|
|
return a.events.Publish(ctx, a.events.NewEventSavedPaymentInitiationAdjustment(*req.PaymentInitiationAdjustment))
|
|
}
|
|
|
|
if req.PaymentInitiationRelatedPayment != nil {
|
|
return a.events.Publish(ctx, a.events.NewEventSavedPaymentInitiationRelatedPayment(*req.PaymentInitiationRelatedPayment))
|
|
}
|
|
|
|
if req.UserPendingDisconnect != nil {
|
|
return a.events.Publish(ctx, a.events.NewEventOpenBankingUserPendingDisconnect(*req.UserPendingDisconnect))
|
|
}
|
|
|
|
if req.UserDisconnected != nil {
|
|
return a.events.Publish(ctx, a.events.NewEventOpenBankingUserDisconnected(*req.UserDisconnected))
|
|
}
|
|
|
|
if req.UserConnectionDisconnected != nil {
|
|
return a.events.Publish(ctx, a.events.NewEventOpenBankingUserConnectionDisconnected(*req.UserConnectionDisconnected))
|
|
}
|
|
|
|
if req.UserConnectionReconnected != nil {
|
|
return a.events.Publish(ctx, a.events.NewEventOpenBankingUserConnectionReconnected(*req.UserConnectionReconnected))
|
|
}
|
|
|
|
if req.UserLinkStatus != nil {
|
|
return a.events.Publish(ctx, a.events.NewEventOpenBankingUserLinkStatus(*req.UserLinkStatus))
|
|
}
|
|
|
|
if req.UserConnectionDataSynced != nil {
|
|
return a.events.Publish(ctx, a.events.NewEventOpenBankingUserConnectionDataSynced(*req.UserConnectionDataSynced))
|
|
}
|
|
|
|
if req.Task != nil {
|
|
return a.events.Publish(ctx, a.events.NewEventUpdatedTask(*req.Task))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
var SendEventsActivity = Activities{}.SendEvents
|
|
|
|
func SendEvents(ctx workflow.Context, req SendEventsRequest) error {
|
|
return executeActivity(ctx, SendEventsActivity, nil, req)
|
|
}
|