CommerceWeavers/SyliusSaferpayPlugin

Attempt of creation Error object from non-existing response fields

plewandowski opened this issue ยท 3 comments

What is the problem?

Value object cannot be created and causes PHP fatal error.

This is about following line:

How to reproduce?

Simulate any API error and place order

How I did it?

Basically you can send some invalid fields?

This is sample error response I have just triggered:

{
    "ResponseHeader": {
        "SpecVersion": "1.34",
        "RequestId": "XXXX534543534"
    },
    "Behavior": "DO_NOT_RETRY",
    "ErrorName": "VALIDATION_FAILED",
    "ErrorMessage": "Request validation failed",
    "ErrorDetail": [
        "Payment.OrderId: The field OrderId is invalid.",
        "ReturnUrl.Url: The field Url is invalid."
    ]
}

Why I think is wrong?

Following code uses non-existing fields names. Correct fields names you can find in example error response given above and on the doc page: https://saferpay.github.io/jsonapi/#errorhandling

public static function fromArray(array $data): self
    {
        return new self(
            $data['Behavior'],
            $data['Name'],
            $data['Message'],
            $data['Details'],
        );
    }

How do I think it could be fixed?

public static function fromArray(array $data): self
    {
        return new self(
            $data['Behavior'],
            $data['ErrorName'],
            $data['ErrorMessage'],
            $data['ErrorDetail'],
        );
    }

btw. even after fixing the names ErrorDetail is not logged, which is quite important as errorName is usually something very general like "validation failed"

Naming is already fixed on main ๐Ÿ–– https://github.com/CommerceWeavers/SyliusSaferpayPlugin/blob/main/src/Client/ValueObject/Body/Error.php#L82

I totally agree ErrorDetail should be logged as well ๐Ÿ‘

Done ๐Ÿ––