-
Notifications
You must be signed in to change notification settings - Fork 7
feat(psu): add payment service user entity #424
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3188568
chore(storage): remove errors.Wrap deprecated
paul-nicolas c479ec4
feat: add psu models
paul-nicolas cfae58c
feat(storage): add psu migrations and functions
paul-nicolas 1813004
feat(*): add payment service users entity
paul-nicolas be356b0
feat(tests): update sdks and add psu integration tests
paul-nicolas 5619a73
fix go lint tests
paul-nicolas f2bbef1
fixes after coderabbit review
paul-nicolas a935476
fix typos
paul-nicolas 57534cd
fix tests
paul-nicolas 1d06919
feat(validation): add validation on email and phone number
paul-nicolas b756de3
use classic one to many postgres relationship
paul-nicolas 4ba031d
remove duplicate test
paul-nicolas 8dfd4a7
remove default when adding the psu id column
paul-nicolas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
11 changes: 11 additions & 0 deletions
11
internal/api/services/payment_service_users_add_bank_account.go
This file contains hidden or 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,11 @@ | ||
package services | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/google/uuid" | ||
) | ||
|
||
func (s *Service) PaymentServiceUsersAddBankAccount(ctx context.Context, psuID uuid.UUID, bankAccountID uuid.UUID) error { | ||
return newStorageError(s.storage.PaymentServiceUsersAddBankAccount(ctx, psuID, bankAccountID), "failed to add bank account to payment service user") | ||
} |
59 changes: 59 additions & 0 deletions
59
internal/api/services/payment_service_users_add_bank_account_test.go
This file contains hidden or 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,59 @@ | ||
package services | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/formancehq/payments/internal/connectors/engine" | ||
"github.com/formancehq/payments/internal/storage" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/require" | ||
gomock "go.uber.org/mock/gomock" | ||
) | ||
|
||
func TestPaymentServiceUsersAddBankAccount(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
store := storage.NewMockStorage(ctrl) | ||
eng := engine.NewMockEngine(ctrl) | ||
|
||
s := New(store, eng, false) | ||
|
||
tests := []struct { | ||
name string | ||
err error | ||
expectedError error | ||
}{ | ||
{ | ||
name: "success", | ||
err: nil, | ||
expectedError: nil, | ||
}, | ||
{ | ||
name: "storage error not found", | ||
err: storage.ErrNotFound, | ||
expectedError: newStorageError(storage.ErrNotFound, "failed to add bank account to payment service user"), | ||
}, | ||
{ | ||
name: "other error", | ||
err: fmt.Errorf("error"), | ||
expectedError: newStorageError(fmt.Errorf("error"), "failed to add bank account to payment service user"), | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
psuID, baID := uuid.New(), uuid.New() | ||
store.EXPECT().PaymentServiceUsersAddBankAccount(gomock.Any(), psuID, baID).Return(test.err) | ||
err := s.PaymentServiceUsersAddBankAccount(context.Background(), psuID, baID) | ||
if test.expectedError == nil { | ||
require.NoError(t, err) | ||
} else { | ||
require.Equal(t, test.expectedError, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains hidden or 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,11 @@ | ||
package services | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/formancehq/payments/internal/models" | ||
) | ||
|
||
func (s *Service) PaymentServiceUsersCreate(ctx context.Context, psu models.PaymentServiceUser) error { | ||
return newStorageError(s.storage.PaymentServiceUsersCreate(ctx, psu), "cannot create payment service user") | ||
} |
58 changes: 58 additions & 0 deletions
58
internal/api/services/payment_service_users_create_test.go
This file contains hidden or 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,58 @@ | ||
package services | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/formancehq/payments/internal/connectors/engine" | ||
"github.com/formancehq/payments/internal/models" | ||
"github.com/formancehq/payments/internal/storage" | ||
"github.com/stretchr/testify/require" | ||
gomock "go.uber.org/mock/gomock" | ||
) | ||
|
||
func TestPSUCreate(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
store := storage.NewMockStorage(ctrl) | ||
eng := engine.NewMockEngine(ctrl) | ||
|
||
s := New(store, eng, false) | ||
|
||
tests := []struct { | ||
name string | ||
err error | ||
expectedError error | ||
}{ | ||
{ | ||
name: "success", | ||
err: nil, | ||
expectedError: nil, | ||
}, | ||
{ | ||
name: "storage error not found", | ||
err: storage.ErrNotFound, | ||
expectedError: newStorageError(storage.ErrNotFound, "cannot create payment service user"), | ||
}, | ||
{ | ||
name: "other error", | ||
err: fmt.Errorf("error"), | ||
expectedError: newStorageError(fmt.Errorf("error"), "cannot create payment service user"), | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
store.EXPECT().PaymentServiceUsersCreate(gomock.Any(), models.PaymentServiceUser{}).Return(test.err) | ||
err := s.PaymentServiceUsersCreate(context.Background(), models.PaymentServiceUser{}) | ||
if test.expectedError == nil { | ||
require.NoError(t, err) | ||
} else { | ||
require.Equal(t, test.expectedError, err) | ||
} | ||
}) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
internal/api/services/payment_service_users_forward_bank_account.go
This file contains hidden or 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,35 @@ | ||
package services | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/formancehq/payments/internal/models" | ||
"github.com/formancehq/payments/internal/storage" | ||
"github.com/google/uuid" | ||
) | ||
|
||
func (s *Service) PaymentServiceUsersForwardBankAccountToConnector(ctx context.Context, psuID, bankAccountID uuid.UUID, connectorID models.ConnectorID) (models.Task, error) { | ||
ba, err := s.storage.BankAccountsGet(ctx, bankAccountID, true) | ||
if err != nil { | ||
return models.Task{}, newStorageError(err, "failed to get bank account") | ||
} | ||
|
||
if ba == nil { | ||
// Should not happen, but just in case | ||
return models.Task{}, newStorageError(storage.ErrNotFound, "bank account not found") | ||
} | ||
|
||
psu, err := s.storage.PaymentServiceUsersGet(ctx, psuID) | ||
if err != nil { | ||
return models.Task{}, newStorageError(err, "failed to get payment service user") | ||
} | ||
|
||
models.FillBankAccountMetadataWithPaymentServiceUserInfo(ba, psu) | ||
|
||
task, err := s.engine.ForwardBankAccount(ctx, *ba, connectorID, false) | ||
if err != nil { | ||
return models.Task{}, handleEngineErrors(err) | ||
} | ||
|
||
return task, nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.