Skip to content

Commit

Permalink
fix orchestration
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-nicolas committed Sep 25, 2023
1 parent 8ad2098 commit edf60cb
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,30 @@ import (
"context"
"fmt"
"net/http"
"time"

"github.com/formancehq/formance-sdk-go/pkg/models/shared"
"go.temporal.io/sdk/activity"
"go.temporal.io/sdk/workflow"
)

func (a Activities) StripeTransfer(ctx context.Context, request shared.StripeTransferRequest) error {
func (a Activities) StripeTransfer(ctx context.Context, request shared.ActivityStripeTransfer) error {
activityInfo := activity.GetInfo(ctx)
ti := shared.TransferInitiationRequest{
Amount: request.Amount,
Asset: *request.Asset,
CreatedAt: time.Now(),
DestinationAccountID: *request.Destination,
Provider: shared.ConnectorStripe,
Type: shared.TransferInitiationRequestTypeTransfer,
UniqueRequestID: activityInfo.WorkflowExecution.ID + activityInfo.ActivityID,
Validated: true, // No need to validate
}

response, err := a.client.Payments.
ConnectorsStripeTransfer(
CreateTransferInitiation(
ctx,
request,
ti,
)
if err != nil {
return err
Expand All @@ -29,6 +43,6 @@ func (a Activities) StripeTransfer(ctx context.Context, request shared.StripeTra

var StripeTransferActivity = Activities{}.StripeTransfer

func StripeTransfer(ctx workflow.Context, request shared.StripeTransferRequest) error {
func StripeTransfer(ctx workflow.Context, request shared.ActivityStripeTransfer) error {
return executeActivity(ctx, StripeTransferActivity, nil, request)
}
4 changes: 2 additions & 2 deletions components/orchestration/internal/workflow/stages/send/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func runWalletToPayment(ctx workflow.Context, source *WalletSource, destination
return err
}

if err := activities.StripeTransfer(internal.InfiniteRetryContext(ctx), shared.StripeTransferRequest{
if err := activities.StripeTransfer(internal.InfiniteRetryContext(ctx), shared.ActivityStripeTransfer{
Amount: amount.Amount,
Asset: &amount.Asset,
Destination: &stripeConnectID,
Expand Down Expand Up @@ -360,7 +360,7 @@ func runAccountToPayment(ctx workflow.Context, source *LedgerAccountSource, dest
return err
}

if err := activities.StripeTransfer(internal.InfiniteRetryContext(ctx), shared.StripeTransferRequest{
if err := activities.StripeTransfer(internal.InfiniteRetryContext(ctx), shared.ActivityStripeTransfer{
Amount: amount.Amount,
Asset: &amount.Asset,
Destination: &stripeConnectID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ var (
{
Activity: activities.StripeTransferActivity,
Args: []any{
mock.Anything, shared.StripeTransferRequest{
mock.Anything, shared.ActivityStripeTransfer{
Amount: big.NewInt(100),
Asset: pointer.For("USD"),
Destination: pointer.For("abcd"),
Expand Down Expand Up @@ -1025,7 +1025,7 @@ var (
{
Activity: activities.StripeTransferActivity,
Args: []any{
mock.Anything, shared.StripeTransferRequest{
mock.Anything, shared.ActivityStripeTransfer{
Amount: big.NewInt(100),
Asset: pointer.For("USD"),
Destination: pointer.For("abcd"),
Expand Down
23 changes: 22 additions & 1 deletion components/orchestration/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ paths:
$ref: '#/components/responses/ErrorResponse'
204:
description: No content

/workflows/{workflowID}/instances:
parameters:
- in: path
Expand Down Expand Up @@ -614,6 +614,27 @@ components:
- $ref: '#/components/schemas/StageSend'
- $ref: '#/components/schemas/StageDelay'
- $ref: '#/components/schemas/StageWaitEvent'
StripeTransferRequest:
type: object
properties:
amount:
type: integer
format: bigint
minimum: 0
example: 100
asset:
type: string
example: USD
destination:
type: string
example: acct_1Gqj58KZcSIg2N2q
metadata:
type: object
description: |
A set of key/value pairs that you can attach to a transfer object.
It can be useful for storing additional information about the transfer in a structured format.
example:
order_id: '6735'
ActivityStripeTransfer:
$ref: '#/components/schemas/StripeTransferRequest'
ActivityGetAccount:
Expand Down
57 changes: 5 additions & 52 deletions components/payments/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -305,18 +305,6 @@ paths:
responses:
'200':
$ref: '#/components/responses/Transfers'
/connectors/stripe/transfers:
post:
summary: Transfer funds between Stripe accounts
tags:
- Payments
operationId: connectorsStripeTransfer
description: Execute a transfer between two Stripe accounts.
requestBody:
$ref: '#/components/requestBodies/StripeTransfer'
responses:
'200':
$ref: '#/components/responses/StripeTransfer'

# ---------------------- COMPONENTS ----------------------
components:
Expand Down Expand Up @@ -478,12 +466,6 @@ components:
application/json:
schema:
$ref: '#/components/schemas/TaskResponse'
StripeTransfer:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/StripeTransferResponse'
Transfer:
description: OK
content:
Expand All @@ -504,12 +486,6 @@ components:
application/json:
schema:
$ref: '#/components/schemas/ConnectorConfig'
StripeTransfer:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/StripeTransferRequest'
UpdateMetadata:
required: true
content:
Expand Down Expand Up @@ -838,7 +814,7 @@ components:
type: string
example: '60s'
description: |
The frequency at which the connector will try to fetch new BalanceTransaction objects from Stripe API.
The frequency at which the connector will try to fetch new BalanceTransaction objects from Wise API.
default: '120s'
ModulrConfig:
type: object
Expand All @@ -859,7 +835,7 @@ components:
type: string
example: '60s'
description: |
The frequency at which the connector will try to fetch new BalanceTransaction objects from Stripe API.
The frequency at which the connector will try to fetch new BalanceTransaction objects from Modulr API.
default: '120s'
BankingCircleConfig:
type: object
Expand Down Expand Up @@ -893,7 +869,7 @@ components:
type: string
example: '60s'
description: |
The frequency at which the connector will try to fetch new BalanceTransaction objects from Stripe API.
The frequency at which the connector will try to fetch new BalanceTransaction objects from Banking Circle API.
default: '120s'
MangoPayConfig:
type: object
Expand All @@ -906,7 +882,7 @@ components:
type: string
example: '60s'
description: |
The frequency at which the connector will try to fetch new BalanceTransaction objects from Stripe API.
The frequency at which the connector will try to fetch new BalanceTransaction objects from MangoPay API.
default: '120s'
clientID:
type: string
Expand Down Expand Up @@ -937,7 +913,7 @@ components:
type: string
example: '60s'
description: |
The frequency at which the connector will try to fetch new BalanceTransaction objects from Stripe API.
The frequency at which the connector will try to fetch new BalanceTransaction objects from MoneyCorp API.
default: '120s'
CurrencyCloudConfig:
type: object
Expand Down Expand Up @@ -1416,29 +1392,6 @@ components:
- FAILED
- REJECTED
- VALIDATED
StripeTransferRequest:
type: object
properties:
amount:
type: integer
format: bigint
minimum: 0
example: 100
asset:
type: string
example: USD
destination:
type: string
example: acct_1Gqj58KZcSIg2N2q
metadata:
type: object
description: |
A set of key/value pairs that you can attach to a transfer object.
It can be useful for storing additional information about the transfer in a structured format.
example:
order_id: '6735'
StripeTransferResponse:
type: object
PaymentStatus:
type: string
enum:
Expand Down
Loading

0 comments on commit edf60cb

Please sign in to comment.