Skip to content

Commit

Permalink
Allow response undefined parameters as extra parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
dtorras committed Jun 2, 2024
1 parent ca470e5 commit 804c574
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Support/DataTransferObject/DataTransferObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static function fromArray(array $parameters): static
$normalizedParameters = [];
$propertiesName = [];
$propertiesCast = [];
$extraParameters = [];
$class = new ReflectionClass(static::class);
$properties = $class->getProperties();

Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/Support/NotificationParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public function __construct(

#[MapFrom('DS_RESPONSE_DESCRIPTION')]
public ?string $responseDescription = null,

public ?array $extraParameters = null,
) {
}

Expand Down

0 comments on commit 804c574

Please sign in to comment.