Ejegg has uploaded a new change for review.
https://gerrit.wikimedia.org/r/277600
Change subject: Use GatewayType hints in a few places, add functions
......................................................................
Use GatewayType hints in a few places, add functions
Also moves the PHPDoc comments from the abstract adapter class into
the interface.
Change-Id: Ifc040dd7d069d087f38befb8d99cd3eb8d79c7e3
---
M gateway_common/DataValidator.php
M gateway_common/DonationLoggerFactory.php
M gateway_common/GatewayType.php
M gateway_common/ResultPages.php
M gateway_common/gateway.adapter.php
5 files changed, 74 insertions(+), 55 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface
refs/changes/00/277600/1
diff --git a/gateway_common/DataValidator.php b/gateway_common/DataValidator.php
index 956d439..a6e2457 100644
--- a/gateway_common/DataValidator.php
+++ b/gateway_common/DataValidator.php
@@ -180,7 +180,7 @@
* validate
* Run all the validation rules we have defined against a (hopefully
* normalized) DonationInterface data set.
- * @param GatewayAdapter $gateway
+ * @param GatewayType $gateway
* @param array $data The DonationInterface data set, or a subset
thereof.
* @param array $check_not_empty An array of fields to do empty
validation
* on. If this is not populated, no fields will throw errors for being
empty,
@@ -191,7 +191,7 @@
* the main DonationInterface Form class to display. The array will be
empty
* if no errors were generated and everything passed OK.
*/
- public static function validate( GatewayAdapter $gateway, $data,
$check_not_empty = array() ){
+ public static function validate( GatewayType $gateway, $data,
$check_not_empty = array() ){
//return the array of errors that should be generated on
validate.
//just the same way you'd do it if you were a form passing the
error array around.
diff --git a/gateway_common/DonationLoggerFactory.php
b/gateway_common/DonationLoggerFactory.php
index 63d324f..7e69ae3 100644
--- a/gateway_common/DonationLoggerFactory.php
+++ b/gateway_common/DonationLoggerFactory.php
@@ -16,13 +16,13 @@
public static $overrideLogger = null;
/**
- * @param GatewayAdapter $adapter Get settings from this instance
+ * @param GatewayType $adapter Get settings from this instance
* @param string $suffix Append this string to the adapter identifier
* @param LogPrefixProvider $prefixer Optionally use this to override
* prefixing via the adapter.
* @return \Psr\Log\LoggerInterface
*/
- public static function getLogger( GatewayAdapter $adapter = null,
$suffix = '', LogPrefixProvider $prefixer = null ) {
+ public static function getLogger( GatewayType $adapter = null, $suffix
= '', LogPrefixProvider $prefixer = null ) {
if ( self::$overrideLogger !== null ) {
return self::$overrideLogger;
}
@@ -65,10 +65,10 @@
/**
* Retrieve a profiler instance which saves communication statistics
* if the adapter's SaveCommStats global is set to true.
- * @param GatewayAdapter $adapter
+ * @param GatewayType $adapter
* @return DonationProfiler
*/
- public static function getProfiler( GatewayAdapter $adapter ) {
+ public static function getProfiler( GatewayType $adapter ) {
if ( $adapter::getGlobal( 'SaveCommStats' ) ) {
$commLogger = self::getLogger( $adapter, '_commstats' );
} else {
diff --git a/gateway_common/GatewayType.php b/gateway_common/GatewayType.php
index c84ef79..e77f3a3 100644
--- a/gateway_common/GatewayType.php
+++ b/gateway_common/GatewayType.php
@@ -8,6 +8,40 @@
// all the particulars of the child classes. Aaaaall.
/**
+ * Gets the name of the payment processor, e.g. Adyen
+ * @return string
+ */
+ public static function getGatewayName();
+
+ /**
+ * Get a tag to use to identify this adapter in logs, e.g.
amazon_gateway
+ * @return string
+ */
+ public static function getLogIdentifier();
+
+ /**
+ * This function is important.
+ * All the globals in Donation Interface should be accessed in this
manner
+ * if they are meant to have a default value, but can be overridden by
any
+ * of the gateways. It will check to see if a gateway-specific global
+ * exists, and if one is not set, it will pull the default from the
+ * wgDonationInterface definitions. Through this function, it is no
longer
+ * necessary to define gateway-specific globals in LocalSettings unless
you
+ * wish to override the default value for all gateways.
+ * If the variable exists in {prefix}AccountInfo[currentAccountName],
+ * that value will override the default settings.
+ *
+ * @param string $varname The global value we're looking for. It will
first
+ * look for a global named for the instantiated gateway's GLOBAL_PREFIX,
+ * plus the $varname value. If that doesn't come up with anything that
has
+ * been set, it will use the default value for all of donation
interface,
+ * stored in $wgDonationInterface . $varname.
+ * @return mixed The configured value for that gateway if it exists. If
not,
+ * the configured value for Donation Interface if it exists or not.
+ */
+ public static function getGlobal( $varname );
+
+ /**
* Process the API response obtained from the payment processor and set
* properties of transaction_response
* @param array|DomDocument $response Cleaned-up response returned from
@@ -163,4 +197,30 @@
* @return string
*/
function getResponseType();
+
+ /**
+ * This is the ONLY getData type function anything should be using
+ * outside the adapter.
+ * Short explanation of the data population up to now:
+ * *) When the gateway adapter is constructed, it constructs a
DonationData
+ * object.
+ * *) On construction, the DonationData object pulls donation data
from an
+ * appropriate source, and normalizes the entire data set
for storage.
+ * *) The gateway adapter pulls normalized, html escaped data out
of the
+ * DonationData object, as the base of its own data set.
+ * @param string $val The specific key you're looking for (if any)
+ * @return mixed An array of all the raw, unstaged (but normalized and
+ * sanitized) data sent to the adapter, or if $val was set, either the
+ * specific value held for $val, or null if none exists.
+ */
+ public function getData_Unstaged_Escaped( $val = '' );
+
+ /**
+ * Retrieve the data we will need in order to retry a payment.
+ * This is useful in the event that we have just killed a session before
+ * the next retry.
+ * @return array Data required for a payment retry.
+ */
+ public function getRetryData();
+
}
diff --git a/gateway_common/ResultPages.php b/gateway_common/ResultPages.php
index 3800c54..6653a3f 100644
--- a/gateway_common/ResultPages.php
+++ b/gateway_common/ResultPages.php
@@ -4,11 +4,11 @@
/**
* Get the URL for a page to show donors after a successful donation,
* with the country code appended as a query string variable
- * @param GatewayAdapter $adapter
+ * @param GatewayType $adapter
* @param array $extraParams any extra parameters to add to the URL
* @return string
*/
- public static function getThankYouPage( GatewayAdapter $adapter,
$extraParams = array() ) {
+ public static function getThankYouPage( GatewayType $adapter,
$extraParams = array() ) {
$page = $adapter::getGlobal( "ThankYouPage" );
if ( $page ) {
$page = self::appendLanguageAndMakeURL( $page, $adapter
);
@@ -19,10 +19,10 @@
/**
* Get the URL for a page to show donors after a failed donation
- * @param GatewayAdapter $adapter
+ * @param GatewayType $adapter
* @return string
*/
- public static function getFailPage( GatewayAdapter $adapter ) {
+ public static function getFailPage( GatewayType $adapter ) {
// Prefer RapidFail.
if ( $adapter::getGlobal( 'RapidFail' ) ) {
$data = $adapter->getData_Unstaged_Escaped();
@@ -53,10 +53,10 @@
/**
* Get the URL for a page to show donors who cancel their attempt
- * @param GatewayAdapter $adapter
+ * @param GatewayType $adapter
* @return string
*/
- public static function getCancelPage( GatewayAdapter $adapter ) {
+ public static function getCancelPage( GatewayType $adapter ) {
$cancelPage = $adapter->getGlobal( 'CancelPage' );
if ( empty( $cancelPage ) ) {
return '';
@@ -70,10 +70,10 @@
* appended onto the end.
* @param string $url Either a wiki page title, or a URL to an external
wiki
* page title.
- * @param GatewayAdapter $adapter
+ * @param GatewayType $adapter
* @return string A URL
*/
- protected static function appendLanguageAndMakeURL( $url,
GatewayAdapter $adapter ) {
+ protected static function appendLanguageAndMakeURL( $url, GatewayType
$adapter ) {
$language = $adapter->getData_Unstaged_Escaped( 'language' );
// make sure we don't already have the language in there...
$dirs = explode('/', $url);
diff --git a/gateway_common/gateway.adapter.php
b/gateway_common/gateway.adapter.php
index 7619dee..b068dc9 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -417,21 +417,6 @@
$this->dataObj->addData( $newlyUnstagedData );
}
- /**
- * This is the ONLY getData type function anything should be using
- * outside the adapter.
- * Short explanation of the data population up to now:
- * *) When the gateway adapter is constructed, it constructs a
DonationData
- * object.
- * *) On construction, the DonationData object pulls donation data
from an
- * appropriate source, and normalizes the entire data set
for storage.
- * *) The gateway adapter pulls normalized, html escaped data out
of the
- * DonationData object, as the base of its own data set.
- * @param string $val The specific key you're looking for (if any)
- * @return mixed An array of all the raw, unstaged (but normalized and
- * sanitized) data sent to the adapter, or if $val was set, either the
- * specific value held for $val, or null if none exists.
- */
public function getData_Unstaged_Escaped( $val = '' ) {
if ( $val === '' ) {
return $this->unstaged_data;
@@ -444,26 +429,6 @@
}
}
- /**
- * This function is important.
- * All the globals in Donation Interface should be accessed in this
manner
- * if they are meant to have a default value, but can be overridden by
any
- * of the gateways. It will check to see if a gateway-specific global
- * exists, and if one is not set, it will pull the default from the
- * wgDonationInterface definitions. Through this function, it is no
longer
- * necessary to define gateway-specific globals in LocalSettings unless
you
- * wish to override the default value for all gateways.
- * If the variable exists in {prefix}AccountInfo[currentAccountName],
- * that value will override the default settings.
- *
- * @param string $varname The global value we're looking for. It will
first
- * look for a global named for the instantiated gateway's GLOBAL_PREFIX,
- * plus the $varname value. If that doesn't come up with anything that
has
- * been set, it will use the default value for all of donation
interface,
- * stored in $wgDonationInterface . $varname.
- * @return mixed The configured value for that gateway if it exists. If
not,
- * the configured value for Donation Interface if it exists or not.
- */
static function getGlobal( $varname ) {
// adding another layer of depth here, in case you're working
with two gateways in the same request.
// That does, in fact, ruin everything. :/
@@ -3257,12 +3222,6 @@
return $match;
}
- /**
- * Retrieve the data we will need in order to retry a payment.
- * This is useful in the event that we have just killed a session before
- * the next retry.
- * @return array Data required for a payment retry.
- */
public function getRetryData() {
$params = array ( );
foreach ( $this->dataObj->getRetryFields() as $field ) {
--
To view, visit https://gerrit.wikimedia.org/r/277600
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifc040dd7d069d087f38befb8d99cd3eb8d79c7e3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits