diff --git a/internal/connectors/plugins/public/bankingcircle/client/metadata.go b/internal/connectors/plugins/public/bankingcircle/client/metadata.go new file mode 100644 index 000000000..3cbc26f62 --- /dev/null +++ b/internal/connectors/plugins/public/bankingcircle/client/metadata.go @@ -0,0 +1,8 @@ +package client + +const ( + bankingCircleMetadataSpecNamespace = "com.bankingCircle.spec/" + + BankingCircleChargeBearerMetadataKey = bankingCircleMetadataSpecNamespace + "chargeBearer" + BankingCircleClearingNetworkMetadataKey = bankingCircleMetadataSpecNamespace + "clearingNetwork" +) diff --git a/internal/connectors/plugins/public/bankingcircle/client/transfer_payouts.go b/internal/connectors/plugins/public/bankingcircle/client/transfer_payouts.go index 22bb15a15..d2fdc35ed 100644 --- a/internal/connectors/plugins/public/bankingcircle/client/transfer_payouts.go +++ b/internal/connectors/plugins/public/bankingcircle/client/transfer_payouts.go @@ -28,6 +28,7 @@ type PaymentRequest struct { ChargeBearer string `json:"chargeBearer"` CreditorAccount *PaymentAccount `json:"creditorAccount"` CreditorName string `json:"creditorName"` + ClearingNetwork string `json:"clearingNetwork,omitempty"` } type PaymentResponse struct { diff --git a/internal/connectors/plugins/public/bankingcircle/payouts.go b/internal/connectors/plugins/public/bankingcircle/payouts.go index 52c582828..044761466 100644 --- a/internal/connectors/plugins/public/bankingcircle/payouts.go +++ b/internal/connectors/plugins/public/bankingcircle/payouts.go @@ -85,6 +85,12 @@ func (p *Plugin) createPayout(ctx context.Context, pi models.PSPPaymentInitiatio account = pi.DestinationAccount.Metadata[models.AccountIBANMetadataKey] } + chargeBearer := models.ExtractNamespacedMetadata(pi.Metadata, client.BankingCircleChargeBearerMetadataKey) + if chargeBearer == "" { + chargeBearer = "SHA" + } + clearingNetwork := models.ExtractNamespacedMetadata(pi.Metadata, client.BankingCircleClearingNetworkMetadataKey) + resp, err := p.client.InitiateTransferOrPayouts(ctx, &client.PaymentRequest{ IdempotencyKey: pi.Reference, RequestedExecutionDate: pi.CreatedAt, @@ -99,13 +105,14 @@ func (p *Plugin) createPayout(ctx context.Context, pi models.PSPPaymentInitiatio Currency: curr, Amount: json.Number(amount), }, - ChargeBearer: "SHA", + ChargeBearer: chargeBearer, CreditorAccount: &client.PaymentAccount{ Account: account, FinancialInstitution: pi.DestinationAccount.Metadata[models.AccountSwiftBicCodeMetadataKey], Country: pi.DestinationAccount.Metadata[models.AccountBankAccountCountryMetadataKey], }, - CreditorName: *pi.DestinationAccount.Name, + CreditorName: *pi.DestinationAccount.Name, + ClearingNetwork: clearingNetwork, }) if err != nil { return nil, err diff --git a/internal/connectors/plugins/public/bankingcircle/payouts_test.go b/internal/connectors/plugins/public/bankingcircle/payouts_test.go index 0797a4a8a..5a690ae4e 100644 --- a/internal/connectors/plugins/public/bankingcircle/payouts_test.go +++ b/internal/connectors/plugins/public/bankingcircle/payouts_test.go @@ -229,6 +229,78 @@ var _ = Describe("BankingCircle Plugin Payouts Creation", func() { Expect(resp).To(Equal(models.CreatePayoutResponse{})) }) + It("should forward metadata", func(ctx SpecContext) { + copyPI := samplePSPPaymentInitiation + copyPI.Metadata = map[string]string{ + client.BankingCircleChargeBearerMetadataKey: "OUR", + client.BankingCircleClearingNetworkMetadataKey: "SEPAINST", + } + req := models.CreatePayoutRequest{ + PaymentInitiation: copyPI, + } + + pr := client.PaymentResponse{ + PaymentID: "p1", + } + m.EXPECT().GetAccount(gomock.Any(), samplePSPPaymentInitiation.SourceAccount.Reference). + Return(&client.Account{ + AccountIdentifiers: []client.AccountIdentifier{{ + Account: "123456789", + FinancialInstitution: "test", + Country: "US", + }}, + }, nil) + + m.EXPECT().InitiateTransferOrPayouts(gomock.Any(), &client.PaymentRequest{ + IdempotencyKey: samplePSPPaymentInitiation.Reference, + RequestedExecutionDate: samplePSPPaymentInitiation.CreatedAt, + DebtorAccount: client.PaymentAccount{ + Account: "123456789", + FinancialInstitution: "test", + Country: "US", + }, + DebtorReference: samplePSPPaymentInitiation.Description, + CurrencyOfTransfer: "EUR", + Amount: client.Amount{ + Currency: "EUR", + Amount: "1.00", + }, + ChargeBearer: "OUR", + CreditorAccount: &client.PaymentAccount{ + Account: "acc", + FinancialInstitution: "bic", + Country: "US", + }, + CreditorName: "acc2", + ClearingNetwork: "SEPAINST", + }).Return(&pr, nil) + + paymentResponse := client.Payment{ + PaymentID: "p1", + TransactionReference: "transaction-p1", + Status: "Processed", + Classification: "Outgoing", + ProcessedTimestamp: now.UTC(), + LatestStatusChangedTimestamp: now.UTC(), + DebtorInformation: client.DebtorInformation{ + AccountID: "123", + }, + Transfer: client.Transfer{ + Amount: client.Amount{ + Currency: "EUR", + Amount: "1.00", + }, + }, + CreditorInformation: client.CreditorInformation{ + AccountID: "321", + }, + } + m.EXPECT().GetPayment(gomock.Any(), "p1").Return(&paymentResponse, nil) + + _, err := plg.CreatePayout(ctx, req) + Expect(err).To(BeNil()) + }) + It("should be ok", func(ctx SpecContext) { req := models.CreatePayoutRequest{ PaymentInitiation: samplePSPPaymentInitiation,