Skip to content
Draft
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
2 changes: 2 additions & 0 deletions internal/connectors/plugins/public/generic/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ var capabilities = []models.Capability{
models.CAPABILITY_FETCH_EXTERNAL_ACCOUNTS,
models.CAPABILITY_FETCH_PAYMENTS,

models.CAPABILITY_CREATE_PAYOUT,

models.CAPABILITY_ALLOW_FORMANCE_ACCOUNT_CREATION,
models.CAPABILITY_ALLOW_FORMANCE_PAYMENT_CREATION,
}
2 changes: 2 additions & 0 deletions internal/connectors/plugins/public/generic/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type Client interface {
GetBalances(ctx context.Context, accountID string) (*genericclient.Balances, error)
ListBeneficiaries(ctx context.Context, page, pageSize int64, createdAtFrom time.Time) ([]genericclient.Beneficiary, error)
ListTransactions(ctx context.Context, page, pageSize int64, updatedAtFrom time.Time) ([]genericclient.Transaction, error)
CreatePayout(ctx context.Context, request *PayoutRequest) (*PayoutResponse, error)
GetPayoutStatus(ctx context.Context, payoutId string) (*PayoutResponse, error)
}

type apiTransport struct {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,34 @@ paths:
default:
$ref: '#/components/responses/ErrorResponse'

/payouts:
post:
summary: Create payout
operationId: createPayout
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/PayoutRequest'
responses:
201:
$ref: '#/components/responses/PayoutResponse'
default:
$ref: '#/components/responses/ErrorResponse'

/payouts/{payoutId}:
get:
summary: Get payout status
operationId: getPayoutStatus
parameters:
- $ref: '#/components/parameters/PayoutId'
responses:
200:
$ref: '#/components/responses/PayoutResponse'
default:
$ref: '#/components/responses/ErrorResponse'

# ---------------------- COMPONENTS ----------------------
components:
# ---------------------- PARAMETERS ----------------------
Expand All @@ -72,6 +100,12 @@ components:
required: true
schema:
type: string
PayoutId:
name: payoutId
in: path
required: true
schema:
type: string
PageSize:
name: pageSize
in: query
Expand Down Expand Up @@ -160,6 +194,13 @@ components:
items:
$ref: '#/components/schemas/Transaction'

PayoutResponse:
description: Payout response
content:
application/json:
schema:
$ref: '#/components/schemas/Payout'

# ---------------------- SCHEMAS ----------------------
schemas:
Error:
Expand Down Expand Up @@ -295,4 +336,78 @@ components:
enum:
- PENDING
- SUCCEEDED
- FAILED
- FAILED

PayoutRequest:
type: object
required:
- idempotencyKey
- amount
- currency
- sourceAccountId
- destinationAccountId
properties:
idempotencyKey:
type: string
description: Unique identifier for the payout request
amount:
type: string
description: Payout amount
currency:
type: string
description: Currency code (ISO 4217)
sourceAccountId:
type: string
description: Source account identifier
destinationAccountId:
type: string
description: Destination account identifier
description:
type: string
description: Payout description
metadata:
$ref: '#/components/schemas/Metadata'

Payout:
type: object
required:
- id
- idempotencyKey
- amount
- currency
- sourceAccountId
- destinationAccountId
- status
- createdAt
properties:
id:
type: string
description: Payout identifier
idempotencyKey:
type: string
description: Unique identifier for the payout request
amount:
type: string
description: Payout amount
currency:
type: string
description: Currency code (ISO 4217)
sourceAccountId:
type: string
description: Source account identifier
destinationAccountId:
type: string
description: Destination account identifier
description:
type: string
description: Payout description
status:
$ref: '#/components/schemas/TransactionStatus'
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
metadata:
$ref: '#/components/schemas/Metadata'
71 changes: 71 additions & 0 deletions internal/connectors/plugins/public/generic/client/payouts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package client

import (
"context"

"github.com/formancehq/payments/internal/connectors/metrics"
)

type PayoutRequest struct {
IdempotencyKey string `json:"idempotencyKey"`
Amount string `json:"amount"`
Currency string `json:"currency"`
SourceAccountId string `json:"sourceAccountId"`
DestinationAccountId string `json:"destinationAccountId"`
Description *string `json:"description,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}

type PayoutResponse struct {
Id string `json:"id"`
IdempotencyKey string `json:"idempotencyKey"`
Amount string `json:"amount"`
Currency string `json:"currency"`
SourceAccountId string `json:"sourceAccountId"`
DestinationAccountId string `json:"destinationAccountId"`
Description *string `json:"description,omitempty"`
Status string `json:"status"`
CreatedAt string `json:"createdAt"`
UpdatedAt *string `json:"updatedAt,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}

func (c *client) CreatePayout(ctx context.Context, request *PayoutRequest) (*PayoutResponse, error) {
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "create_payout")

// TODO: Once the OpenAPI client is regenerated, replace this with actual API calls
// For now, return a mock response to satisfy the interface
return &PayoutResponse{
Id: "payout_" + request.IdempotencyKey,
IdempotencyKey: request.IdempotencyKey,
Amount: request.Amount, // Pass through the amount as-is
Currency: request.Currency,
SourceAccountId: request.SourceAccountId,
DestinationAccountId: request.DestinationAccountId,
Description: request.Description,
Status: "PENDING",
CreatedAt: "2024-01-01T00:00:00Z",
UpdatedAt: nil,
Metadata: request.Metadata,
}, nil
}

func (c *client) GetPayoutStatus(ctx context.Context, payoutId string) (*PayoutResponse, error) {
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "get_payout_status")

// TODO: Once the OpenAPI client is regenerated, replace this with actual API calls
// For now, return a mock response to satisfy the interface
return &PayoutResponse{
Id: payoutId,
IdempotencyKey: payoutId + "_key",
Amount: "1000",
Currency: "USD",
SourceAccountId: "source_account",
DestinationAccountId: "dest_account",
Description: nil,
Status: "SUCCEEDED",
CreatedAt: "2024-01-01T00:00:00Z",
UpdatedAt: nil,
Metadata: make(map[string]string),
}, nil
}
Loading
Loading