Ejegg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/287135

Change subject: Better validation for donation.api
......................................................................

Better validation for donation.api

This version touches the code as little as possible, but there's
a lot of refactoring needed in that file.

Bug: T134527
Change-Id: I7c29f8d5ed967d82145e32483cadf815e9b318ec
---
M gateway_common/donation.api.php
1 file changed, 35 insertions(+), 14 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/35/287135/1

diff --git a/gateway_common/donation.api.php b/gateway_common/donation.api.php
index 0c330c4..2d4efd3 100644
--- a/gateway_common/donation.api.php
+++ b/gateway_common/donation.api.php
@@ -7,8 +7,6 @@
 class DonationApi extends ApiBase {
        public $donationData, $gateway;
        public function execute() {
-               global $wgDonationInterfaceTestMode;
-
                $this->donationData = $this->extractRequestParams();
 
                $this->gateway = $this->donationData['gateway'];
@@ -17,17 +15,21 @@
                // @todo FIXME: Unused local variable.
                $submethod = $this->donationData['payment_submethod'];
 
-               $gateway_opts = array(
-                       'api_request' => 'true'
-               );
+               $gatewayObj = $this->getGatewayObject();
+
+               if ( !$gatewayObj ) {
+                       return; // already failed with a dieUsage call
+               }
+
+               $gatewayObj->revalidate();
+               if ( !$gatewayObj->validatedOK() ) {
+                       $outputResult['errors'] = $gatewayObj->getAllErrors();
+                       $this->getResult()->setIndexedTagName( 
$outputResult['errors'], 'error' );
+                       $this->getResult()->addValue( null, 'result', 
$outputResult );
+                       return;
+               }
 
                if ( $this->gateway == 'globalcollect' ) {
-                       // FIXME: no test code path in prod
-                       if ( $wgDonationInterfaceTestMode === true ) {
-                               $gatewayObj = new TestingGlobalCollectAdapter( 
$gateway_opts );
-                       } else {
-                               $gatewayObj = new GlobalCollectAdapter( 
$gateway_opts );
-                       }
                        switch ( $method ) {
                                // TODO: add other payment methods
                                case 'cc':
@@ -37,10 +39,7 @@
                                        $result = $gatewayObj->do_transaction( 
'TEST_CONNECTION' );
                        }
                } elseif ( $this->gateway == 'adyen' ) {
-                       $gatewayObj = new AdyenAdapter( $gateway_opts );
                        $result = $gatewayObj->do_transaction( 'donate' );
-               } else {
-                       $this->dieUsage( "Invalid gateway 
<<<{$this->gateway}>>> passed to Donation API.", 'unknown_gateway' );
                }
 
                // $normalizedData = $gatewayObj->getData_Unstaged_Escaped();
@@ -197,4 +196,26 @@
                                => 'apihelp-donate-example-1',
                );
        }
+
+       private function getGatewayObject() {
+               global $wgDonationInterfaceTestMode;
+
+               $gateway_opts = array(
+                       'api_request' => 'true'
+               );
+
+               if ( $this->gateway == 'globalcollect' ) {
+                       // FIXME: no test code path in prod
+                       if ( $wgDonationInterfaceTestMode === true ) {
+                               return new TestingGlobalCollectAdapter( 
$gateway_opts );
+                       } else {
+                               return new GlobalCollectAdapter( $gateway_opts 
);
+                       }
+               } elseif ( $this->gateway == 'adyen' ) {
+                       return new AdyenAdapter( $gateway_opts );
+               } else {
+                       $this->dieUsage( "Invalid gateway 
<<<{$this->gateway}>>> passed to Donation API.", 'unknown_gateway' );
+               }
+               return null;
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/287135
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7c29f8d5ed967d82145e32483cadf815e9b318ec
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

Reply via email to