Extension:DonationInterface/Refactor 2015

Defining Refactor

 * Refactoring something should not change any features - there's no UI changes at all to the user, only to the back end
 * We should write complete tests that pass as is before writing the new pieces
 * Fixing bugs as a direct by-product of the refactor is OK, but not as a goal for the refactor
 * Documentation is a requirement to mark a refactored item as finished

UI/Forms

 * CSS - it's all over the place. Much of this must be unused, and should be removed.
 * JS - same thing
 * Reuse as many template pieces between gateways / countries / whatever else we're currently duplicating on, as possible
 * Handle the excessive amount of template file duplication without sacrificing flexibility, reusing as universally as possible
 * Remove php form cruft - Much of the extension doesn't take RapidHTML for granted, and we basically do now.
 * Replace template engine
 * Universal form (may not be possible)
 * Friendly error messages for situations we can tell the donors about (not a refactor concern. This is new work)
 * Form validation is currently taking place in GatewayPage.php, in the validateForm function. It says all over the thing that it should be somewhere else.

GatewayPage child classes

 * Remove all control logic from the page-related classes, and roll back in to the gateway classes

DonationData class

 * There is some evidence currently in the code, relating to a dream we had once, in the way we're currently trying (and failing) to handle order_id. This should be rolled in to the main strategy:
 * Each piece of data that DonationData keeps, should be an instance of a new data item class
 * The new class should keep track of all places that the data item can currently be pulled from ($_GET, $_POST, $_SESSION, passed to other class via constructor denoting some kind of batch mode, whatever else)
 * DonationData should keep general rules about what sources should win over other data sources, for each individual data item
 * DonationData should try to call back to specific gateway adapter classes for rule overrides

Gateway adapter classes

 * Refactor Transaction Structure
 * Put transaction structure data nodes somewhere that they can easily be added/ignored
 * Transformations become first class entities, or at least easy (and clear) to compose.
 * Improve readability and reduce complexity
 * Examine child classes for things to move to parent, and vice versa
 * Kill PFP and all its stupid references, right in its face.
 * This also involves moving all the resources that live in pfp, or are *called* pfp-something, or Payflow-something, or any variation on those things, to the common area and renaming them everywhere.
 * Separate declarative and code elements of adapters, see https://gerrit.wikimedia.org/r/#/c/65003/
 * Remove logging and logging-related functionality from adapter classes
 * Create a logger class that will do all the things we currently do, but won't require that the current adapter object is fully constructed before the logging will work without erroring out.
 * Clean up session handling
 * Refactor the way we store and handle payment method and submethod... violates REFACTOR ONLY rule
 * Polish antifraud rules
 * antifraud cruft removal
 * Transaction Status buckets: The map of their status to our buckets
 * Move XML and NVP building into helper classes, but we need a way to override some of that behavior from adapters.
 * Look at all the places where unexpected things were overridden in (particularly) Adyen and Amazon, and try to build these things in to the parent class where it makes sense to do so. (lots of TODO complaining in these classes)

ContributionTracking

 * Not working on Donate wiki
 * Make it not a SPOF
 * UTM information handling
 * Later step: would be nice to record each event rather than rollup

Misc

 * Remove all heavy lifting from class constructors <--helps with unit testing A LOT
 * Vagrant role for working on payments.wikimedia.org. The remaining glue here is to modify the MultiWiki module to handle a second mediawiki-core source checkout, under another branch.
 * LocalSettings. Is a mess. See what we can do about that.
 * Admin UI.
 * Status page for all the stuff, lockouts.
 * Once the UI is decoupled
 * take UI out of the DI extension entirely.
 * Then, beef up the standaloneness of DI payments code.
 * Merge into SmashPig.
 * Make i18n strings sane.
 * Lots of unused stuff and copies.
 * Actually sort into interface, gateway, etc... or pull out into more obviously universal place
 * UNIT TESTS - there's probably already a bunch of useless mess in there.
 * Anything hard to test, should probably be refactored in the actual code
 * activemq_stomp.php
 * All the things that "normalize" for our queues should probably start using smashpig message formats
 * reduce code duplication in this file and allow for more flexibility, as opposed to the current bizarre rigidity

Approach

 * Commits should be as contained as possible so that we can roll them back individually as we go if there is a problem
 * Does it make sense to have a difference between the old and new so that we can toggle between them?
 * Pros
 * If a new goal is set by not-fr-tech, we can hopefully meet that quickly
 * Having a staging vs. dev environment
 * Cons
 * Can't build a house on 2 foundations
 * Toggling between the 2 is hard/tricky/fiddly
 * If we want to really use the new thing, we need other people to use the new thing, too.
 * Don't change queue message format or queues in the refactor

Goals
Near-term
 * Achieve maintainable and modern UI.
 * Make it easy for other WMF engineers and volunteers to help with code.

Long-term
 * Our payments stuff is used and maintained by other orgs.

Steps

 * SmashPig
 * Push DonationInterface payments code into SmashPig.
 * Push sundry audit and listener components into SmashPig.
 * SmashPig should use standard libraries like Composer autoload and Monolog.