mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* feat(EN-420): added page size as a const for each plugin * feat(EN-420): remove pageSize from connector config * feat(EN-420): review all limits according to api docs * ensure pageSize is marked as deprecated * sdk generation * fix: tests * fix: ignore linting error on depreated call * feat: change deprecation message * regenerate openapi & sdk * change message to avoid duplicating the deprecation word * regenerate openapi & sdk * feat: change deprecation message * regenerate openapi & sdk
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package generic
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/formancehq/payments/internal/connectors/plugins/sharedconfig"
|
|
"github.com/formancehq/payments/internal/models"
|
|
"github.com/go-playground/validator/v10"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type Config struct {
|
|
APIKey string `json:"apiKey" validate:"required"`
|
|
Endpoint string `json:"endpoint" validate:"required"`
|
|
PollingPeriod sharedconfig.PollingPeriod `json:"pollingPeriod"`
|
|
}
|
|
|
|
const PAGE_SIZE = 100 // 100 seems more likely
|
|
|
|
func unmarshalAndValidateConfig(payload json.RawMessage) (Config, error) {
|
|
var raw struct {
|
|
APIKey string `json:"apiKey"`
|
|
Endpoint string `json:"endpoint"`
|
|
PollingPeriod string `json:"pollingPeriod"`
|
|
}
|
|
if err := json.Unmarshal(payload, &raw); err != nil {
|
|
return Config{}, errors.Wrap(models.ErrInvalidConfig, err.Error())
|
|
}
|
|
|
|
pp, err := sharedconfig.NewPollingPeriod(
|
|
raw.PollingPeriod,
|
|
sharedconfig.DefaultPollingPeriod,
|
|
sharedconfig.MinimumPollingPeriod,
|
|
)
|
|
if err != nil {
|
|
return Config{}, errors.Wrap(models.ErrInvalidConfig, err.Error())
|
|
}
|
|
|
|
config := Config{
|
|
APIKey: raw.APIKey,
|
|
Endpoint: raw.Endpoint,
|
|
PollingPeriod: pp,
|
|
}
|
|
validate := validator.New(validator.WithRequiredStructEnabled())
|
|
return config, validate.Struct(config)
|
|
}
|