Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 77 additions & 13 deletions cmd/payments/connectors/configs/getconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (
)

type PaymentsLoadConfigStore struct {
ConnectorConfig *shared.ConnectorConfigResponse `json:"connectorConfig"`
Provider string `json:"provider"`
ConnectorID string `json:"connectorId"`
ConnectorConfig *shared.ConnectorConfigResponse `json:"connectorConfig"`
V3ConnectorConfig *shared.V3GetConnectorConfigResponse `json:"v3ConnectorConfig,omitempty"`
Provider string `json:"provider"`
ConnectorID string `json:"connectorId"`
}

type PaymentsLoadConfigController struct {
Expand Down Expand Up @@ -53,10 +54,10 @@ func NewPaymentsLoadConfigController() *PaymentsLoadConfigController {
func NewLoadConfigCommand() *cobra.Command {
c := NewPaymentsLoadConfigController()
return fctl.NewCommand("get-config",
fctl.WithAliases("LoadConfig", "getconf", "gc", "get", "g"),
fctl.WithAliases("getconfig", "getconf", "gc", "get", "g"),
fctl.WithArgs(cobra.ExactArgs(0)),
fctl.WithValidArgsFunction(cobra.NoFileCompletions),
fctl.WithStringFlag("provider", "", "Provider name"),
fctl.WithStringFlag("provider", "", "Provider name (only used for v0, v1 or v2)"),
fctl.WithStringFlag("connector-id", "", "Connector ID"),
fctl.WithShortDescription(fmt.Sprintf("Read a connector config (Connectors available: %v)", internal.AllConnectors)),
fctl.WithController[*PaymentsLoadConfigStore](c),
Expand All @@ -68,7 +69,6 @@ func (c *PaymentsLoadConfigController) GetStore() *PaymentsLoadConfigStore {
}

func (c *PaymentsLoadConfigController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) {

_, profile, profileName, relyingParty, err := fctl.LoadAndAuthenticateCurrentProfile(cmd)
if err != nil {
return nil, err
Expand All @@ -87,6 +87,29 @@ func (c *PaymentsLoadConfigController) Run(cmd *cobra.Command, args []string) (f
connectorID := fctl.GetString(cmd, c.connectorIDFlag)

switch c.PaymentsVersion {
case versions.V3:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original getConfig allows to specify only the provider, then to request the user to select the connector if there is multiple. I forced the use of connectorId for this case.

if connectorID == "" {
return nil, fmt.Errorf("connector-id is required for v3")
}

response, err := stackClient.Payments.V3.GetConnectorConfig(cmd.Context(), operations.V3GetConnectorConfigRequest{
ConnectorID: connectorID,
})
if err != nil {
return nil, err
}
if response.StatusCode >= 300 {
return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode)
}

if response.V3GetConnectorConfigResponse == nil {
return nil, fmt.Errorf("unexpected response: %v", response)
}

c.store.V3ConnectorConfig = response.V3GetConnectorConfigResponse
c.store.ConnectorID = connectorID
c.store.Provider = strings.ToLower(string(response.V3GetConnectorConfigResponse.Data.Type))

case versions.V0:
if provider == "" {
return nil, fmt.Errorf("provider is required")
Expand Down Expand Up @@ -170,8 +193,53 @@ func (c *PaymentsLoadConfigController) Run(cmd *cobra.Command, args []string) (f

// TODO: This need to use the ui.NewListModel
func (c *PaymentsLoadConfigController) Render(cmd *cobra.Command, args []string) error {
if c.PaymentsVersion == versions.V3 {
return c.renderV3(cmd, args)
}
return c.renderV1V2(cmd, args)
}

func (c *PaymentsLoadConfigController) renderV3(cmd *cobra.Command, args []string) error {
var err error
switch c.store.Provider {
provider := c.store.Provider
switch provider {
case internal.StripeConnector:
err = views.DisplayStripeConfigV3(cmd, c.store.V3ConnectorConfig)
case internal.ModulrConnector:
err = views.DisplayModulrConfigV3(cmd, c.store.V3ConnectorConfig)
case internal.BankingCircleConnector:
err = views.DisplayBankingCircleConfigV3(cmd, c.store.V3ConnectorConfig)
case internal.CurrencyCloudConnector:
err = views.DisplayCurrencyCloudConfigV3(cmd, c.store.V3ConnectorConfig)
case internal.WiseConnector:
err = views.DisplayWiseConfigV3(cmd, c.store.V3ConnectorConfig)
case internal.MangoPayConnector:
err = views.DisplayMangopayConfigV3(cmd, c.store.V3ConnectorConfig)
case internal.MoneycorpConnector:
err = views.DisplayMoneycorpConfigV3(cmd, c.store.V3ConnectorConfig)
case internal.AtlarConnector:
err = views.DisplayAtlarConfigV3(cmd, c.store.V3ConnectorConfig)
case internal.AdyenConnector:
err = views.DisplayAdyenConfigV3(cmd, c.store.V3ConnectorConfig)
case internal.QontoConnector:
err = views.DisplayQontoConfigV3(cmd, c.store.V3ConnectorConfig)
case internal.ColumnConnector:
err = views.DisplayColumnConfigV3(cmd, c.store.V3ConnectorConfig)
default:
err = fmt.Errorf("unknown provider: %s", provider)
pterm.Error.WithWriter(cmd.OutOrStderr()).Printfln("%s", err.Error())
}

return err
}

func (c *PaymentsLoadConfigController) renderV1V2(cmd *cobra.Command, args []string) error {
if c.store.ConnectorConfig == nil {
return fmt.Errorf("no connector config available")
}
var err error
provider := c.store.Provider
switch provider {
case internal.StripeConnector:
err = views.DisplayStripeConfig(cmd, c.store.ConnectorConfig)
case internal.ModulrConnector:
Expand All @@ -190,14 +258,10 @@ func (c *PaymentsLoadConfigController) Render(cmd *cobra.Command, args []string)
err = views.DisplayAtlarConfig(cmd, c.store.ConnectorConfig)
case internal.AdyenConnector:
err = views.DisplayAdyenConfig(cmd, c.store.ConnectorConfig)
case internal.QontoConnector:
err = views.DisplayQontoConfig(cmd, c.store.ConnectorConfig)
case internal.ColumnConnector:
err = views.DisplayColumnConfig(cmd, c.store.ConnectorConfig)
default:
pterm.Error.WithWriter(cmd.OutOrStderr()).Printfln("Connection unknown.")
err = fmt.Errorf("unknown provider: %s", provider)
pterm.Error.WithWriter(cmd.OutOrStderr()).Printfln("%s", err.Error())
}

return err

}
38 changes: 25 additions & 13 deletions cmd/payments/connectors/views/adyen.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"github.com/spf13/cobra"

"github.com/formancehq/formance-sdk-go/v3/pkg/models/shared"

fctl "github.com/formancehq/fctl/pkg"
)

func DisplayAdyenConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error {
Expand All @@ -14,19 +16,29 @@ func DisplayAdyenConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorCon
tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name})
tableData = append(tableData, []string{pterm.LightCyan("ApiKey:"), config.APIKey})
tableData = append(tableData, []string{pterm.LightCyan("HMACKey:"), config.HmacKey})
tableData = append(tableData, []string{pterm.LightCyan("LiveEndpointPrefix:"), func() string {
if config.LiveEndpointPrefix == nil {
return ""
}

return *config.LiveEndpointPrefix
}()})
tableData = append(tableData, []string{pterm.LightCyan("Polling Period:"), func() string {
if config.PollingPeriod == nil {
return ""
}
return *config.PollingPeriod
}()})
tableData = append(tableData, []string{pterm.LightCyan("LiveEndpointPrefix:"), fctl.StringPointerToString(config.LiveEndpointPrefix)})
tableData = append(tableData, []string{pterm.LightCyan("Polling Period:"), fctl.StringPointerToString(config.PollingPeriod)})

if err := pterm.DefaultTable.
WithWriter(cmd.OutOrStdout()).
WithData(tableData).
Render(); err != nil {
return err
}
return nil
}

func DisplayAdyenConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error {
config := v3Config.Data.V3AdyenConfig

tableData := pterm.TableData{}
tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name})
tableData = append(tableData, []string{pterm.LightCyan("ApiKey:"), config.APIKey})
tableData = append(tableData, []string{pterm.LightCyan("CompanyID:"), config.CompanyID})
tableData = append(tableData, []string{pterm.LightCyan("LiveEndpointPrefix:"), fctl.StringPointerToString(config.LiveEndpointPrefix)})
tableData = append(tableData, []string{pterm.LightCyan("Polling Period:"), fctl.StringPointerToString(config.PollingPeriod)})
tableData = append(tableData, []string{pterm.LightCyan("WebhookPassword:"), fctl.StringPointerToString(config.WebhookPassword)})
tableData = append(tableData, []string{pterm.LightCyan("WebhookUsername:"), fctl.StringPointerToString(config.WebhookUsername)})

if err := pterm.DefaultTable.
WithWriter(cmd.OutOrStdout()).
Expand Down
42 changes: 24 additions & 18 deletions cmd/payments/connectors/views/atlar.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/spf13/cobra"

"github.com/formancehq/formance-sdk-go/v3/pkg/models/shared"

fctl "github.com/formancehq/fctl/pkg"
)

func DisplayAtlarConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error {
Expand All @@ -16,30 +18,34 @@ func DisplayAtlarConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorCon
tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name})
tableData = append(tableData, []string{pterm.LightCyan("AccessKey:"), config.AccessKey})
tableData = append(tableData, []string{pterm.LightCyan("Secret:"), config.Secret})
tableData = append(tableData, []string{pterm.LightCyan("BaseUrl:"), func() string {
if config.BaseURL == nil {
return ""
}
return *config.BaseURL
}()})
tableData = append(tableData, []string{pterm.LightCyan("BaseUrl:"), fctl.StringPointerToString(config.BaseURL)})
tableData = append(tableData, []string{pterm.LightCyan("PageSize:"), func() string {
if config.PageSize == nil {
return ""
}
return fmt.Sprintf("%d", *config.PageSize)
}()})
tableData = append(tableData, []string{pterm.LightCyan("Polling Period:"), func() string {
if config.PollingPeriod == nil {
return ""
}
return *config.PollingPeriod
}()})
tableData = append(tableData, []string{pterm.LightCyan("Transfer Initiation Status Polling Period:"), func() string {
if config.TransferInitiationStatusPollingPeriod == nil {
return ""
}
return *config.TransferInitiationStatusPollingPeriod
}()})
tableData = append(tableData, []string{pterm.LightCyan("Polling Period:"), fctl.StringPointerToString(config.PollingPeriod)})
tableData = append(tableData, []string{pterm.LightCyan("Transfer Initiation Status Polling Period:"), fctl.StringPointerToString(config.TransferInitiationStatusPollingPeriod)})

if err := pterm.DefaultTable.
WithWriter(cmd.OutOrStdout()).
WithData(tableData).
Render(); err != nil {
return err
}
return nil
}

func DisplayAtlarConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error {
config := v3Config.Data.V3AtlarConfig

tableData := pterm.TableData{}
tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name})
tableData = append(tableData, []string{pterm.LightCyan("AccessKey:"), config.AccessKey})
tableData = append(tableData, []string{pterm.LightCyan("BaseUrl:"), config.BaseURL})
tableData = append(tableData, []string{pterm.LightCyan("Polling Period:"), fctl.StringPointerToString(config.PollingPeriod)})
tableData = append(tableData, []string{pterm.LightCyan("Secret:"), config.Secret})

if err := pterm.DefaultTable.
WithWriter(cmd.OutOrStdout()).
Expand Down
32 changes: 26 additions & 6 deletions cmd/payments/connectors/views/banking_circle.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"github.com/spf13/cobra"

"github.com/formancehq/formance-sdk-go/v3/pkg/models/shared"

fctl "github.com/formancehq/fctl/pkg"
)

func DisplayBankingCircleConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error {
Expand All @@ -16,12 +18,30 @@ func DisplayBankingCircleConfig(cmd *cobra.Command, connectorConfig *shared.Conn
tableData = append(tableData, []string{pterm.LightCyan("Password:"), config.Password})
tableData = append(tableData, []string{pterm.LightCyan("Endpoint:"), config.Endpoint})
tableData = append(tableData, []string{pterm.LightCyan("Authorization endpoint:"), config.AuthorizationEndpoint})
tableData = append(tableData, []string{pterm.LightCyan("Polling Period:"), func() string {
if config.PollingPeriod == nil {
return ""
}
return *config.PollingPeriod
}()})
tableData = append(tableData, []string{pterm.LightCyan("UserCertificate:"), config.UserCertificate})
tableData = append(tableData, []string{pterm.LightCyan("UserCertificateKey:"), config.UserCertificateKey})

if err := pterm.DefaultTable.
WithWriter(cmd.OutOrStdout()).
WithData(tableData).
Render(); err != nil {
return err
}
return nil
}

func DisplayBankingCircleConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error {
config := v3Config.Data.V3BankingcircleConfig

tableData := pterm.TableData{}
tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name})
tableData = append(tableData, []string{pterm.LightCyan("Username:"), config.Username})
tableData = append(tableData, []string{pterm.LightCyan("Password:"), config.Password})
tableData = append(tableData, []string{pterm.LightCyan("Endpoint:"), config.Endpoint})
tableData = append(tableData, []string{pterm.LightCyan("Authorization endpoint:"), config.AuthorizationEndpoint})
tableData = append(tableData, []string{pterm.LightCyan("Polling Period:"), fctl.StringPointerToString(config.PollingPeriod)})
tableData = append(tableData, []string{pterm.LightCyan("UserCertificate:"), config.UserCertificate})
tableData = append(tableData, []string{pterm.LightCyan("UserCertificateKey:"), config.UserCertificateKey})

if err := pterm.DefaultTable.
WithWriter(cmd.OutOrStdout()).
Expand Down
24 changes: 17 additions & 7 deletions cmd/payments/connectors/views/column.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
package views

import (
"encoding/json"

"github.com/pterm/pterm"
"github.com/spf13/cobra"

"github.com/formancehq/formance-sdk-go/v3/pkg/models/shared"

fctl "github.com/formancehq/fctl/pkg"
)

func DisplayColumnConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error {
// Display raw JSON since SDK might not have ColumnConfig type yet
jsonData, err := json.MarshalIndent(connectorConfig.Data, "", " ")
if err != nil {
// Column is a connector implemented in v3, so not compatible with the v1 call.

func DisplayColumnConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error {
config := v3Config.Data.V3ColumnConfig

tableData := pterm.TableData{}
tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name})
tableData = append(tableData, []string{pterm.LightCyan("APIKey:"), config.APIKey})
tableData = append(tableData, []string{pterm.LightCyan("Endpoint:"), config.Endpoint})
tableData = append(tableData, []string{pterm.LightCyan("Polling Period:"), fctl.StringPointerToString(config.PollingPeriod)})

if err := pterm.DefaultTable.
WithWriter(cmd.OutOrStdout()).
WithData(tableData).
Render(); err != nil {
return err
}
pterm.DefaultBox.WithWriter(cmd.OutOrStdout()).WithTitle("Column Configuration").Println(string(jsonData))
return nil
}
28 changes: 22 additions & 6 deletions cmd/payments/connectors/views/currency_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"github.com/spf13/cobra"

"github.com/formancehq/formance-sdk-go/v3/pkg/models/shared"

fctl "github.com/formancehq/fctl/pkg"
)

func DisplayCurrencyCloudConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error {
Expand All @@ -14,12 +16,7 @@ func DisplayCurrencyCloudConfig(cmd *cobra.Command, connectorConfig *shared.Conn
tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name})
tableData = append(tableData, []string{pterm.LightCyan("API key:"), config.APIKey})
tableData = append(tableData, []string{pterm.LightCyan("Login ID:"), config.LoginID})
tableData = append(tableData, []string{pterm.LightCyan("Endpoint:"), func() string {
if config.Endpoint == nil {
return ""
}
return *config.Endpoint
}()})
tableData = append(tableData, []string{pterm.LightCyan("Endpoint:"), fctl.StringPointerToString(config.Endpoint)})
tableData = append(tableData, []string{pterm.LightCyan("Polling Period:"), func() string {
if config.PollingPeriod == nil {
return ""
Expand All @@ -35,3 +32,22 @@ func DisplayCurrencyCloudConfig(cmd *cobra.Command, connectorConfig *shared.Conn
}
return nil
}

func DisplayCurrencyCloudConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error {
config := v3Config.Data.V3CurrencycloudConfig

tableData := pterm.TableData{}
tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name})
tableData = append(tableData, []string{pterm.LightCyan("API key:"), config.APIKey})
tableData = append(tableData, []string{pterm.LightCyan("Login ID:"), config.LoginID})
tableData = append(tableData, []string{pterm.LightCyan("Endpoint:"), config.Endpoint})
tableData = append(tableData, []string{pterm.LightCyan("Polling Period:"), fctl.StringPointerToString(config.PollingPeriod)})

if err := pterm.DefaultTable.
WithWriter(cmd.OutOrStdout()).
WithData(tableData).
Render(); err != nil {
return err
}
return nil
}
Loading
Loading