improved tgsettle messages + storage fixes
This commit is contained in:
@@ -28,6 +28,7 @@ type Config struct {
|
||||
|
||||
type Account struct {
|
||||
AccountID string
|
||||
AccountCode string
|
||||
Currency string
|
||||
OrganizationRef string
|
||||
}
|
||||
@@ -130,14 +131,20 @@ func (c *connectorClient) GetAccount(ctx context.Context, accountID string) (*Ac
|
||||
if account == nil {
|
||||
return nil, merrors.NoData("ledger account not found")
|
||||
}
|
||||
accountCode := strings.TrimSpace(account.GetLabel())
|
||||
organizationRef := strings.TrimSpace(account.GetOwnerRef())
|
||||
if organizationRef == "" && account.GetProviderDetails() != nil {
|
||||
if value, ok := account.GetProviderDetails().AsMap()["organization_ref"]; ok {
|
||||
organizationRef = strings.TrimSpace(fmt.Sprint(value))
|
||||
details := account.GetProviderDetails().AsMap()
|
||||
if organizationRef == "" {
|
||||
organizationRef = firstDetailValue(details, "organization_ref", "organizationRef", "org_ref")
|
||||
}
|
||||
if accountCode == "" {
|
||||
accountCode = firstDetailValue(details, "account_code", "accountCode", "code", "ledger_account_code")
|
||||
}
|
||||
}
|
||||
return &Account{
|
||||
AccountID: accountID,
|
||||
AccountCode: accountCode,
|
||||
Currency: strings.ToUpper(strings.TrimSpace(account.GetAsset())),
|
||||
OrganizationRef: organizationRef,
|
||||
}, nil
|
||||
@@ -285,3 +292,21 @@ func normalizeEndpoint(raw string) (string, bool) {
|
||||
return raw, false
|
||||
}
|
||||
}
|
||||
|
||||
func firstDetailValue(values map[string]any, keys ...string) string {
|
||||
if len(values) == 0 || len(keys) == 0 {
|
||||
return ""
|
||||
}
|
||||
for _, key := range keys {
|
||||
key = strings.TrimSpace(key)
|
||||
if key == "" {
|
||||
continue
|
||||
}
|
||||
if value, ok := values[key]; ok {
|
||||
if text := strings.TrimSpace(fmt.Sprint(value)); text != "" {
|
||||
return text
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user