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
6 changes: 6 additions & 0 deletions internal/connectors/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,9 @@ func (e *engine) CreatePaymentServiceUserLink(ctx context.Context, applicationNa
openBankingForwardedUser, err := e.storage.OpenBankingForwardedUserGet(ctx, psuID, connectorID)
if err != nil {
otel.RecordError(span, err)
if errors.Is(err, storage.ErrNotFound) {
return "", "", fmt.Errorf("payment service user has not been forwarded to connector '%s'. Please forward the payment service user to the connector before creating a link: %w", connectorID, ErrValidation)
}
return "", "", err
}

Expand Down Expand Up @@ -1089,6 +1092,9 @@ func (e *engine) UpdatePaymentServiceUserLink(ctx context.Context, applicationNa
openBankingForwardedUser, err := e.storage.OpenBankingForwardedUserGet(ctx, psuID, connectorID)
if err != nil {
otel.RecordError(span, err)
if errors.Is(err, storage.ErrNotFound) {
return "", "", fmt.Errorf("payment service user has not been forwarded to connector '%s'. Please forward the payment service user to the connector before updating a link: %w", connectorID, ErrValidation)
}
return "", "", err
}

Expand Down
6 changes: 4 additions & 2 deletions internal/connectors/engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,8 @@ var _ = Describe("Engine Tests", func() {
store.EXPECT().OpenBankingForwardedUserGet(gomock.Any(), psuID, connectorID).Return(nil, storage.ErrNotFound)
_, _, err := eng.CreatePaymentServiceUserLink(ctx, "Test", psuID, connectorID, idempotencyKey, clientRedirectURL)
Expect(err).NotTo(BeNil())
Expect(err).To(MatchError(storage.ErrNotFound))
Expect(err).To(MatchError(ContainSubstring("payment service user has not been forwarded to connector")))
Expect(err).To(MatchError(ContainSubstring("Please forward the payment service user to the connector before creating a link")))
})

It("should return error when connection attempt upsert fails", func(ctx SpecContext) {
Expand Down Expand Up @@ -1045,7 +1046,8 @@ var _ = Describe("Engine Tests", func() {
store.EXPECT().OpenBankingForwardedUserGet(gomock.Any(), psuID, connectorID).Return(nil, storage.ErrNotFound)
_, _, err := eng.UpdatePaymentServiceUserLink(ctx, "Test", psuID, connectorID, connectionID, idempotencyKey, clientRedirectURL)
Expect(err).NotTo(BeNil())
Expect(err).To(MatchError(storage.ErrNotFound))
Expect(err).To(MatchError(ContainSubstring("payment service user has not been forwarded to connector")))
Expect(err).To(MatchError(ContainSubstring("Please forward the payment service user to the connector before updating a link")))
})

It("should return error when connection not found", func(ctx SpecContext) {
Expand Down
37 changes: 37 additions & 0 deletions test/e2e/api_open_banking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,43 @@ var _ = Context("Payments API Open Banking", Serial, func() {
})
})

When("creating a link without forwarding PSU", func() {
var (
connectorID string
)

BeforeEach(func() {
var err error

id := uuid.New()
conf := newV3ConnectorConfigFn()(id)
conf.LinkFlowError = pointer.For(false)
conf.UpdateLinkFlowError = pointer.For(false)
connectorID, err = installV3Connector(ctx, app.GetValue(), conf, id)
Expect(err).To(BeNil())
})

AfterEach(func() {
uninstallConnector(ctx, app.GetValue(), connectorID)
})

It("should fail with clear error message when PSU has not been forwarded", func() {
applicationName := "test"
_, err := app.GetValue().SDK().Payments.V3.CreateLinkForPaymentServiceUser(
ctx,
psuID,
connectorID,
&components.V3PaymentServiceUserCreateLinkRequest{
ApplicationName: &applicationName,
ClientRedirectURL: "https://www.google.com",
},
)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("payment service user has not been forwarded to connector"))
Expect(err.Error()).To(ContainSubstring("Please forward the payment service user to the connector before creating a link"))
})
})

When("creating a link and call it - success", func() {
var (
connectorID string
Expand Down
Loading