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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package client

const (
bankingCircleMetadataSpecNamespace = "com.bankingCircle.spec/"

BankingCircleChargeBearerMetadataKey = bankingCircleMetadataSpecNamespace + "chargeBearer"
BankingCircleClearingNetworkMetadataKey = bankingCircleMetadataSpecNamespace + "clearingNetwork"
)
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions internal/connectors/plugins/public/bankingcircle/payouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading