jenkins-bot has submitted this change and it was merged.
Change subject: Add banner history log ID processor
......................................................................
Add banner history log ID processor
Adds:
- non-critical queue 'banner-history'
- 'GatewayReady' hook
Bug: T112022
Change-Id: Ibfeccec7be38a8201f4cc0d4a96534f116c3698c
---
M DonationInterface.php
A extras/banner_history/BannerHistoryLogIdProcessor.php
M gateway_common/gateway.adapter.php
M tests/Adapter/GatewayAdapterTest.php
4 files changed, 106 insertions(+), 0 deletions(-)
Approvals:
Ejegg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/DonationInterface.php b/DonationInterface.php
index 98054cf..2769e0e 100644
--- a/DonationInterface.php
+++ b/DonationInterface.php
@@ -121,6 +121,8 @@
$wgAutoloadClasses['Gateway_Extras_CustomFilters_Functions'] = __DIR__ .
'/extras/custom_filters/filters/functions/functions.body.php';
$wgAutoloadClasses['Gateway_Extras_CustomFilters_IP_Velocity'] = __DIR__ .
'/extras/custom_filters/filters/ip_velocity/ip_velocity.body.php';
+$wgAutoloadClasses['BannerHistoryLogIdProcessor'] = __DIR__ .
'/extras/banner_history/BannerHistoryLogIdProcessor.php';
+
$wgAutoloadClasses['Gateway_Extras_SessionVelocityFilter'] = __DIR__ .
'/extras/session_velocity/session_velocity.body.php';
$wgAutoloadClasses['GatewayFormChooser'] = __DIR__ .
'/special/GatewayFormChooser.php';
$wgAutoloadClasses['SystemStatus'] = __DIR__ . '/special/SystemStatus.php';
@@ -510,8 +512,14 @@
// These messages will be shoved into the fraud database (see
// crm/modules/fredge).
'payments-antifraud' => array(),
+
// These are shoved into the payments-initial database.
'payments-init' => array(),
+
+ // Banner history log ID-contribution tracking ID associations that go
in
+ // Drupal in banner_history_contribution_associations. See
+ // crm/modules/queue2civicrm/banner_history
+ 'banner-history' => array(),
);
//Custom Filters globals
@@ -793,6 +801,8 @@
$wgDonationInterfaceGatewayAdapters[] = 'WorldpayAdapter';
//Custom Filters hooks
+$wgHooks['GatewayReady'][] = array(
'BannerHistoryLogIdProcessor::onGatewayReady' );
+
$wgHooks['GatewayValidate'][] = array(
'Gateway_Extras_CustomFilters::onValidate' );
$wgHooks['GatewayCustomFilter'][] = array(
'Gateway_Extras_CustomFilters_Referrer::onFilter' );
diff --git a/extras/banner_history/BannerHistoryLogIdProcessor.php
b/extras/banner_history/BannerHistoryLogIdProcessor.php
new file mode 100644
index 0000000..1e4c3c6
--- /dev/null
+++ b/extras/banner_history/BannerHistoryLogIdProcessor.php
@@ -0,0 +1,92 @@
+<?php
+
+/**
+ * Processor for banner history log ID. Handles the GatewayReady hook. (See
+ * below.)
+ */
+class BannerHistoryLogIdProcessor {
+
+ /**
+ * The URL parameter used to send the banner history log ID. Must
correspond
+ * with Javascript used in banners.
+ */
+ const BANNER_HISTORY_LOG_ID_PARAM = 'bannerhistlog';
+
+ /**
+ * @var \Psr\Log\LoggerInterface
+ */
+ protected $logger;
+
+ /**
+ * @var GatewayAdapter
+ */
+ protected $gatewayAdapter;
+
+ protected static function singleton( $gatewayAdapter ) {
+ static $instance;
+
+ if ( !$instance ) {
+ $instance = new BannerHistoryLogIdProcessor(
$gatewayAdapter );
+ }
+ return $instance;
+ }
+
+ protected function __construct( $gatewayAdapter ) {
+ $this->gatewayAdapter = $gatewayAdapter;
+
+ $this->logger = DonationLoggerFactory::getLogger(
+ $gatewayAdapter, '_banner_history' );
+ }
+
+ /**
+ * Queue a message with the banner history ID sent on the URL, the
+ * contribution tracking ID from DonationData, and some additional data.
+ */
+ protected function queueAssociationOfIds() {
+
+ $this->logger->debug(
+ 'BannerHistoryLogIdProcessor::queueAssociationOfIds():
will ' .
+ 'push to banner-history queue if required info is
available.' );
+
+ $bannerHistoryId = RequestContext::getMain()->getRequest()
+ ->getText( self::BANNER_HISTORY_LOG_ID_PARAM );
+
+ // Campaigns may not have banner history enabled. For now, at
least,
+ // bow out silently if no banner history ID was sent.
+ if ( !$bannerHistoryId ) {
+ return;
+ }
+
+ $contributionTrackingId = $this->gatewayAdapter
+ ->getData_Unstaged_Escaped( 'contribution_tracking_id'
);
+
+ if ( !$contributionTrackingId ) {
+ $this->logger->info( 'No contribution tracking ID for '
.
+ 'banner-history queue ' .
$bannerHistoryId . '.' );
+ return;
+ }
+
+ $data = array(
+ 'freeform' => true,
+ 'banner_history_id' => $bannerHistoryId,
+ 'contribution_tracking_id' => $contributionTrackingId,
+ );
+
+ $this->logger->info( 'Pushing to banner-history queue.' );
+ DonationQueue::instance()->push( $data, 'banner-history' );
+ }
+
+ /**
+ * Handler for the GatewayReady hook. This is the class's entry point.
+ *
+ * @param GatewayAdapter $gatewayAdapter
+ * @param DonationData $donationData
+ */
+ public static function onGatewayReady( $gatewayAdapter ) {
+
+ self::singleton( $gatewayAdapter )
+ ->queueAssociationOfIds();
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/gateway_common/gateway.adapter.php
b/gateway_common/gateway.adapter.php
index 7b16c0d..d64b3e4 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -420,6 +420,8 @@
$this->setGatewayDefaults( $options );
$this->stageData();
+
+ WmfFramework::runHooks( 'GatewayReady', array( $this ) );
}
/**
diff --git a/tests/Adapter/GatewayAdapterTest.php
b/tests/Adapter/GatewayAdapterTest.php
index 440c306..2bee06c 100644
--- a/tests/Adapter/GatewayAdapterTest.php
+++ b/tests/Adapter/GatewayAdapterTest.php
@@ -169,6 +169,7 @@
// Then they go back and decide they want to make a recurring
donation
$init['recurring'] = '1';
+ RequestContext::resetMain();
$this->setMwGlobals( 'wgRequest', new FauxRequest( $init, false
) );
$gateway = new TestingGlobalCollectAdapter();
@@ -197,6 +198,7 @@
// Then they go back and decide they want to donate via credit
card
$init['payment_method'] = 'cc';
unset( $init['payment_submethod'] );
+ RequestContext::resetMain();
$this->setMwGlobals( 'wgRequest', new FauxRequest( $init, false
) );
$gateway = new TestingAstropayAdapter();
--
To view, visit https://gerrit.wikimedia.org/r/244109
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibfeccec7be38a8201f4cc0d4a96534f116c3698c
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: AndyRussG <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Awight <[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