Fundraising/Data and flow/PSP integrations/Gateway Chooser
Overview
The gateway chooser is a special page on paymentswiki used as a middleware to select a payment gateway (aka payment processor) for each donor based on their country, currency, and selected payment method, then prioritize the final gateway base on certain rules. Links from https://donate.wikimedia.org/ and banners will send donors to this special page rather than to the special pages for individual processors, so we can quickly respond to any outages by simply changing settings at paymentswiki.
The gateway chooser examines query string parameters currency, country and payment_method (e.g cc or apple, representing credit card and Apple Pay), recurring (boolean), and other params like payment_submethod as visa amex and so on. It loads yaml configuration files for all enabled gateways to filter down to a list of gateways which support the intended donation parameters.
Then finally it uses rules (defined in extension.json as DonationInterfaceGatewayPriorityRules) to select the target gateway. Each rule can have conditions (if no conditions exist it is the default, that is, it always applied) and a list of gateways in priority order. All conditions must match for a rule to be selected.
Testing
We can go to DI box
docker-compose exec -w "/var/www/html/" payments /bin/bash
then test testAssertExpectedGateway to test all the target gateway
php tests/phpunit/phpunit.php --filter testAssertExpectedGateway
locally we can test as below