-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
feat(payments): Atlar connector: Add more bank details to Accounts (internal) and Payments #1607
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/formancehq/payments/cmd/connectors/internal/connectors" | ||
"github.com/get-momo/atlar-v1-go-client/client/third_parties" | ||
) | ||
|
||
func (c *Client) GetV1BetaThirdPartiesID(ctx context.Context, id string) (*third_parties.GetV1betaThirdPartiesIDOK, error) { | ||
f := connectors.ClientMetrics(ctx, "atlar", "list_third_parties") | ||
now := time.Now() | ||
defer f(ctx, now) | ||
|
||
params := third_parties.GetV1betaThirdPartiesIDParams{ | ||
Context: ctx, | ||
ID: id, | ||
} | ||
|
||
return c.client.ThirdParties.GetV1betaThirdPartiesID(¶ms) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ func FetchTransactionsTask(config Config, client *client.Client) task.Task { | |
|
||
token = pagedTransactions.Payload.NextToken | ||
|
||
if err := ingestPaymentsBatch(ctx, connectorID, ingester, pagedTransactions); err != nil { | ||
if err := ingestPaymentsBatch(ctx, connectorID, taskID, ingester, client, pagedTransactions); err != nil { | ||
otel.RecordError(span, err) | ||
return err | ||
} | ||
|
@@ -66,13 +66,15 @@ func FetchTransactionsTask(config Config, client *client.Client) task.Task { | |
func ingestPaymentsBatch( | ||
ctx context.Context, | ||
connectorID models.ConnectorID, | ||
taskID models.TaskID, | ||
ingester ingestion.Ingester, | ||
client *client.Client, | ||
pagedTransactions *transactions.GetV1TransactionsOK, | ||
) error { | ||
batch := ingestion.PaymentBatch{} | ||
|
||
for _, item := range pagedTransactions.Payload.Items { | ||
batchElement, err := atlarTransactionToPaymentBatchElement(connectorID, item) | ||
batchElement, err := atlarTransactionToPaymentBatchElement(ctx, connectorID, taskID, item, client) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -91,9 +93,20 @@ func ingestPaymentsBatch( | |
} | ||
|
||
func atlarTransactionToPaymentBatchElement( | ||
ctx context.Context, | ||
connectorID models.ConnectorID, | ||
taskID models.TaskID, | ||
transaction *atlar_models.Transaction, | ||
client *client.Client, | ||
) (*ingestion.PaymentBatchElement, error) { | ||
ctx, span := connectors.StartSpan( | ||
ctx, | ||
"atlar.atlarTransactionToPaymentBatchElement", | ||
attribute.String("connectorID", connectorID.String()), | ||
attribute.String("taskID", taskID.String()), | ||
) | ||
defer span.End() | ||
Comment on lines
+102
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hope creating instead of passing a span is the correct thing to do here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep it's good, it's gonna be linked to the parent span thanks to the StartSpan function, so LGTM |
||
|
||
if _, ok := supportedCurrenciesWithDecimal[*transaction.Amount.Currency]; !ok { | ||
// Discard transactions with unsupported currencies | ||
return nil, nil | ||
|
@@ -117,6 +130,22 @@ func atlarTransactionToPaymentBatchElement( | |
return nil, err | ||
} | ||
|
||
requestCtx, cancel := contextutil.DetachedWithTimeout(ctx, 30*time.Second) | ||
defer cancel() | ||
accountResponse, err := client.GetV1AccountsID(requestCtx, *transaction.Account.ID) | ||
if err != nil { | ||
otel.RecordError(span, err) | ||
return nil, err | ||
} | ||
|
||
requestCtx, cancel = contextutil.DetachedWithTimeout(ctx, 30*time.Second) | ||
defer cancel() | ||
thirdPartyResponse, err := client.GetV1BetaThirdPartiesID(requestCtx, *&accountResponse.Payload.ThirdPartyID) | ||
if err != nil { | ||
otel.RecordError(span, err) | ||
return nil, err | ||
} | ||
|
||
paymentId := models.PaymentID{ | ||
PaymentReference: models.PaymentReference{ | ||
Reference: transaction.ID, | ||
|
@@ -137,7 +166,7 @@ func atlarTransactionToPaymentBatchElement( | |
Amount: amount, | ||
InitialAmount: amount, | ||
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, *transaction.Amount.Currency), | ||
Metadata: ExtractPaymentMetadata(paymentId, transaction), | ||
Metadata: ExtractPaymentMetadata(paymentId, transaction, accountResponse.Payload, thirdPartyResponse.Payload), | ||
RawData: raw, | ||
}, | ||
} | ||
|
@@ -197,7 +226,7 @@ func determinePaymentScheme(item *atlar_models.Transaction) models.PaymentScheme | |
return models.PaymentSchemeSepa | ||
} | ||
|
||
func ExtractPaymentMetadata(paymentId models.PaymentID, transaction *atlar_models.Transaction) []*models.PaymentMetadata { | ||
func ExtractPaymentMetadata(paymentId models.PaymentID, transaction *atlar_models.Transaction, account *atlar_models.Account, bank *atlar_models.ThirdParty) []*models.PaymentMetadata { | ||
result := []*models.PaymentMetadata{} | ||
if transaction.Date != "" { | ||
result = append(result, ComputePaymentMetadata(paymentId, "date", transaction.Date)) | ||
|
@@ -207,6 +236,9 @@ func ExtractPaymentMetadata(paymentId models.PaymentID, transaction *atlar_model | |
} | ||
result = append(result, ComputePaymentMetadata(paymentId, "remittanceInformation/type", *transaction.RemittanceInformation.Type)) | ||
result = append(result, ComputePaymentMetadata(paymentId, "remittanceInformation/value", *transaction.RemittanceInformation.Value)) | ||
result = append(result, ComputePaymentMetadata(paymentId, "bank/id", bank.ID)) | ||
result = append(result, ComputePaymentMetadata(paymentId, "bank/name", bank.Name)) | ||
result = append(result, ComputePaymentMetadata(paymentId, "bank/bic", account.Bank.Bic)) | ||
result = append(result, ComputePaymentMetadata(paymentId, "btc/domain", transaction.Characteristics.BankTransactionCode.Domain)) | ||
result = append(result, ComputePaymentMetadata(paymentId, "btc/family", transaction.Characteristics.BankTransactionCode.Family)) | ||
result = append(result, ComputePaymentMetadata(paymentId, "btc/subfamily", transaction.Characteristics.BankTransactionCode.Subfamily)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the
DKK
currency, because there is only one bank for theEUR
currency in the Atlar default sandbox. After asking them for a secondEUR
bank, they asked us if we could use aDKK
accounts for testing multi banking.