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 state machine for a single-form payment #49

Open judgej opened 7 years ago

judgej commented 7 years ago

Okay, a state machine sounds a little fancy, but the idea is to map out all the states needed to be able to support payment in a single form.

The form would contain the auto-generated CC fields, and the personal details (name, address etc.). LOTS of things need to happen in the right order for this to work.

In short, one simple success path through, but MANY things that can expire or be found to be invalid at various stages, with jumps back to earlier stages in the path needed to pick up on those exceptions.

We also need to think hard about how JS validation of personal details would work, since it needs to work alongside the CC details validation. Perhaps the way to handle that would be a callback on successful tokenisation of the card to physically remove the CC form fields immediately so it won't be accidentally tokenised twice (the second time of which would fail).

Also note that the AJAX tokenisation may also discover the session key is expired or overused, and so need to fetch a new from the server to retry tokenisation.

It might make more sense as a spreadsheet. It's had me stumped for a long time. My solution at the moment is to have two separate forms on two pages - the first to collect the CC details and tokenise them (AJAX) and the second to submit the personal details. Once the user is past the first form, they can submit the second form as many times as needed to get through local validation, before eventually sending the payment request. It's not as smooth a UX as it should be as a consequence.