diff --git a/cmd/payments/connectors/configs/getconfig.go b/cmd/payments/connectors/configs/getconfig.go index 0909b7da..2ad1ae82 100644 --- a/cmd/payments/connectors/configs/getconfig.go +++ b/cmd/payments/connectors/configs/getconfig.go @@ -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 { @@ -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), @@ -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 @@ -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: + 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") @@ -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: @@ -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 - } diff --git a/cmd/payments/connectors/views/adyen.go b/cmd/payments/connectors/views/adyen.go index e062e6a1..34aec0c0 100644 --- a/cmd/payments/connectors/views/adyen.go +++ b/cmd/payments/connectors/views/adyen.go @@ -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 { @@ -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()). diff --git a/cmd/payments/connectors/views/atlar.go b/cmd/payments/connectors/views/atlar.go index 6fcf0838..0318db3c 100644 --- a/cmd/payments/connectors/views/atlar.go +++ b/cmd/payments/connectors/views/atlar.go @@ -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 { @@ -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()). diff --git a/cmd/payments/connectors/views/banking_circle.go b/cmd/payments/connectors/views/banking_circle.go index 5bb0f371..a67b984a 100644 --- a/cmd/payments/connectors/views/banking_circle.go +++ b/cmd/payments/connectors/views/banking_circle.go @@ -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 { @@ -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()). diff --git a/cmd/payments/connectors/views/column.go b/cmd/payments/connectors/views/column.go index 574cec68..1d7859b3 100644 --- a/cmd/payments/connectors/views/column.go +++ b/cmd/payments/connectors/views/column.go @@ -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 } diff --git a/cmd/payments/connectors/views/currency_cloud.go b/cmd/payments/connectors/views/currency_cloud.go index d0dded1f..8f0c9677 100644 --- a/cmd/payments/connectors/views/currency_cloud.go +++ b/cmd/payments/connectors/views/currency_cloud.go @@ -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 { @@ -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 "" @@ -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 +} diff --git a/cmd/payments/connectors/views/mangopay.go b/cmd/payments/connectors/views/mangopay.go index b6898978..efba7a10 100644 --- a/cmd/payments/connectors/views/mangopay.go +++ b/cmd/payments/connectors/views/mangopay.go @@ -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 DisplayMangopayConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error { @@ -30,3 +32,22 @@ func DisplayMangopayConfig(cmd *cobra.Command, connectorConfig *shared.Connector } return nil } + +func DisplayMangopayConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { + config := v3Config.Data.V3MangopayConfig + + tableData := pterm.TableData{} + tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) + tableData = append(tableData, []string{pterm.LightCyan("ClientID:"), config.ClientID}) + tableData = append(tableData, []string{pterm.LightCyan("API key:"), 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 + } + return nil +} diff --git a/cmd/payments/connectors/views/modulr.go b/cmd/payments/connectors/views/modulr.go index 00626a01..e7474475 100644 --- a/cmd/payments/connectors/views/modulr.go +++ b/cmd/payments/connectors/views/modulr.go @@ -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 DisplayModulrConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error { @@ -35,3 +37,22 @@ func DisplayModulrConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorCo } return nil } + +func DisplayModulrConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { + config := v3Config.Data.V3ModulrConfig + + 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("API secret:"), config.APISecret}) + 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 +} diff --git a/cmd/payments/connectors/views/moneycorp.go b/cmd/payments/connectors/views/moneycorp.go index df828a05..0a923528 100644 --- a/cmd/payments/connectors/views/moneycorp.go +++ b/cmd/payments/connectors/views/moneycorp.go @@ -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 DisplayMoneycorpConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error { @@ -30,3 +32,22 @@ func DisplayMoneycorpConfig(cmd *cobra.Command, connectorConfig *shared.Connecto } return nil } + +func DisplayMoneycorpConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { + config := v3Config.Data.V3MoneycorpConfig + + tableData := pterm.TableData{} + tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) + tableData = append(tableData, []string{pterm.LightCyan("ClientID:"), config.ClientID}) + tableData = append(tableData, []string{pterm.LightCyan("API key:"), 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 + } + return nil +} diff --git a/cmd/payments/connectors/views/qonto.go b/cmd/payments/connectors/views/qonto.go index 353069c9..93866354 100644 --- a/cmd/payments/connectors/views/qonto.go +++ b/cmd/payments/connectors/views/qonto.go @@ -1,20 +1,31 @@ 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 DisplayQontoConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error { - // Display raw JSON since SDK might not have QontoConfig type yet - jsonData, err := json.MarshalIndent(connectorConfig.Data, "", " ") - if err != nil { +// Qonto is a connector implemented in v3, so not compatible with the v1 call. + +func DisplayQontoConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { + config := v3Config.Data.V3QontoConfig + + 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("Client ID:"), config.ClientID}) + tableData = append(tableData, []string{pterm.LightCyan("Polling Period:"), fctl.StringPointerToString(config.PollingPeriod)}) + tableData = append(tableData, []string{pterm.LightCyan("Staging token:"), fctl.StringPointerToString(config.StagingToken)}) + + if err := pterm.DefaultTable. + WithWriter(cmd.OutOrStdout()). + WithData(tableData). + Render(); err != nil { return err } - pterm.DefaultBox.WithWriter(cmd.OutOrStdout()).WithTitle("Qonto Configuration").Println(string(jsonData)) return nil } diff --git a/cmd/payments/connectors/views/stripe.go b/cmd/payments/connectors/views/stripe.go index 87fc77d4..83e0528f 100644 --- a/cmd/payments/connectors/views/stripe.go +++ b/cmd/payments/connectors/views/stripe.go @@ -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 DisplayStripeConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error { @@ -28,3 +30,20 @@ func DisplayStripeConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorCo } return nil } + +func DisplayStripeConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { + config := v3Config.Data.V3StripeConfig + + 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("Polling Period:"), fctl.StringPointerToString(config.PollingPeriod)}) + + if err := pterm.DefaultTable. + WithWriter(cmd.OutOrStdout()). + WithData(tableData). + Render(); err != nil { + return err + } + return nil +} diff --git a/cmd/payments/connectors/views/wise.go b/cmd/payments/connectors/views/wise.go index 4b777390..e3c1f675 100644 --- a/cmd/payments/connectors/views/wise.go +++ b/cmd/payments/connectors/views/wise.go @@ -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 DisplayWiseConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error { @@ -28,3 +30,20 @@ func DisplayWiseConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConf } return nil } + +func DisplayWiseConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { + config := v3Config.Data.V3WiseConfig + + 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("Polling Period:"), fctl.StringPointerToString(config.PollingPeriod)}) + + if err := pterm.DefaultTable. + WithWriter(cmd.OutOrStdout()). + WithData(tableData). + Render(); err != nil { + return err + } + return nil +}