Skip to content

Commit

Permalink
feat(orchestration): update with last payments version (#857)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-nicolas authored Nov 15, 2023
1 parent a35834a commit 4fd415b
Show file tree
Hide file tree
Showing 243 changed files with 5,152 additions and 1,726 deletions.
4 changes: 2 additions & 2 deletions components/fctl/cmd/payments/accounts/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ func (c *ListController) Render(cmd *cobra.Command, args []string) error {
acc.ID,
acc.AccountName,
acc.CreatedAt.Format(time.RFC3339),
string(acc.Provider),
string(acc.ConnectorID),
acc.DefaultAsset,
acc.DefaultCurrency,
acc.Reference,
acc.Type,
}
})
tableData = fctl.Prepend(tableData, []string{"ID", "AccountName", "CreatedAt",
"Provider", "DefaultAsset", "DefaultCurrency", "Reference", "Type"})
"ConnectorID", "DefaultAsset", "DefaultCurrency", "Reference", "Type"})
return pterm.DefaultTable.
WithHasHeader().
WithWriter(cmd.OutOrStdout()).
Expand Down
2 changes: 1 addition & 1 deletion components/fctl/cmd/payments/accounts/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (c *ShowController) Render(cmd *cobra.Command, args []string) error {
tableData = append(tableData, []string{pterm.LightCyan("ID"), c.store.Account.ID})
tableData = append(tableData, []string{pterm.LightCyan("AccountName"), c.store.Account.AccountName})
tableData = append(tableData, []string{pterm.LightCyan("CreatedAt"), c.store.Account.CreatedAt.Format(time.RFC3339)})
tableData = append(tableData, []string{pterm.LightCyan("Provider"), string(c.store.Account.Provider)})
tableData = append(tableData, []string{pterm.LightCyan("ConnectorID"), string(c.store.Account.ConnectorID)})
tableData = append(tableData, []string{pterm.LightCyan("DefaultAsset"), c.store.Account.DefaultAsset})
tableData = append(tableData, []string{pterm.LightCyan("DefaultCurrency"), c.store.Account.DefaultCurrency})
tableData = append(tableData, []string{pterm.LightCyan("Reference"), c.store.Account.Reference})
Expand Down
4 changes: 2 additions & 2 deletions components/fctl/cmd/payments/bankaccounts/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ func (c *ListController) Render(cmd *cobra.Command, args []string) error {
bc.ID,
bc.CreatedAt.Format(time.RFC3339),
bc.Country,
string(bc.Provider),
string(bc.ConnectorID),
}
})
tableData = fctl.Prepend(tableData, []string{"ID", "CreatedAt", "Country", "Provider"})
tableData = fctl.Prepend(tableData, []string{"ID", "CreatedAt", "Country", "ConnectorID"})
return pterm.DefaultTable.
WithHasHeader().
WithWriter(cmd.OutOrStdout()).
Expand Down
2 changes: 1 addition & 1 deletion components/fctl/cmd/payments/bankaccounts/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (c *ShowController) Render(cmd *cobra.Command, args []string) error {
tableData = append(tableData, []string{pterm.LightCyan("ID"), c.store.BankAccount.ID})
tableData = append(tableData, []string{pterm.LightCyan("CreatedAt"), c.store.BankAccount.CreatedAt.Format(time.RFC3339)})
tableData = append(tableData, []string{pterm.LightCyan("Country"), c.store.BankAccount.Country})
tableData = append(tableData, []string{pterm.LightCyan("Provider"), string(c.store.BankAccount.Provider)})
tableData = append(tableData, []string{pterm.LightCyan("ConnectorID"), string(c.store.BankAccount.ConnectorID)})

if err := pterm.DefaultTable.
WithWriter(cmd.OutOrStdout()).
Expand Down
7 changes: 4 additions & 3 deletions components/fctl/cmd/payments/connectors/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ func (c *PaymentsConnectorsListController) Run(cmd *cobra.Command, args []string
func (c *PaymentsConnectorsListController) Render(cmd *cobra.Command, args []string) error {
tableData := fctl.Map(c.store.Connectors, func(connector shared.ConnectorsResponseData) []string {
return []string{
string(*connector.Provider),
fctl.BoolToString(*connector.Enabled),
connector.ConnectorID,
connector.Name,
string(connector.Provider),
}
})
tableData = fctl.Prepend(tableData, []string{"Provider", "Enabled"})
tableData = fctl.Prepend(tableData, []string{"ConnectorID", "Name", "Provider"})
return pterm.DefaultTable.
WithHasHeader().
WithWriter(cmd.OutOrStdout()).
Expand Down
4 changes: 2 additions & 2 deletions components/fctl/cmd/payments/payments/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ func (c *ListController) Render(cmd *cobra.Command, args []string) error {
payment.Reference,
payment.SourceAccountID,
payment.DestinationAccountID,
string(payment.Provider),
string(payment.ConnectorID),
payment.CreatedAt.Format(time.RFC3339),
}
})
tableData = fctl.Prepend(tableData, []string{"ID", "Type", "Amount", "Asset", "Status",
"Scheme", "Reference", "Source Account ID", "Destination Account ID", "Provider", "Created at"})
"Scheme", "Reference", "Source Account ID", "Destination Account ID", "ConnectorID", "Created at"})
return pterm.DefaultTable.
WithHasHeader().
WithWriter(cmd.OutOrStdout()).
Expand Down
4 changes: 2 additions & 2 deletions components/fctl/cmd/payments/transferinitiation/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (c *ListController) Render(cmd *cobra.Command, args []string) error {
tf.Description,
tf.SourceAccountID,
tf.DestinationAccountID,
string(tf.Provider),
string(tf.ConnectorID),
string(tf.Type),
fmt.Sprint(tf.Amount),
tf.Asset,
Expand All @@ -94,7 +94,7 @@ func (c *ListController) Render(cmd *cobra.Command, args []string) error {
}
})
tableData = fctl.Prepend(tableData, []string{"ID", "CreatedAt", "UpdatedAt", "Description", "Source Account ID",
"Destination Account ID", "Provider", "Type", "Amount", "Asset", "Status", "Error"})
"Destination Account ID", "ConnectorID", "Type", "Amount", "Asset", "Status", "Error"})
return pterm.DefaultTable.
WithHasHeader().
WithWriter(cmd.OutOrStdout()).
Expand Down
2 changes: 1 addition & 1 deletion components/fctl/cmd/payments/transferinitiation/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (c *ShowController) Render(cmd *cobra.Command, args []string) error {
tableData = append(tableData, []string{pterm.LightCyan("Description"), c.store.TransferInitiation.Description})
tableData = append(tableData, []string{pterm.LightCyan("SourceAccountID"), c.store.TransferInitiation.SourceAccountID})
tableData = append(tableData, []string{pterm.LightCyan("DestinationAccountID"), c.store.TransferInitiation.DestinationAccountID})
tableData = append(tableData, []string{pterm.LightCyan("Provider"), string(c.store.TransferInitiation.Provider)})
tableData = append(tableData, []string{pterm.LightCyan("ConnectorID"), string(c.store.TransferInitiation.ConnectorID)})
tableData = append(tableData, []string{pterm.LightCyan("Type"), string(c.store.TransferInitiation.Type)})
tableData = append(tableData, []string{pterm.LightCyan("Amount"), fmt.Sprint(c.store.TransferInitiation.Amount)})
tableData = append(tableData, []string{pterm.LightCyan("Asset"), c.store.TransferInitiation.Asset})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"time"

"github.com/formancehq/formance-sdk-go/pkg/models/shared"
"go.temporal.io/sdk/activity"
Expand All @@ -13,12 +12,13 @@ import (

func (a Activities) StripeTransfer(ctx context.Context, request shared.ActivityStripeTransfer) error {
activityInfo := activity.GetInfo(ctx)
provider := shared.ConnectorStripe
ti := shared.TransferInitiationRequest{
Amount: request.Amount,
Asset: *request.Asset,
CreatedAt: time.Now(),
DestinationAccountID: *request.Destination,
Provider: shared.ConnectorStripe,
ConnectorID: request.ConnectorID,
Provider: &provider,
Type: shared.TransferInitiationRequestTypeTransfer,
Reference: activityInfo.WorkflowExecution.ID + activityInfo.ActivityID,
Validated: true, // No need to validate
Expand Down
10 changes: 6 additions & 4 deletions components/orchestration/internal/workflow/stages/send/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ func RunSend(ctx workflow.Context, send Send) (err error) {
case send.Source.Account != nil && send.Destination.Account != nil:
return runAccountToAccount(ctx, send.Source.Account, send.Destination.Account, amount)
case send.Source.Account != nil && send.Destination.Payment != nil:
return runAccountToPayment(ctx, send.Source.Account, send.Destination.Payment, amount)
return runAccountToPayment(ctx, send.ConnectorID, send.Source.Account, send.Destination.Payment, amount)
case send.Source.Account != nil && send.Destination.Wallet != nil:
return runAccountToWallet(ctx, send.Source.Account, send.Destination.Wallet, amount)
case send.Source.Wallet != nil && send.Destination.Account != nil:
return runWalletToAccount(ctx, send.Source.Wallet, send.Destination.Account, amount)
case send.Source.Wallet != nil && send.Destination.Payment != nil:
return runWalletToPayment(ctx, send.Source.Wallet, send.Destination.Payment, amount)
return runWalletToPayment(ctx, send.ConnectorID, send.Source.Wallet, send.Destination.Payment, amount)
case send.Source.Wallet != nil && send.Destination.Wallet != nil:
return runWalletToWallet(ctx, send.Source.Wallet, send.Destination.Wallet, amount)
case send.Source.Payment != nil && send.Destination.Account != nil:
Expand Down Expand Up @@ -189,7 +189,7 @@ func runWalletToWallet(ctx workflow.Context, source *WalletSource, destination *
})
}

func runWalletToPayment(ctx workflow.Context, source *WalletSource, destination *PaymentDestination, amount *shared.Monetary) error {
func runWalletToPayment(ctx workflow.Context, connectorID *string, source *WalletSource, destination *PaymentDestination, amount *shared.Monetary) error {
if amount == nil {
return errors.New("amount must be specified")
}
Expand All @@ -210,6 +210,7 @@ func runWalletToPayment(ctx workflow.Context, source *WalletSource, destination
Amount: amount.Amount,
Asset: &amount.Asset,
Destination: &stripeConnectID,
ConnectorID: connectorID,
}); err != nil {
return err
}
Expand Down Expand Up @@ -355,7 +356,7 @@ func runAccountToAccount(ctx workflow.Context, source *LedgerAccountSource, dest
}))
}

func runAccountToPayment(ctx workflow.Context, source *LedgerAccountSource, destination *PaymentDestination, amount *shared.Monetary) error {
func runAccountToPayment(ctx workflow.Context, connectorID *string, source *LedgerAccountSource, destination *PaymentDestination, amount *shared.Monetary) error {
if amount == nil {
return errors.New("amount must be specified")
}
Expand All @@ -375,6 +376,7 @@ func runAccountToPayment(ctx workflow.Context, source *LedgerAccountSource, dest
Amount: amount.Amount,
Asset: &amount.Asset,
Destination: &stripeConnectID,
ConnectorID: connectorID,
}); err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ var (
Data: shared.Payment{
InitialAmount: big.NewInt(100),
Asset: "USD",
Provider: shared.ConnectorStripe,
Status: shared.PaymentStatusSucceeded,
Scheme: shared.PaymentSchemeUnknown,
Type: shared.PaymentTypeOther,
Expand Down Expand Up @@ -244,7 +243,6 @@ var (
Data: shared.Payment{
InitialAmount: big.NewInt(100),
Asset: "USD",
Provider: shared.ConnectorStripe,
Status: shared.PaymentStatusSucceeded,
Scheme: shared.PaymentSchemeUnknown,
Type: shared.PaymentTypeOther,
Expand Down Expand Up @@ -344,7 +342,6 @@ var (
Data: shared.Payment{
InitialAmount: big.NewInt(100),
Asset: "USD",
Provider: shared.ConnectorStripe,
Status: shared.PaymentStatusSucceeded,
Scheme: shared.PaymentSchemeUnknown,
Type: shared.PaymentTypeOther,
Expand Down Expand Up @@ -651,6 +648,7 @@ var (
accountToPayment = stagestesting.WorkflowTestCase[Send]{
Name: "account to payment",
Stage: Send{
ConnectorID: nil,
Source: NewSource().WithAccount(&LedgerAccountSource{
ID: "foo",
Ledger: "default",
Expand Down Expand Up @@ -989,6 +987,7 @@ var (
walletToPayment = stagestesting.WorkflowTestCase[Send]{
Name: "wallet to payment",
Stage: Send{
ConnectorID: nil,
Source: NewSource().WithWallet(&WalletSource{
ID: "foo",
Balance: "main",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (s Destination) WithAccount(src *LedgerAccountDestination) Destination {
type Send struct {
Source Source `json:"source"`
Destination Destination `json:"destination"`
ConnectorID *string `json:"connectorId,omitempty"`
Amount *shared.Monetary `json:"amount,omitempty"`
}

Expand Down
2 changes: 2 additions & 0 deletions components/orchestration/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,8 @@ components:
StripeTransferRequest:
type: object
properties:
connectorID:
type: string
amount:
type: integer
format: bigint
Expand Down
14 changes: 13 additions & 1 deletion components/payments/internal/app/api/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ func uninstall[Config models.ConnectorConfigObject](connectorManager *integratio
}
}

type installResponse struct {
ConnectorID string `json:"connectorID"`
}

func install[Config models.ConnectorConfigObject](connectorManager *integration.ConnectorManager[Config],
) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -232,7 +236,15 @@ func install[Config models.ConnectorConfigObject](connectorManager *integration.
return
}

w.WriteHeader(http.StatusNoContent)
w.WriteHeader(http.StatusCreated)
err = json.NewEncoder(w).Encode(api.BaseResponse[installResponse]{
Data: &installResponse{
ConnectorID: "",
},
})
if err != nil {
panic(err)
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions components/payments/internal/app/api/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type paymentResponse struct {
SourceAccountID string `json:"sourceAccountID"`
DestinationAccountID string `json:"destinationAccountID"`
Type string `json:"type"`
ConnectorID string `json:"connectorID"`
Provider models.ConnectorProvider `json:"provider"`
Status models.PaymentStatus `json:"status"`
InitialAmount *big.Int `json:"initialAmount"`
Expand Down Expand Up @@ -105,6 +106,7 @@ func listPaymentsHandler(repo listPaymentsRepository) http.HandlerFunc {
Reference: ret[i].Reference,
Type: ret[i].Type.String(),
Provider: ret[i].Connector.Provider,
ConnectorID: ret[i].Connector.ID.String(),
Status: ret[i].Status,
InitialAmount: ret[i].Amount,
Scheme: ret[i].Scheme,
Expand Down Expand Up @@ -179,6 +181,7 @@ func readPaymentHandler(repo readPaymentRepository) http.HandlerFunc {
ID: payment.ID.String(),
Reference: payment.Reference,
Type: payment.Type.String(),
ConnectorID: payment.Connector.ID.String(),
Provider: payment.Connector.Provider,
Status: payment.Status,
InitialAmount: payment.Amount,
Expand Down
Loading

0 comments on commit 4fd415b

Please sign in to comment.