8000 fix(atlar): fix payout creation and polling statuses by paul-nicolas · Pull Request #305 · formancehq/payments · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(atlar): fix payout creation and polling statuses #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2025
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
6 changes: 3 additions & 3 deletions internal/connectors/engine/workflow/create_payout.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ func (w Workflow) createPayout(
Every: config.PollingPeriod,
},
Action: client.ScheduleWorkflowAction{
Workflow: RunPollTransfer,
Workflow: RunPollPayout,
Args: []interface{}{
PollTransfer{
PollPayout{
TaskID: createPayout.TaskID,
ConnectorID: createPayout.ConnectorID,
PaymentInitia 8000 tionID: createPayout.PaymentInitiationID,
TransferID: *createPayoutResponse.PollingPayoutID,
PayoutID: *createPayoutResponse.PollingPayoutID,
ScheduleID: scheduleID,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (s *UnitTestSuite) Test_CreatePayout_WithPollingPayment_Success() {
})
s.env.OnActivity(activities.TemporalScheduleCreateActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, options activities.ScheduleCreateOptions) error {
s.Contains(options.ScheduleID, "polling-payout")
s.Equal(RunPollTransfer, options.Action.Workflow)
s.Equal(RunPollPayout, options.Action.Workflow)
return nil
})

Expand Down
4 changes: 2 additions & 2 deletions internal/connectors/plugins/public/atlar/client/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (c *client) GetV1AccountsID(ctx context.Context, id string) (*accounts.GetV
}

resp, err := c.client.Accounts.GetV1AccountsID(&accountsParams)
return resp, wrapSDKErr(err)
return resp, wrapSDKErr(err, &accounts.GetV1AccountsIDNotFound{})
}

func (c *client) GetV1Accounts(ctx context.Context, token string, pageSize int64) (*accounts.GetV1AccountsOK, error) {
Expand All @@ -27,5 +27,5 @@ func (c *client) GetV1Accounts(ctx context.Context, token string, pageSize int64
}

resp, err := c.client.Accounts.GetV1Accounts(&accountsParams)
return resp, wrapSDKErr(err)
return resp, wrapSDKErr(err, nil)
}
36 changes: 29 additions & 7 deletions internal/connectors/plugins/public/atlar/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -66,25 +67,46 @@ func createAtlarClient(baseURL *url.URL, accessKey, secret string) *atlar_client
return client
}

type ErrorCodeReader interface {
Code() int
}

