academe / SagePay-Integration

HTTP Messages for the Sage Pay REST (Pi) gateway.
GNU General Public License v3.0
9 stars 5 forks source link

Create response message factory #36

Closed judgej closed 8 years ago

judgej commented 8 years ago

Instead of handling which message to send the response into in the application, just send it into the factory and get the appropriate response message back. It would be a kind of "auto-detect" that would return a message, which could include a collection of errors.

A general "state" or "message type" property of the response will be useful to make high-level decisions.

This could also apply to ServerResponse messages, with one possible state being "nothing of relevance here".

This would make writing the wrapper code much easier. pulling more of the sequence detection logic into this package.

judgej commented 8 years ago

A few things we may need:

judgej commented 8 years ago

The response factory detects errors, payments, repeat payments and card identifiers so far. It can be called up like this:

$client = new Client(['http_errors' => false]); // Guzzle, suppress exceptions on HTTP errors.
$psr7_response = $client->send($payment->message());
$response_object = \Academe\SagePay\Psr7\Factory\ResponseFactory::parse($psr7_response);

and that will return the appropriate ErrorCollection or Response object. This makes me wonder whether the ErrorCollection should share an interface with the Response messages for a consistent return from this factory? Edit: oh, it already is. Sorted.

judgej commented 8 years ago

The checks for each response message type should be moved to the message classes. This way they can be used by an external application that may want to add its own logic and not go through the factory.

judgej commented 8 years ago

Added support for 3D Secure Redirect Response in Issue #37.

judgej commented 8 years ago

The messages need a comprehensive set of attributes that allow actions to be supported, informing the application what kind of message it has received and what to do with it. Some ideas:

Different flags will be relevant to different types of message. These flags can be used as a proxy to checking what the message classname is. For example, after sending a payment, isRedierct() will tell us whether the response is a 3D Secure redirect that needs a specific action. isAuthed() will check the values of the statuses without the need to know in the application what each returned status code means.

judgej commented 8 years ago

The factory provide the planned functionality now.