mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* Use validation library for dummypay config * Replace individual connector configs with go-playground/validation struct * Update command to compile configs.json * Update connector template to use new validation system * Move plugin configuration into registry and remove config.json * Detect different types of configuration data when registering plugins * Ensure that RegisterPlugin skips non-json fields in Config * Update connector template to send Config struct to RegisterPlugin * Allow omission of optional Adyen fields from config * Add panic statements in RegisterPlugin to guard against bad plugin config setup
29 lines
916 B
Go
29 lines
916 B
Go
package adyen
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"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"`
|
|
CompanyID string `json:"companyID" validate:"required"`
|
|
LiveEndpointPrefix string `json:"liveEndpointPrefix" validate:"omitempty,alphanum"`
|
|
|
|
// https://datatracker.ietf.org/doc/html/rfc7617
|
|
WebhookUsername string `json:"webhookUsername" validate:"omitempty,excludes=:"`
|
|
WebhookPassword string `json:"webhookPassword" validate:""`
|
|
}
|
|
|
|
func unmarshalAndValidateConfig(payload []byte) (Config, error) {
|
|
var config Config
|
|
if err := json.Unmarshal(payload, &config); err != nil {
|
|
return Config{}, errors.Wrap(models.ErrInvalidConfig, err.Error())
|
|
}
|
|
validate := validator.New(validator.WithRequiredStructEnabled())
|
|
return config, validate.Struct(config)
|
|
}
|