The AJAX endpoint at civicrm/stripe/confirm-payment was responsible for:
- handling HTTP request
- performing work
- emmitting HTTP response
This pattern tied the doing code to an HTTP request, which means it's untestable and also means the doing part of the code cannot be used for custom donation pages (for example).
This PR separates out the two functions (the HTTP handling from the doing code). It should have no functional change.
It leaves the original method as responsible for handling the HTTP request, but the inner workings are now separated out:
doConfirmPayment()takes an array of inputs, throws different exceptions for invalid request or for stripe card errors, and returns a Stripe PaymentIntent if successful.
generatePaymentResponse()now outputs an array (instead of exiting the script via json output) and throws an exception if there's an error.
It brings each method down to well below 100 SLOC.
As well as opening the possibility of (future) phpunit tests, it also means custom integrations can use the functionality without reimplementing it.
I've not tested this yet, but thought I'd pop this up here now in case you had any strong objections?