Awight has uploaded a new change for review.
https://gerrit.wikimedia.org/r/189139
Change subject: WIP more controller logic consolidation
......................................................................
WIP more controller logic consolidation
Bug: T86251
Change-Id: Iea2b71ee4745fff7ab9e0d3fcccc5cfe4588380d
---
M amazon_gateway/amazon.adapter.php
M amazon_gateway/amazon_gateway.body.php
A amazon_gateway/amazon_resultswitcher.body.php
M tests/Adapter/Amazon/AmazonTest.php
M worldpay_gateway/worldpay_gateway.body.php
5 files changed, 105 insertions(+), 78 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface
refs/changes/39/189139/1
diff --git a/amazon_gateway/amazon.adapter.php
b/amazon_gateway/amazon.adapter.php
index c7dd724..7eda508 100644
--- a/amazon_gateway/amazon.adapter.php
+++ b/amazon_gateway/amazon.adapter.php
@@ -232,8 +232,12 @@
$this->dataObj->saveContributionTrackingData();
//@TODO: This shouldn't be happening here. Oh
Amazon... Why can't you be more like PayPalAdapter?
- $wgOut->redirect("{$this->getGlobal( "URL"
)}?{$query_str}&signature={$signature}");
- return;
+ $this->setTransactionResult( array(
+ 'status' => true,
+ 'action' =>
$this->getValidationAction(),
+ 'redirect' => "{$this->getGlobal( "URL"
)}?{$query_str}&signature={$signature}",
+ ) );
+ break;
case 'VerifySignature':
// We don't currently use this. In fact we just
ignore the return URL signature.
@@ -251,19 +255,20 @@
$this->runPostProcessHooks();
$this->doLimboStompTransaction( true );
}
- return;
+ break;
case 'ProcessAmazonReturn':
// What we need to do here is make sure
$this->addDataFromURI();
$this->analyzeReturnStatus();
- return;
+ break;
default:
$this->log( "At $transaction; THIS IS NOT
DEFINED!", LOG_CRIT );
$this->finalizeInternalStatus( 'failed' );
- return;
}
+
+ return $this->getTransactionAllResults();
}
static function getCurrencies() {
diff --git a/amazon_gateway/amazon_gateway.body.php
b/amazon_gateway/amazon_gateway.body.php
index 785f4b9..41c6184 100644
--- a/amazon_gateway/amazon_gateway.body.php
+++ b/amazon_gateway/amazon_gateway.body.php
@@ -34,42 +34,21 @@
protected function handleRequest() {
$this->getOutput()->allowClickjacking();
- $this->setHeaders();
+ $this->handleDonationRequest();
+ }
- if ( $this->validateForm() ) {
- $this->displayForm();
+ protected function processPayment() {
+ error_log("foo");
+ if ( $this->adapter->getData_Unstaged_Escaped( 'ffname' ) ===
'amazon-recurring'
+ || $this->adapter->getData_Unstaged_Escaped(
'recurring' )
+ ) {
+ $result = $this->adapter->do_transaction(
'DonateMonthly' );
} else {
- if ( $this->getRequest()->getText( 'redirect', 0 ) ) {
- if ( $this->getRequest()->getText( 'ffname',
'default' ) === 'amazon-recurring'
- || $this->getRequest()->getText(
'recurring', 0 )
- ) {
- $this->adapter->do_transaction(
'DonateMonthly' );
- } else {
- $this->adapter->do_transaction(
'Donate' );
- }
- return;
- }
-
- $this->log( 'At gateway return with params: ' .
json_encode( $this->getRequest()->getValues() ), LOG_INFO );
- if ( $this->adapter->checkTokens() &&
$this->getRequest()->getText( 'status' ) ) {
- $this->adapter->do_transaction(
'ProcessAmazonReturn' );
-
- $status = $this->adapter->getFinalStatus();
-
- if ( ( $status == 'complete' ) || ( $status ==
'pending' ) ) {
- $this->getOutput()->redirect(
$this->adapter->getThankYouPage() );
- }
- else {
- $this->getOutput()->redirect(
$this->adapter->getFailPage() );
- }
- } else {
- $specialform = $this->getRequest()->getText(
'ffname', null );
- if ( !is_null( $specialform ) &&
$this->adapter->isValidSpecialForm( $specialform ) ){
- $this->displayForm();
- } else {
- $this->log( 'Failed to process gateway
return. Tokens bad or no status.', LOG_ERR );
- }
- }
+ $result = $this->adapter->do_transaction( 'Donate' );
+ }
+ // TODO: will move into common renderResponse() code.
+ if ( !empty( $result['redirect'] ) ) {
+ $this->getOutput()->redirect( $result['redirect'] );
}
}
}
diff --git a/amazon_gateway/amazon_resultswitcher.body.php
b/amazon_gateway/amazon_resultswitcher.body.php
new file mode 100644
index 0000000..3a1c0f7
--- /dev/null
+++ b/amazon_gateway/amazon_resultswitcher.body.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * Wikimedia Foundation
+ *
+ * LICENSE
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+class AmazonResultSwitcher extends GatewayPage {
+ /**
+ * Constructor - set up the new special page
+ */
+ public function __construct() {
+ $this->adapter = new AmazonAdapter();
+ parent::__construct(); //the next layer up will know who we are.
+ }
+
+ /**
+ * Show the special page
+ *
+ * @todo
+ * - Finish error handling
+ */
+ protected function handleRequest() {
+ $this->getOutput()->allowClickjacking();
+
+ $this->handleResultRequest();
+ }
+
+ protected function processResponse() {
+ if ( $this->adapter->checkTokens() &&
$this->getRequest()->getText( 'status' ) ) {
+ // TODO: move to adapter?
+ $this->adapter->do_transaction( 'ProcessAmazonReturn' );
+
+ $status = $this->adapter->getFinalStatus();
+
+ if ( ( $status == 'complete' ) || ( $status ==
'pending' ) ) {
+ $this->getOutput()->redirect(
$this->adapter->getThankYouPage() );
+ }
+ else {
+ $this->getOutput()->redirect(
$this->adapter->getFailPage() );
+ }
+ } else {
+ $specialform = $this->getRequest()->getText( 'ffname',
null );
+ if ( !is_null( $specialform ) &&
$this->adapter->isValidSpecialForm( $specialform )
+ ) {
+ $this->displayForm();
+ } else {
+ $this->log( 'Failed to process gateway return.
Tokens bad or no status.', LOG_ERR );
+ }
+ }
+ }
+}
diff --git a/tests/Adapter/Amazon/AmazonTest.php
b/tests/Adapter/Amazon/AmazonTest.php
index 92c38f3..3765d63 100644
--- a/tests/Adapter/Amazon/AmazonTest.php
+++ b/tests/Adapter/Amazon/AmazonTest.php
@@ -133,37 +133,29 @@
function testCanadianDollarConversion( $language ) {
$init = $this->getDonorTestData( 'CA' );
unset( $init['order_id'] );
- $init['payment_method'] = 'amazon';
- $init['ffname'] = 'amazon';
$init['language'] = $language;
- $init['redirect'] = 1;
+ $init['currency_code'] = 'CAD';
+ $this->setLanguage( $language );
$donateText = wfMessage(
'donate_interface-donation-description' )->inLanguage( $language )->text();
$rates = CurrencyRates::getCurrencyRates();
$cadRate = $rates['CAD'];
- $expectedAmount = floor( $init['amount'] / $cadRate );
+ $expectedAmount = $init['amount'] / $cadRate;
TestingAmazonAdapter::$fakeGlobals = array(
'FallbackCurrency' => 'USD',
'NotifyOnConvert' => false,
);
- $that = $this; //needed for PHP pre-5.4
- $redirectTest = function( $location ) use ( $expectedAmount,
$donateText, $that ) {
- $actual = array();
- parse_str( $location, $actual );
- $that->assertTrue( is_numeric( $actual['amount'] ) );
- $difference = abs( floatval( $actual['amount'] ) -
$expectedAmount );
- $that->assertTrue( $difference <= 1 );
- $that->assertEquals( $donateText,
$actual['description'] );
- };
+ $gateway = $this->getFreshGatewayObject( $init );
+ $ret = $gateway->do_transaction( 'Donate' );
- $assertNodes = array(
- 'headers' => array(
- 'Location' => $redirectTest,
- )
- );
- $this->verifyFormOutput( 'TestingAmazonGateway', $init,
$assertNodes, false );
+ $actual = array();
+ parse_str( $ret['redirect'], $actual );
+ $this->assertTrue( is_numeric( $actual['amount'] ) );
+ $difference = abs( floatval( $actual['amount'] ) -
$expectedAmount );
+ $this->assertTrue( $difference <= 0.01 );
+ $this->assertEquals( $donateText, $actual['description'] );
}
/**
diff --git a/worldpay_gateway/worldpay_gateway.body.php
b/worldpay_gateway/worldpay_gateway.body.php
index 2b6e149..4f5e5b3 100644
--- a/worldpay_gateway/worldpay_gateway.body.php
+++ b/worldpay_gateway/worldpay_gateway.body.php
@@ -39,28 +39,16 @@
protected function handleRequest() {
$this->getOutput()->addModules(
'ext.donationinterface.worldpay.styles' ); //loads early
$this->getOutput()->addModules(
'ext.donationinterface.worldpay.code' ); //loads at normal time
- $this->setHeaders();
- // dispatch forms/handling
- if ( $this->adapter->checkTokens() ) {
- $ott = $this->getRequest()->getText( 'OTT' );
- if ( $ott ) {
- $this->adapter->do_transaction(
'QueryAuthorizeDeposit' );
- if ( $this->adapter->getFinalStatus() ===
'failed' ) {
- $this->getOutput()->redirect(
$this->adapter->getFailPage() );
- } else {
- $this->getOutput()->redirect(
$this->adapter->getThankYouPage() );
- }
+ $this->handleDonationRequest();
+ }
- } else {
- // Show either the initial form or an error form
- $this->adapter->session_addDonorData();
- $this->displayForm();
- }
- } else { //token mismatch
- $error['general']['token-mismatch'] = $this->msg(
'donate_interface-token-mismatch' )->text();
- $this->adapter->addManualError( $error );
- $this->displayForm();
+ protected function processPayment() {
+ $this->adapter->do_transaction( 'QueryAuthorizeDeposit' );
+ if ( $this->adapter->getFinalStatus() === 'failed' ) {
+ $this->getOutput()->redirect(
$this->adapter->getFailPage() );
+ } else {
+ $this->getOutput()->redirect(
$this->adapter->getThankYouPage() );
}
}
}
--
To view, visit https://gerrit.wikimedia.org/r/189139
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iea2b71ee4745fff7ab9e0d3fcccc5cfe4588380d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits