refactored payment orchestration

This commit is contained in:
Stephan D
2026-02-03 00:40:46 +01:00
parent 05d998e0f7
commit 5e87e2f2f9
184 changed files with 3920 additions and 2219 deletions

View File

@@ -9,7 +9,7 @@ import (
"github.com/tech/sendico/pkg/ledgerconv"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/model"
"github.com/tech/sendico/pkg/model/account_role"
"github.com/tech/sendico/pkg/payments/rail"
describablev1 "github.com/tech/sendico/pkg/proto/common/describable/v1"
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
@@ -317,7 +317,7 @@ func (c *ledgerClient) BlockAccount(ctx context.Context, req *ledgerv1.BlockAcco
if req == nil || strings.TrimSpace(req.GetLedgerAccountRef()) == "" {
return nil, merrors.InvalidArgument("ledger: ledger_account_ref is required")
}
sourceRole := model.ToProto(accountRoleFromLedgerProto(req.GetRole()))
sourceRole := account_role.ToProto(accountRoleFromLedgerProto(req.GetRole()))
resp, err := c.client.UpdateAccountState(ctx, &connectorv1.UpdateAccountStateRequest{
AccountRef: &connectorv1.AccountRef{ConnectorId: ledgerConnectorID, AccountId: strings.TrimSpace(req.GetLedgerAccountRef())},
TargetState: connectorv1.AccountState_ACCOUNT_SUSPENDED,
@@ -338,7 +338,7 @@ func (c *ledgerClient) UnblockAccount(ctx context.Context, req *ledgerv1.Unblock
if req == nil || strings.TrimSpace(req.GetLedgerAccountRef()) == "" {
return nil, merrors.InvalidArgument("ledger: ledger_account_ref is required")
}
sourceRole := model.ToProto(accountRoleFromLedgerProto(req.GetRole()))
sourceRole := account_role.ToProto(accountRoleFromLedgerProto(req.GetRole()))
resp, err := c.client.UpdateAccountState(ctx, &connectorv1.UpdateAccountStateRequest{
AccountRef: &connectorv1.AccountRef{ConnectorId: ledgerConnectorID, AccountId: strings.TrimSpace(req.GetLedgerAccountRef())},
TargetState: connectorv1.AccountState_ACCOUNT_ACTIVE,
@@ -430,8 +430,8 @@ func (c *ledgerClient) submitLedgerOperationWithExtras(ctx context.Context, opTy
charges []*ledgerv1.PostingLine
eventTime *timestamppb.Timestamp
contraRef string
fromRole model.AccountRole
toRole model.AccountRole
fromRole account_role.AccountRole
toRole account_role.AccountRole
)
switch r := req.(type) {
@@ -487,10 +487,10 @@ func (c *ledgerClient) submitLedgerOperationWithExtras(ctx context.Context, opTy
op.To = accountParty(toRef)
}
if fromRole != "" {
op.FromRole = model.ToProto(fromRole)
op.FromRole = account_role.ToProto(fromRole)
}
if toRole != "" {
op.ToRole = model.ToProto(toRole)
op.ToRole = account_role.ToProto(toRole)
}
resp, err := c.client.SubmitOperation(ctx, &connectorv1.SubmitOperationRequest{Operation: op})
@@ -503,30 +503,30 @@ func (c *ledgerClient) submitLedgerOperationWithExtras(ctx context.Context, opTy
return &ledgerv1.PostResponse{JournalEntryRef: resp.GetReceipt().GetOperationId(), EntryType: entryTypeFromOperation(opType)}, nil
}
func accountRoleFromLedgerProto(role ledgerv1.AccountRole) model.AccountRole {
func accountRoleFromLedgerProto(role ledgerv1.AccountRole) account_role.AccountRole {
switch role {
case ledgerv1.AccountRole_ACCOUNT_ROLE_OPERATING:
return model.AccountRoleOperating
return account_role.AccountRoleOperating
case ledgerv1.AccountRole_ACCOUNT_ROLE_HOLD:
return model.AccountRoleHold
return account_role.AccountRoleHold
case ledgerv1.AccountRole_ACCOUNT_ROLE_TRANSIT:
return model.AccountRoleTransit
return account_role.AccountRoleTransit
case ledgerv1.AccountRole_ACCOUNT_ROLE_SETTLEMENT:
return model.AccountRoleSettlement
return account_role.AccountRoleSettlement
case ledgerv1.AccountRole_ACCOUNT_ROLE_CLEARING:
return model.AccountRoleClearing
return account_role.AccountRoleClearing
case ledgerv1.AccountRole_ACCOUNT_ROLE_PENDING:
return model.AccountRolePending
return account_role.AccountRolePending
case ledgerv1.AccountRole_ACCOUNT_ROLE_RESERVE:
return model.AccountRoleReserve
return account_role.AccountRoleReserve
case ledgerv1.AccountRole_ACCOUNT_ROLE_LIQUIDITY:
return model.AccountRoleLiquidity
return account_role.AccountRoleLiquidity
case ledgerv1.AccountRole_ACCOUNT_ROLE_FEE:
return model.AccountRoleFee
return account_role.AccountRoleFee
case ledgerv1.AccountRole_ACCOUNT_ROLE_CHARGEBACK:
return model.AccountRoleChargeback
return account_role.AccountRoleChargeback
case ledgerv1.AccountRole_ACCOUNT_ROLE_ADJUSTMENT:
return model.AccountRoleAdjustment
return account_role.AccountRoleAdjustment
default:
return ""
}