From 804c574e37e9a44e8f79d2f87f2de33360c4f80e Mon Sep 17 00:00:00 2001 From: David Torras Date: Sun, 2 Jun 2024 18:06:03 +0200 Subject: [PATCH] Allow response undefined parameters as extra parameters --- .../DataTransferObject/DataTransferObject.php | 16 +++++++++++++++- src/Support/NotificationParameters.php | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Support/DataTransferObject/DataTransferObject.php b/src/Support/DataTransferObject/DataTransferObject.php index 996c00a..a0fd073 100644 --- a/src/Support/DataTransferObject/DataTransferObject.php +++ b/src/Support/DataTransferObject/DataTransferObject.php @@ -39,6 +39,7 @@ public static function fromArray(array $parameters): static $normalizedParameters = []; $propertiesName = []; $propertiesCast = []; + $extraParameters = []; $class = new ReflectionClass(static::class); $properties = $class->getProperties(); @@ -58,7 +59,20 @@ public static function fromArray(array $parameters): static foreach ($parameters as $key => $value) { $caseKey = self::caseSensitive() ? $key : strtoupper($key); - $normalizedParameters[$propertiesName[$caseKey] ?? $key] = self::getCastedValue($value, $propertiesCast[$propertiesName[$caseKey]] ?? null); + $foundKey = $propertiesName[$caseKey] ?? null; + if (! $foundKey) { + /** + * Received undefined parameter from Redsys. Probably not documented. + * Please report this at https://github.com/creagia/redsys-php + */ + $extraParameters[$caseKey] = $value; + } else { + $normalizedParameters[$propertiesName[$caseKey] ?? $key] = self::getCastedValue($value, $propertiesCast[$propertiesName[$caseKey]] ?? null); + } + } + + if (! empty($extraParameters)) { + $normalizedParameters['extraParameters'] = $extraParameters; } return new static(...$normalizedParameters); diff --git a/src/Support/NotificationParameters.php b/src/Support/NotificationParameters.php index 9ce95af..7872d67 100644 --- a/src/Support/NotificationParameters.php +++ b/src/Support/NotificationParameters.php @@ -109,6 +109,8 @@ public function __construct( #[MapFrom('DS_RESPONSE_DESCRIPTION')] public ?string $responseDescription = null, + + public ?array $extraParameters = null, ) { }