// wrap a public error for cases that we don't want to retry
// so that activities can classify this error for temporal
func wrapSDKErr(err error) error {
func wrapSDKErr(err error, atlarErr any) error {
if err == nil {
return nil
}

atlarErr, ok := err.(*runtime.APIError)
if !ok {
return err
var code int
switch {
case atlarErr == nil:
var atlarError *runtime.APIError
if !errors.As(err, &atlarError) {
return err
}
code = atlarError.Code

default:
if !errors.As(err, &atlarErr) {
return err
}

reader, ok := atlarErr.(ErrorCodeReader)
if !ok {
return err
}

code = reader.Code()
}

if atlarErr.Code == http.StatusTooManyRequests {
if code == http.StatusTooManyRequests {
return fmt.Errorf("atlar error: %w: %w", err, httpwrapper.ErrStatusCodeTooManyRequests)
}

if atlarErr.Code >= http.StatusBadRequest && atlarErr.Code < http.StatusInternalServerError {
if code >= http.StatusBadRequest && code < http.StatusInternalServerError {
return fmt.Errorf("atlar error: %w: %w", err, httpwrapper.ErrStatusCodeClientError)
} else if atlarErr.Code >= http.StatusInternalServerError {
} else if code >= http.StatusInternalServerError {
return fmt.Errorf("atlar error: %w: %w", err, httpwrapper.ErrStatusCodeServerError)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (c *client) GetV1CounterpartiesID(ctx context.Context, counterPartyID strin
HTTPClient: c.httpClient,
}
counterpartyResponse, err := c.client.Counterparties.GetV1CounterpartiesID(&getCounterpartyParams)
return counterpartyResponse, wrapSDKErr(err)
return counterpartyResponse, wrapSDKErr(err, &counterparties.GetV1CounterpartiesIDNotFound{})
}

func (c *client) PostV1CounterParties(ctx context.Context, newExternalBankAccount models.BankAccount) (*counterparties.PostV1CounterpartiesCreated, error) {
Expand Down Expand Up @@ -61,7 +61,7 @@ func (c *client) PostV1CounterParties(ctx context.Context, newExternalBankAccoun
}
postCounterpartiesResponse, err := c.client.Counterparties.PostV1Counterparties(&postCounterpartiesParams)
if err != nil {
return nil, wrapSDKErr(err)
return nil, wrapSDKErr(err, &counterparties.PostV1CounterpartiesBadRequest{})
}

if len(postCounterpartiesResponse.Payload.ExternalAccounts) != 1 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (c *client) GetV1ExternalAccountsID(ctx context.Context, externalAccountID
}

externalAccountResponse, err := c.client.ExternalAccounts.GetV1ExternalAccountsID(&getExternalAccountParams)
return externalAccountResponse, wrapSDKErr(err)
return externalAccountResponse, wrapSDKErr(err, &external_accounts.GetV1ExternalAccountsIDNotFound{})
}

func (c *client) GetV1ExternalAccounts(ctx context.Context, token string, pageSize int64) (*external_accounts.GetV1ExternalAccountsOK, error) {
Expand All @@ -27,5 +27,5 @@ func (c *client) GetV1ExternalAccounts(ctx context.Context, token string, pageSi
}

resp, err := c.client.ExternalAccounts.GetV1ExternalAccounts(&externalAccountsParams)
return resp, wrapSDKErr(err)
return resp, wrapSDKErr(err, nil)
}
2E87
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ func (c *client) GetV1BetaThirdPartiesID(ctx context.Context, id string) (*third
}

resp, err := c.client.ThirdParties.GetV1betaThirdPartiesID(&params)
return resp, wrapSDKErr(err)
return resp, wrapSDKErr(err, &third_parties.GetV1betaThirdPartiesIDNotFound{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (c *client) GetV1Transactions(ctx context.Context, token string, pageSize i
}

resp, err := c.client.Transactions.GetV1Transactions(&params)
return resp, wrapSDKErr(err)
return resp, wrapSDKErr(err, nil)
}

func (c *client) GetV1TransactionsID(ctx context.Context, id string) (*transactions.GetV1TransactionsIDOK, error) {
Expand All @@ -27,5 +27,5 @@ func (c *client) GetV1TransactionsID(ctx context.Context, id string) (*transacti
}

resp, err := c.client.Transactions.GetV1TransactionsID(&params)
return resp, wrapSDKErr(err)
return resp, wrapSDKErr(err, &transactions.GetV1TransactionsIDNotFound{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (c *client) PostV1CreditTransfers(ctx context.Context, req *atlar_models.Cr
}

resp, err := c.client.CreditTransfers.PostV1CreditTransfers(&postCreditTransfersParams)
return resp, wrapSDKErr(err)
return resp, wrapSDKErr(err, &credit_transfers.PostV1CreditTransfersBadRequest{})
}

func (c *client) GetV1CreditTransfersGetByExternalIDExternalID(ctx context.Context, externalID string) (*credit_transfers.GetV1CreditTransfersGetByExternalIDExternalIDOK, error) {
Expand All @@ -27,5 +27,5 @@ func (c *client) GetV1CreditTransfersGetByExternalIDExternalID(ctx context.Conte
}

resp, err := c.client.CreditTransfers.GetV1CreditTransfersGetByExternalIDExternalID(&getCreditTransferParams)
return resp, wrapSDKErr(err)
return resp, wrapSDKErr(err, &credit_transfers.GetV1CreditTransfersGetByExternalIDExternalIDNotFound{})
}
0