mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
84 lines
2.1 KiB
Go
84 lines
2.1 KiB
Go
package v2
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/formancehq/go-libs/v3/api"
|
|
"github.com/formancehq/payments/internal/api/backend"
|
|
"github.com/formancehq/payments/internal/api/common"
|
|
"github.com/formancehq/payments/internal/otel"
|
|
"github.com/google/uuid"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
)
|
|
|
|
func bankAccountsGet(backend backend.Backend) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
ctx, span := otel.Tracer().Start(r.Context(), "v2_bankAccountsGet")
|
|
defer span.End()
|
|
|
|
span.SetAttributes(attribute.String("bankAccountID", bankAccountID(r)))
|
|
id, err := uuid.Parse(bankAccountID(r))
|
|
if err != nil {
|
|
otel.RecordError(span, err)
|
|
api.BadRequest(w, ErrInvalidID, err)
|
|
return
|
|
}
|
|
|
|
bankAccount, err := backend.BankAccountsGet(ctx, id)
|
|
if err != nil {
|
|
otel.RecordError(span, err)
|
|
handleServiceErrors(w, r, err)
|
|
return
|
|
}
|
|
|
|
if err := bankAccount.Obfuscate(); err != nil {
|
|
otel.RecordError(span, err)
|
|
common.InternalServerError(w, r, err)
|
|
return
|
|
}
|
|
|
|
data := &BankAccountResponse{
|
|
ID: bankAccount.ID.String(),
|
|
Name: bankAccount.Name,
|
|
CreatedAt: bankAccount.CreatedAt,
|
|
Metadata: bankAccount.Metadata,
|
|
}
|
|
|
|
if bankAccount.IBAN != nil {
|
|
data.Iban = *bankAccount.IBAN
|
|
}
|
|
|
|
if bankAccount.AccountNumber != nil {
|
|
data.AccountNumber = *bankAccount.AccountNumber
|
|
}
|
|
|
|
if bankAccount.SwiftBicCode != nil {
|
|
data.SwiftBicCode = *bankAccount.SwiftBicCode
|
|
}
|
|
|
|
if bankAccount.Country != nil {
|
|
data.Country = *bankAccount.Country
|
|
}
|
|
|
|
for _, relatedAccount := range bankAccount.RelatedAccounts {
|
|
data.RelatedAccounts = append(data.RelatedAccounts, &bankAccountRelatedAccountsResponse{
|
|
ID: "",
|
|
CreatedAt: relatedAccount.CreatedAt,
|
|
AccountID: relatedAccount.AccountID.String(),
|
|
ConnectorID: relatedAccount.AccountID.ConnectorID.String(),
|
|
Provider: toV2Provider(relatedAccount.AccountID.ConnectorID.Provider),
|
|
})
|
|
}
|
|
|
|
err = json.NewEncoder(w).Encode(api.BaseResponse[BankAccountResponse]{
|
|
Data: data,
|
|
})
|
|
if err != nil {
|
|
otel.RecordError(span, err)
|
|
common.InternalServerError(w, r, err)
|
|
return
|
|
}
|
|
}
|
|
}
|