applyExternalAccount applies external account details to the given account. It fetches the configuration, checks if auto-generation is enabled, and makes an HTTP request to get account details. If the account details are successfully retrieved, they are applied to the account. Parameters: - account
(account *model.Account)
| 38 | // Returns: |
| 39 | // - error: An error if the operation fails. |
| 40 | func applyExternalAccount(account *model.Account) error { |
| 41 | type accountDetails struct { |
| 42 | AccountNumber string `json:"account_number"` |
| 43 | BankName string `json:"bank_name"` |
| 44 | } |
| 45 | |
| 46 | cnf, err := config.Fetch() |
| 47 | if err != nil { |
| 48 | return err |
| 49 | } |
| 50 | |
| 51 | if cnf.AccountNumberGeneration.EnableAutoGeneration { |
| 52 | req, err := http.NewRequest("GET", cnf.AccountNumberGeneration.HttpService.Url, nil) |
| 53 | if err != nil { |
| 54 | return err |
| 55 | } |
| 56 | |
| 57 | // Set the Authorization header for the HTTP request using the configuration. |
| 58 | req.Header.Set("Authorization", cnf.AccountNumberGeneration.HttpService.Headers.Authorization) |
| 59 | var response accountDetails |
| 60 | _, err = request.Call(req, &response) |
| 61 | if err != nil { |
| 62 | return err |
| 63 | } |
| 64 | |
| 65 | if response.AccountNumber != "" && response.BankName != "" { |
| 66 | account.Number = response.AccountNumber |
| 67 | account.BankName = response.BankName |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return nil |
| 72 | } |
| 73 | |
| 74 | // applyAccountName applies a name to the given account based on its identity. |
| 75 | // If the account name is empty, it fetches the identity and sets the account name |
no test coverage detected