Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • Stripe Stripe
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 90
    • Issues 90
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Extensions
  • StripeStripe
  • Merge requests
  • !142

Refactor confirm code to make more testable and support custom use

  • Review changes

  • Download
  • Patches
  • Plain diff
Closed Rich requested to merge artfulrobot/stripe:refactor-confirm-code into master Dec 07, 2020
  • Overview 2
  • Commits 1
  • Pipelines 0
  • Changes 1

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?

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: refactor-confirm-code