-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29571f9
commit 52e5e0e
Showing
144 changed files
with
6,866 additions
and
1,161 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package transferinitiation | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
fctl "github.com/formancehq/fctl/pkg" | ||
"github.com/formancehq/formance-sdk-go/pkg/models/shared" | ||
"github.com/pkg/errors" | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type TransferInitiationCreateStore struct { | ||
TransferInitiationId string `json:"transferInitiationId"` | ||
} | ||
type TransferInitiationCreateController struct { | ||
store *TransferInitiationCreateStore | ||
} | ||
|
||
var _ fctl.Controller[*TransferInitiationCreateStore] = (*TransferInitiationCreateController)(nil) | ||
|
||
func NewDefaultTransferInitiationCreateStore() *TransferInitiationCreateStore { | ||
return &TransferInitiationCreateStore{} | ||
} | ||
|
||
func NewTransferInitiationCreateController() *TransferInitiationCreateController { | ||
return &TransferInitiationCreateController{ | ||
store: NewDefaultTransferInitiationCreateStore(), | ||
} | ||
} | ||
|
||
func NewCreateCommand() *cobra.Command { | ||
return fctl.NewCommand("create <file>|-", | ||
fctl.WithShortDescription("Create a transfer initiation"), | ||
fctl.WithAliases("cr", "c"), | ||
fctl.WithArgs(cobra.ExactArgs(1)), | ||
fctl.WithController[*TransferInitiationCreateStore](NewTransferInitiationCreateController()), | ||
) | ||
} | ||
|
||
func (c *TransferInitiationCreateController) GetStore() *TransferInitiationCreateStore { | ||
return c.store | ||
} | ||
|
||
func (c *TransferInitiationCreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { | ||
|
||
soc, err := fctl.GetStackOrganizationConfig(cmd) | ||
if err != nil { | ||
return nil, err | ||
} | ||
client, err := fctl.NewStackClient(cmd, soc.Config, soc.Stack) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "creating stack client") | ||
} | ||
|
||
script, err := fctl.ReadFile(cmd, soc.Stack, args[0]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
request := shared.TransferInitiationRequest{} | ||
if err := json.Unmarshal([]byte(script), &request); err != nil { | ||
return nil, err | ||
} | ||
|
||
//nolint:gosimple | ||
response, err := client.Payments.CreateTransferInitiation(cmd.Context(), request) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if response.StatusCode >= 300 { | ||
return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) | ||
} | ||
|
||
c.store.TransferInitiationId = response.TransferInitiationResponse.Data.ID | ||
|
||
return c, nil | ||
} | ||
|
||
func (c *TransferInitiationCreateController) Render(cmd *cobra.Command, args []string) error { | ||
pterm.Success.WithWriter(cmd.OutOrStdout()).Printfln("Transfer Initiation created with ID: %s", c.store.TransferInitiationId) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package transferinitiation | ||
|
||
import ( | ||
"fmt" | ||
|
||
fctl "github.com/formancehq/fctl/pkg" | ||
"github.com/formancehq/formance-sdk-go/pkg/models/operations" | ||
"github.com/pkg/errors" | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type TransferInitiationDeleteStore struct { | ||
TransferID string `json:"transferId"` | ||
Success bool `json:"success"` | ||
} | ||
|
||
type TransferInitiationDeleteController struct { | ||
store *TransferInitiationDeleteStore | ||
} | ||
|
||
var _ fctl.Controller[*TransferInitiationDeleteStore] = (*TransferInitiationDeleteController)(nil) | ||
|
||
func NewDefaultTransferInitiationDeleteStore() *TransferInitiationDeleteStore { | ||
return &TransferInitiationDeleteStore{} | ||
} | ||
|
||
func NewTransferInitiationDeleteController() *TransferInitiationDeleteController { | ||
return &TransferInitiationDeleteController{ | ||
store: NewDefaultTransferInitiationDeleteStore(), | ||
} | ||
} | ||
func NewDeleteCommand() *cobra.Command { | ||
return fctl.NewCommand("delete <transferID>", | ||
fctl.WithAliases("del", "d"), | ||
fctl.WithShortDescription("Delete a transfer Initiation"), | ||
fctl.WithArgs(cobra.ExactArgs(1)), | ||
fctl.WithController[*TransferInitiationDeleteStore](NewTransferInitiationDeleteController()), | ||
) | ||
} | ||
|
||
func (c *TransferInitiationDeleteController) GetStore() *TransferInitiationDeleteStore { | ||
return c.store | ||
} | ||
|
||
func (c *TransferInitiationDeleteController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { | ||
cfg, err := fctl.GetConfig(cmd) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "retrieving config") | ||
} | ||
|
||
organizationID, err := fctl.ResolveOrganizationID(cmd, cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
stack, err := fctl.ResolveStack(cmd, cfg, organizationID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
client, err := fctl.NewStackClient(cmd, cfg, stack) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "creating stack client") | ||
} | ||
|
||
response, err := client.Payments.DeleteTransferInitiation( | ||
cmd.Context(), | ||
operations.DeleteTransferInitiationRequest{ | ||
TransferID: args[0], | ||
}, | ||
) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if response.StatusCode >= 300 { | ||
return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) | ||
} | ||
|
||
c.store.TransferID = args[0] | ||
c.store.Success = true | ||
|
||
return c, nil | ||
} | ||
|
||
func (c *TransferInitiationDeleteController) Render(cmd *cobra.Command, args []string) error { | ||
pterm.Success.WithShowLineNumber().Printfln("Transfer Initiation %s Deleted!", c.store.TransferID) | ||
return nil | ||
} |
112 changes: 112 additions & 0 deletions
112
components/fctl/cmd/payments/transferinitiation/list.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package transferinitiation | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
fctl "github.com/formancehq/fctl/pkg" | ||
"github.com/formancehq/formance-sdk-go/pkg/models/operations" | ||
"github.com/formancehq/formance-sdk-go/pkg/models/shared" | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type TransferInitiationListStore struct { | ||
Cursor *shared.TransferInitiationsCursorCursor `json:"cursor"` | ||
} | ||
|
||
type TransferInitiationListController struct { | ||
store *TransferInitiationListStore | ||
} | ||
|
||
var _ fctl.Controller[*TransferInitiationListStore] = (*TransferInitiationListController)(nil) | ||
|
||
func NewDefaultTransferInitiationListStore() *TransferInitiationListStore { | ||
return &TransferInitiationListStore{ | ||
Cursor: &shared.TransferInitiationsCursorCursor{}, | ||
} | ||
} | ||
|
||
func NewTransferInitiationListController() *TransferInitiationListController { | ||
return &TransferInitiationListController{ | ||
store: NewDefaultTransferInitiationListStore(), | ||
} | ||
} | ||
|
||
func (c *TransferInitiationListController) GetStore() *TransferInitiationListStore { | ||
return c.store | ||
} | ||
|
||
func (c *TransferInitiationListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { | ||
|
||
cfg, err := fctl.GetConfig(cmd) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
organizationID, err := fctl.ResolveOrganizationID(cmd, cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
stack, err := fctl.ResolveStack(cmd, cfg, organizationID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
client, err := fctl.NewStackClient(cmd, cfg, stack) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
response, err := client.Payments.ListTransferInitiations( | ||
cmd.Context(), | ||
operations.ListTransferInitiationsRequest{}, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if response.StatusCode >= 300 { | ||
return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) | ||
} | ||
|
||
c.store.Cursor = &response.TransferInitiationsCursor.Cursor | ||
|
||
return c, nil | ||
} | ||
|
||
func (c *TransferInitiationListController) Render(cmd *cobra.Command, args []string) error { | ||
tableData := fctl.Map(c.store.Cursor.Data, func(tf shared.TransferInitiation) []string { | ||
return []string{ | ||
tf.ID, | ||
tf.CreatedAt.Format(time.RFC3339), | ||
tf.UpdatedAt.Format(time.RFC3339), | ||
tf.Description, | ||
tf.SourceAccountID, | ||
tf.DestinationAccountID, | ||
string(tf.Provider), | ||
string(tf.Type), | ||
fmt.Sprint(tf.Amount), | ||
tf.Asset, | ||
string(tf.Status), | ||
tf.Error, | ||
} | ||
}) | ||
tableData = fctl.Prepend(tableData, []string{"ID", "CreatedAt", "UpdatedAt", "Description", "Source Account ID", | ||
"Destination Account ID", "Provider", "Type", "Amount", "Asset", "Status", "Error"}) | ||
return pterm.DefaultTable. | ||
WithHasHeader(). | ||
WithWriter(cmd.OutOrStdout()). | ||
WithData(tableData). | ||
Render() | ||
} | ||
|
||
func NewListTransferInitiationCommand() *cobra.Command { | ||
return fctl.NewCommand("list_transfer_initiations", | ||
fctl.WithAliases("ls"), | ||
fctl.WithArgs(cobra.ExactArgs(0)), | ||
fctl.WithShortDescription("List transfer initiation"), | ||
fctl.WithController[*TransferInitiationListStore](NewTransferInitiationListController()), | ||
) | ||
} |
Oops, something went wrong.