jenkins-bot has submitted this change and it was merged.
Change subject: Generalize data transformations
......................................................................
Generalize data transformations
Transformers are often specialized to only stage or unstage. Mark this with
specific interfaces. This also leaves us a path to implementing more
transformation types.
Bug: T130075
Change-Id: I1e6cf2f581f036cb4e875d8c5ae04bc4b7968ebd
---
M DonationInterface.php
M adyen_gateway/adyen.adapter.php
M amazon_gateway/amazon.adapter.php
M astropay_gateway/AstroPayFinancialNumbers.php
M astropay_gateway/AstroPayMethodCodec.php
M astropay_gateway/astropay.adapter.php
M gateway_common/AmountInCents.php
M gateway_common/DonorEmail.php
M gateway_common/DonorFullName.php
M gateway_common/GatewayType.php
M gateway_common/StagingHelper.php
M gateway_common/StreetAddress.php
A gateway_common/UnstagingHelper.php
M gateway_common/gateway.adapter.php
M globalcollect_gateway/globalcollect.adapter.php
M paypal_gateway/paypal.adapter.php
M tests/includes/test_gateway/TestingGenericAdapter.php
M worldpay_gateway/worldpay.adapter.php
18 files changed, 47 insertions(+), 42 deletions(-)
Approvals:
Cdentinger: Looks good to me, approved
jenkins-bot: Verified
diff --git a/DonationInterface.php b/DonationInterface.php
index e4d8e71..1de10b6 100644
--- a/DonationInterface.php
+++ b/DonationInterface.php
@@ -65,6 +65,7 @@
$wgAutoloadClasses['ResultPages'] = __DIR__ .
'/gateway_common/ResultPages.php';
$wgAutoloadClasses['StagingHelper'] = __DIR__ .
'/gateway_common/StagingHelper.php';
$wgAutoloadClasses['StreetAddress'] = __DIR__ .
'/gateway_common/StreetAddress.php';
+$wgAutoloadClasses['UnstagingHelper'] = __DIR__ .
'/gateway_common/UnstagingHelper.php';
$wgAutoloadClasses['WmfFramework_Mediawiki'] = __DIR__ .
'/gateway_common/WmfFramework.mediawiki.php';
$wgAutoloadClasses['WmfFrameworkLogHandler'] = __DIR__ .
'/gateway_common/WmfFrameworkLogHandler.php';
diff --git a/adyen_gateway/adyen.adapter.php b/adyen_gateway/adyen.adapter.php
index 2831156..fad6b0d 100644
--- a/adyen_gateway/adyen.adapter.php
+++ b/adyen_gateway/adyen.adapter.php
@@ -65,8 +65,8 @@
);
}
- function defineStagingHelpers() {
- $this->staging_helpers = parent::getCoreStagingHelpers();
+ public function defineDataTransformers() {
+ $this->data_transformers = parent::getCoreDataTransformers();
}
/**
diff --git a/amazon_gateway/amazon.adapter.php
b/amazon_gateway/amazon.adapter.php
index edbecb1..cc90db6 100644
--- a/amazon_gateway/amazon.adapter.php
+++ b/amazon_gateway/amazon.adapter.php
@@ -133,9 +133,11 @@
);
}
- function defineStagingHelpers() {
+ function defineDataTransformers() {
// Skip AmountInCents, we want to pass the real amount x1.
- $this->staging_helpers = array(
+ $this->data_transformers = array(
+ new DonorEmail(),
+ new DonorFullName(),
new StreetAddress(),
);
}
diff --git a/astropay_gateway/AstroPayFinancialNumbers.php
b/astropay_gateway/AstroPayFinancialNumbers.php
index 9c86d59..a2f94b4 100644
--- a/astropay_gateway/AstroPayFinancialNumbers.php
+++ b/astropay_gateway/AstroPayFinancialNumbers.php
@@ -36,7 +36,4 @@
$stagedData['fiscal_number'] = preg_replace(
'/[^a-zA-Z0-9]/', '', $unstagedData['fiscal_number'] );
}
}
-
- // No-op
- public function unstage( GatewayType $adapter, $stagedData,
&$unstagedData ) {}
}
diff --git a/astropay_gateway/AstroPayMethodCodec.php
b/astropay_gateway/AstroPayMethodCodec.php
index 9b70cfd..e77362d 100644
--- a/astropay_gateway/AstroPayMethodCodec.php
+++ b/astropay_gateway/AstroPayMethodCodec.php
@@ -1,9 +1,6 @@
<?php
-class AstroPayMethodCodec implements StagingHelper {
- // No-op
- public function stage( GatewayType $adapter, $unstagedData,
&$stagedData ) {}
-
+class AstroPayMethodCodec implements UnstagingHelper {
/**
* Transforms the astropay payment method into our method name
*/
diff --git a/astropay_gateway/astropay.adapter.php
b/astropay_gateway/astropay.adapter.php
index 455a4d9..e3f8f47 100644
--- a/astropay_gateway/astropay.adapter.php
+++ b/astropay_gateway/astropay.adapter.php
@@ -658,9 +658,9 @@
}
- function defineStagingHelpers() {
+ public function defineDataTransformers() {
// Skip AmountInCents.
- $this->staging_helpers = array(
+ $this->data_transformers = array(
new AstroPayFinancialNumbers(),
new AstroPayMethodCodec(),
new DonorFullName(),
diff --git a/gateway_common/AmountInCents.php b/gateway_common/AmountInCents.php
index d5e03a2..f04bb1c 100644
--- a/gateway_common/AmountInCents.php
+++ b/gateway_common/AmountInCents.php
@@ -9,7 +9,7 @@
* avoid killing the payment processor.
* For example: JPY 1000.05 would be changed to 100005, but should be 100000.
*/
-class AmountInCents implements StagingHelper {
+class AmountInCents implements StagingHelper, UnstagingHelper {
public function stage( GatewayType $adapter, $unstagedData,
&$stagedData ) {
if ( empty( $unstagedData['amount'] ) || empty(
$unstagedData['currency_code'] ) ) {
//can't do anything with amounts at all. Just go home.
diff --git a/gateway_common/DonorEmail.php b/gateway_common/DonorEmail.php
index 5a0e537..36b2144 100644
--- a/gateway_common/DonorEmail.php
+++ b/gateway_common/DonorEmail.php
@@ -6,7 +6,4 @@
$stagedData['email'] = $adapter->getGlobal(
'DefaultEmail' );
}
}
-
- // No-op
- public function unstage( GatewayType $adapter, $stagedData,
&$unstagedData ) {}
}
diff --git a/gateway_common/DonorFullName.php b/gateway_common/DonorFullName.php
index 6a4b7b8..19232b0 100644
--- a/gateway_common/DonorFullName.php
+++ b/gateway_common/DonorFullName.php
@@ -15,7 +15,4 @@
}
$stagedData['full_name'] = implode( ' ', $name_parts );
}
-
- // No-op.
- public function unstage( GatewayType $adapter, $stagedData,
&$unstagedData ) {}
}
diff --git a/gateway_common/GatewayType.php b/gateway_common/GatewayType.php
index 81e320b..074a8a3 100644
--- a/gateway_common/GatewayType.php
+++ b/gateway_common/GatewayType.php
@@ -119,9 +119,9 @@
function definePaymentMethods();
/**
- * Sets up the $staging_helpers array.
+ * Sets up the $data_transformers array.
*/
- function defineStagingHelpers();
+ function defineDataTransformers();
/**
* Sets up the $order_id_meta array.
diff --git a/gateway_common/StagingHelper.php b/gateway_common/StagingHelper.php
index c6b4dec..2e48a96 100644
--- a/gateway_common/StagingHelper.php
+++ b/gateway_common/StagingHelper.php
@@ -1,6 +1,9 @@
<?php
+/**
+ * Used to mark any class which implements an staging method, for transforming
+ * data into the form expected by a payment processing gateway API endpoint.
+ */
interface StagingHelper {
function stage( GatewayType $adapter, $unstagedData, &$stagedData );
- function unstage( GatewayType $adapter, $stagedData, &$unstagedData );
}
diff --git a/gateway_common/StreetAddress.php b/gateway_common/StreetAddress.php
index 37166c9..01850e2 100644
--- a/gateway_common/StreetAddress.php
+++ b/gateway_common/StreetAddress.php
@@ -65,7 +65,4 @@
return $zip;
}
-
- // No-op
- public function unstage( GatewayType $adapter, $stagedData,
&$unstagedData ) {}
}
diff --git a/gateway_common/UnstagingHelper.php
b/gateway_common/UnstagingHelper.php
new file mode 100644
index 0000000..b544336
--- /dev/null
+++ b/gateway_common/UnstagingHelper.php
@@ -0,0 +1,9 @@
+<?php
+
+/**
+ * Used to mark any class which implements an unstaging method, for
transforming
+ * data returned by a payment processing gateway API call.
+ */
+interface UnstagingHelper {
+ function unstage( GatewayType $adapter, $stagedData, &$unstagedData );
+}
diff --git a/gateway_common/gateway.adapter.php
b/gateway_common/gateway.adapter.php
index b88c42b..438f9f1 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -105,9 +105,10 @@
protected $unstaged_data;
/**
- * Staging helper objects. These implement the StagingHelper interface.
+ * Data transformation helpers. These implement the StagingHelper
interface for now,
+ * and are responsible for staging and unstaging data.
*/
- protected $staging_helpers = array();
+ protected $data_transformers = array();
/**
* For gateways that speak XML, we use this variable to hold the
document
@@ -252,7 +253,7 @@
$this->defineDataConstraints();
$this->definePaymentMethods();
- $this->defineStagingHelpers();
+ $this->defineDataTransformers();
$this->session_resetOnSwitch(); // Need to do this before
creating DonationData
@@ -373,7 +374,7 @@
}
}
- public function getCoreStagingHelpers() {
+ public function getCoreDataTransformers() {
return array(
// Always stage email address first, to set default if
missing
new DonorEmail(),
@@ -1689,8 +1690,10 @@
// object initialization.
$this->defineStagedVars();
- foreach ( $this->staging_helpers as $staging_helper ) {
- $staging_helper->stage( $this, $this->unstaged_data,
$this->staged_data );
+ foreach ( $this->data_transformers as $transformer ) {
+ if ( $transformer instanceof StagingHelper ) {
+ $transformer->stage( $this,
$this->unstaged_data, $this->staged_data );
+ }
}
foreach ( $this->staged_vars as $field ) {
@@ -1719,8 +1722,10 @@
}
}
- foreach ( $this->staging_helpers as $staging_helper ) {
- $staging_helper->unstage( $this, $this->staged_data,
$this->unstaged_data );
+ foreach ( $this->data_transformers as $transformer ) {
+ if ( $transformer instanceof UnstagingHelper ) {
+ $transformer->unstage( $this,
$this->staged_data, $this->unstaged_data );
+ }
}
}
diff --git a/globalcollect_gateway/globalcollect.adapter.php
b/globalcollect_gateway/globalcollect.adapter.php
index 45fa384..baa5f32 100644
--- a/globalcollect_gateway/globalcollect.adapter.php
+++ b/globalcollect_gateway/globalcollect.adapter.php
@@ -1258,8 +1258,8 @@
);
}
- function defineStagingHelpers() {
- $this->staging_helpers = parent::getCoreStagingHelpers();
+ public function defineDataTransformers() {
+ $this->data_transformers = parent::getCoreDataTransformers();
}
/**
diff --git a/paypal_gateway/paypal.adapter.php
b/paypal_gateway/paypal.adapter.php
index 17eb657..4d8fd3a 100644
--- a/paypal_gateway/paypal.adapter.php
+++ b/paypal_gateway/paypal.adapter.php
@@ -184,8 +184,8 @@
);
}
- function defineStagingHelpers() {
- $this->staging_helpers = parent::getCoreStagingHelpers();
+ public function defineDataTransformers() {
+ $this->data_transformers = parent::getCoreDataTransformers();
}
public function doPayment() {
diff --git a/tests/includes/test_gateway/TestingGenericAdapter.php
b/tests/includes/test_gateway/TestingGenericAdapter.php
index 7f405b1..3ebb0c5 100644
--- a/tests/includes/test_gateway/TestingGenericAdapter.php
+++ b/tests/includes/test_gateway/TestingGenericAdapter.php
@@ -91,8 +91,8 @@
public function defineTransactions() {
}
- public function defineStagingHelpers() {
- $this->staging_helpers = parent::getCoreStagingHelpers();
+ public function defineDataTransformers() {
+ $this->data_transformers = parent::getCoreDataTransformers();
}
public function defineVarMap() {
diff --git a/worldpay_gateway/worldpay.adapter.php
b/worldpay_gateway/worldpay.adapter.php
index a943e05..cd4cca9 100644
--- a/worldpay_gateway/worldpay.adapter.php
+++ b/worldpay_gateway/worldpay.adapter.php
@@ -802,8 +802,8 @@
);
}
- function defineStagingHelpers() {
- $this->staging_helpers = parent::getCoreStagingHelpers();
+ public function defineDataTransformers() {
+ $this->data_transformers = parent::getCoreDataTransformers();
}
private function get_payment_method_name_from_api_name ( $api_name ) {
--
To view, visit https://gerrit.wikimedia.org/r/277845
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1e6cf2f581f036cb4e875d8c5ae04bc4b7968ebd
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: Ssmith <[email protected]>
Gerrit-Reviewer: XenoRyet <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits