Awight has uploaded a new change for review.

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

Change subject: Finish encapsulating Ingenico staging logic
......................................................................

Finish encapsulating Ingenico staging logic

Change-Id: Ibcc31c1c550a64899e4d7c9bd10a2d638fb80286
---
M DonationInterface.php
A globalcollect_gateway/IngenicoFinancialNumber.php
A globalcollect_gateway/IngenicoMethodCodec.php
A globalcollect_gateway/IngenicoReturntoHelper.php
M globalcollect_gateway/globalcollect.adapter.php
M tests/DonationInterfaceTestCase.php
6 files changed, 266 insertions(+), 286 deletions(-)


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

diff --git a/DonationInterface.php b/DonationInterface.php
index e429406..1b57331 100644
--- a/DonationInterface.php
+++ b/DonationInterface.php
@@ -86,7 +86,10 @@
 $wgAutoloadClasses['GlobalCollectAdapter'] = __DIR__ . 
'/globalcollect_gateway/globalcollect.adapter.php';
 $wgAutoloadClasses['GlobalCollectOrphanAdapter'] = __DIR__ . 
'/globalcollect_gateway/orphan.adapter.php';
 $wgAutoloadClasses['GlobalCollectOrphanRectifier'] = __DIR__ . 
'/globalcollect_gateway/GlobalCollectOrphanRectifier.php';
+$wgAutoloadClasses['IngenicoFinancialNumber'] = __DIR__ . 
'/globalcollect_gateway/IngenicoFinancialNumber.php';
 $wgAutoloadClasses['IngenicoLanguage'] = __DIR__ . 
'/globalcollect_gateway/IngenicoLanguage.php';
+$wgAutoloadClasses['IngenicoMethodCodec'] = __DIR__ . 
'/globalcollect_gateway/IngenicoMethodCodec.php';
+$wgAutoloadClasses['IngenicoReturntoHelper'] = __DIR__ . 
'/globalcollect_gateway/IngenicoReturntoHelper.php';
 
 // Amazon
 $wgAutoloadClasses['AmazonGateway'] = __DIR__ . 
'/amazon_gateway/amazon_gateway.body.php';
diff --git a/globalcollect_gateway/IngenicoFinancialNumber.php 
b/globalcollect_gateway/IngenicoFinancialNumber.php
new file mode 100644
index 0000000..1ea7efe
--- /dev/null
+++ b/globalcollect_gateway/IngenicoFinancialNumber.php
@@ -0,0 +1,27 @@
+<?php
+
+class IngenicoFinancialNumber implements StagingHelper {
+       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
+               // Pad some fields with zeros, to their maximum length.
+               $fields = array(
+                       'account_number',
+                       'bank_code',
+                       'branch_code',
+               );
+
+               foreach ( $fields as $field ) {
+                       if ( isset( $unstagedData[$field] ) ) {
+                               $constraints = $adapter->getDataConstraints( 
$field );
+                               if ( isset( $constraints['length'] ) ) {
+                                       $newval = 
DataValidator::getZeroPaddedValue( $unstagedData[$field], 
$constraints['length'] );
+                                       if ( $newval !== false ) {
+                                               $stagedData[$field] = $newval;
+                                       } else {
+                                               // Invalid value, so blank the 
field.
+                                               $stagedData[$field] = '';
+                                       }
+                               }
+                       }
+               }
+       }
+}
diff --git a/globalcollect_gateway/IngenicoMethodCodec.php 
b/globalcollect_gateway/IngenicoMethodCodec.php
new file mode 100644
index 0000000..97c8b6a
--- /dev/null
+++ b/globalcollect_gateway/IngenicoMethodCodec.php
@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * Convert our payment methods into Ingencio codes.
+ */
+class IngenicoMethodCodec implements StagingHelper {
+       /**
+        * Stage: payment_product and a few minor tweaks
+        * Stages the payment product ID for GC.
+        * Not what I had in mind to begin with, but this *completely* blew up.
+        */
+       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
+               $logger = DonationLoggerFactory::getLogger( $adapter );
+
+               // FIXME: too much variable management
+               if ( empty( $unstagedData['payment_method'] ) ) {
+                       $stagedData['payment_method'] = '';
+                       $stagedData['payment_submethod'] = '';
+                       return;
+               }
+               $payment_method = $unstagedData['payment_method'];
+               $payment_submethod = $unstagedData['payment_submethod'];
+
+               // We might support a variation of the submethod for this 
country.
+               //TODO: Having to front-load the country in the payment 
submethod is pretty lame.
+               //If we don't have one deliberately set...
+               if ( !$payment_submethod ) {
+                       $trythis = $payment_method . '_' . strtolower( 
$unstagedData['country'] );
+                       if ( array_key_exists( $trythis, 
$adapter->getPaymentSubmethods() ) ){
+                               $payment_submethod = $trythis;
+                               $stagedData['payment_submethod'] = 
$payment_submethod;
+                       }
+               }
+
+               // Lookup the payment product ID.
+               if ( $payment_submethod ) {
+                       try {
+                               $submethod_data = 
$adapter->getPaymentSubmethodMeta( $payment_submethod );
+                               if ( isset( $submethod_data['paymentproductid'] 
) ) {
+                                       $stagedData['payment_product'] = 
$submethod_data['paymentproductid'];
+                               }
+                       }
+                       catch ( OutOfBoundsException $ex ) {
+                               // Already logged.  We don't have the heart to 
abort here.
+                       }
+               } else {
+                       $logger->debug( "payment_submethod found to be empty. 
Probably okay though." );
+               }
+
+               switch ( $payment_method ) {
+               case 'dd':
+                       $stagedData['date_collect'] = gmdate('Ymd');
+                       $stagedData['direct_debit_text'] = 'Wikimedia 
Foundation';
+                       break;
+               case 'ew':
+                       $stagedData['descriptor'] = 'Wikimedia 
Foundation/Wikipedia';
+                       break;
+               }
+
+               // Tweak transaction type
+               switch ( $payment_submethod ) {
+               case 'dd_nl':
+                       $stagedData['transaction_type'] = '01';
+                       break;
+               case 'dd_gb':
+                       $stagedData['transaction_type'] = '01';
+                       break;
+               }
+       }
+}
diff --git a/globalcollect_gateway/IngenicoReturntoHelper.php 
b/globalcollect_gateway/IngenicoReturntoHelper.php
new file mode 100644
index 0000000..da9e538
--- /dev/null
+++ b/globalcollect_gateway/IngenicoReturntoHelper.php
@@ -0,0 +1,30 @@
+<?php
+
+class IngenicoReturntoHelper implements StagingHelper {
+       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
+               if ( !empty( $unstagedData['returnto'] ) ) {
+                       $returnto = $unstagedData['returnto'];
+               } else {
+                       $returnto = '';
+               }
+
+               if ( isset( $unstagedData['payment_method'] )
+                       && $unstagedData['payment_method'] === 'cc'
+               ) {
+                       // Add order ID to the returnto URL, only if it's not 
already there.
+                       //TODO: This needs to be more robust (like actually 
pulling the
+                       //qstring keys, resetting the values, and putting it 
all back)
+                       //but for now it'll keep us alive.
+                       if ( $adapter->getOrderIDMeta( 'generate' )
+                               && !empty( $returnto )
+                               && !strpos( $returnto, 'order_id' )
+                       ) {
+                               $queryArray = array( 'order_id' => 
$unstagedData['order_id'] );
+                               $stagedData['returnto'] = wfAppendQuery( 
$returnto, $queryArray );
+                       }
+               } else {
+                       // FIXME: An empty returnto should be handled by the 
result switcher instead.
+                       $stagedData['returnto'] = ResultPages::getThankYouPage( 
$adapter );
+               }
+       }
+}
diff --git a/globalcollect_gateway/globalcollect.adapter.php 
b/globalcollect_gateway/globalcollect.adapter.php
index c7b4d63..5ec9646 100644
--- a/globalcollect_gateway/globalcollect.adapter.php
+++ b/globalcollect_gateway/globalcollect.adapter.php
@@ -2293,8 +2293,60 @@
                $this->data_transformers = array_merge( 
parent::getCoreDataTransformers(), array(
                        new BrazilianFiscalNumber(),
                        new ContributionTrackingPlusUnique(),
+                       new IngenicoFinancialNumber(),
                        new IngenicoLanguage(),
+                       new IngenicoMethodCodec(),
+                       new IngenicoReturntoHelper(),
                ) );
+       }
+
+       public function stageData() {
+               // Must run first because staging relies on constraints.
+               $this->tuneConstraints();
+
+               parent::stageData();
+
+               // FIXME: Move to a more specific point in the workflow, in the 
related do_transaction handler.
+               $this->set3dsFlag();
+
+               // FIXME: Move to a post-staging hook.
+               $this->tuneForMethod();
+               $this->tuneForRecurring();
+               $this->tuneForCountry();
+       }
+
+       protected function set3dsFlag() {
+               // This array contains all the card types that can use 
AUTHENTICATIONINDICATOR
+               $authenticationIndicatorTypes = array (
+                       '1', // visa
+                       '3', // mc
+               );
+
+               $enable3ds = false;
+               $currency = $this->getData_Unstaged_Escaped( 'currency_code' );
+               $country = strtoupper( $this->getData_Unstaged_Escaped( 
'country' ) );
+               if ( isset( $this->staged_data['payment_product'] )
+                 && in_array( $this->staged_data['payment_product'], 
$authenticationIndicatorTypes )
+               ) {
+                       $ThreeDSecureRules = $this->getGlobal( '3DSRules' ); 
//ha
+                       if ( array_key_exists( $currency, $ThreeDSecureRules ) 
) {
+                               if ( !is_array( $ThreeDSecureRules[$currency] ) 
) {
+                                       if ( $ThreeDSecureRules[$currency] === 
$country ) {
+                                               $enable3ds = true;
+                                       }
+                               } else {
+                                       if ( empty( 
$ThreeDSecureRules[$currency] ) || in_array( $country, 
$ThreeDSecureRules[$currency] ) ) {
+                                               $enable3ds = true;
+                                       }
+                               }
+                       }
+               }
+
+               if ( $enable3ds ) {
+                       $this->logger->info( "3dSecure enabled for $currency in 
$country" );
+                       // Do the business--set our flag.
+                       
$this->transactions['INSERT_ORDERWITHPAYMENT']['values']['AUTHENTICATIONINDICATOR']
 = '1';
+               }
        }
 
        /**
@@ -2337,169 +2389,74 @@
        }
 
        /**
-        * Stage: card_num
+        * Set up method-specific constraints
         */
-       protected function stage_card_num() {
-               if ( array_key_exists( 'card_num', $this->unstaged_data ) ) {
-                       $this->staged_data['card_num'] = str_replace( ' ', '', 
$this->unstaged_data['card_num'] );
+       protected function tuneConstraints() {
+
+               // TODO: pull from declarative table
+
+               if ( empty( $this->unstaged_data['payment_method'] ) ) {
+                       return;
+               }
+
+               switch ( $this->unstaged_data['payment_method'] ) {
+
+               /* Bank transfer */
+               case 'bt':
+
+                       // Brazil
+                       if ( $this->unstaged_data['country'] == 'BR' ) {
+                               
$this->dataConstraints['direct_debit_text']['city'] = 50;
+                       }
+
+                       // Korea - Manual does not specify North or South
+                       if ( $this->unstaged_data['country'] == 'KR' ) {
+                               
$this->dataConstraints['direct_debit_text']['city'] = 50;
+                       }
+                       break;
+
+               /* Direct Debit */
+               case 'dd':
+                       $this->dataConstraints['iban']['length'] = 21;
+
+                       switch ( $this->unstaged_data['country'] ) {
+                       case 'DE':
+                               
$this->dataConstraints['account_number']['length'] = 10;
+                               $this->dataConstraints['bank_code']['length'] = 
8;
+                               break;
+                       case 'NL':
+                               
$this->dataConstraints['account_name']['length'] = 30;
+                               
$this->dataConstraints['account_number']['length'] = 10;
+                               
$this->dataConstraints['direct_debit_text']['length'] = 32;
+                               break;
+                       case 'AT':
+                               
$this->dataConstraints['account_name']['length'] = 30;
+                               $this->dataConstraints['bank_code']['length'] = 
5;
+                               
$this->dataConstraints['direct_debit_text']['length'] = 28;
+                               break;
+                       case 'ES':
+                               
$this->dataConstraints['account_name']['length'] = 30;
+                               
$this->dataConstraints['account_number']['length'] = 10;
+                               $this->dataConstraints['bank_code']['length'] = 
4;
+                               $this->dataConstraints['branch_code']['length'] 
= 4;
+                               
$this->dataConstraints['direct_debit_text']['length'] = 40;
+                               break;
+                       case 'FR':
+                               
$this->dataConstraints['direct_debit_text']['length'] = 18;
+                               break;
+                       case 'IT':
+                               
$this->dataConstraints['account_name']['length'] = 30;
+                               
$this->dataConstraints['account_number']['length'] = 12;
+                               
$this->dataConstraints['bank_check_digit']['length'] = 1;
+                               $this->dataConstraints['bank_code']['length'] = 
5;
+                               
$this->dataConstraints['direct_debit_text']['length'] = 32;
+                               break;
+                       }
+                       break;
                }
        }
 
        /**
-        * Stage: payment_product
-        * Stages the payment product ID for GC.
-        * Not what I had in mind to begin with, but this *completely* blew up.
-        */
-       public function stage_payment_product() {
-               //cc used to look in card_type, but that's been an alias for 
payment_submethod for a while. DonationData takes care of it.
-               $payment_method = array_key_exists( 'payment_method', 
$this->staged_data ) ? $this->staged_data['payment_method'] : false;
-               $payment_submethod = array_key_exists( 'payment_submethod', 
$this->staged_data ) ? $this->staged_data['payment_submethod'] : false;
-
-               if ( $payment_method === 'cc' ) {
-                       //basically do what used to be stage_card_type.
-                       $types = array (
-                               'visa' => '1',
-                               'amex' => '2',
-                               'mc' => '3',
-                               'maestro' => '117',
-                               'solo' => '118',
-                               'laser' => '124',
-                               'jcb' => '125',
-                               'discover' => '128',
-                               'cb' => '130',
-                       );
-
-                       if ( (!is_null( $payment_submethod ) ) && 
array_key_exists( $payment_submethod, $types ) ) {
-                               $this->staged_data['payment_product'] = 
$types[$payment_submethod];
-                       } else {
-                               if ( !empty( $payment_submethod ) ) {
-                                       $this->logger->error( "Could not find a 
cc payment product for '$payment_submethod'" );
-                               }
-                       }
-
-                       // This array contains all the card types that can use 
AUTHENTICATIONINDICATOR
-                       $authenticationIndicatorTypes = array (
-                               '1', // visa
-                               '3', // mc
-                       );
-
-                       $enable3ds = false;
-                       $currency = $this->getData_Unstaged_Escaped( 
'currency_code' );
-                       $country = strtoupper( $this->getData_Unstaged_Escaped( 
'country' ) );
-                       if ( isset( $this->staged_data['payment_product'] ) && 
in_array( $this->staged_data['payment_product'], $authenticationIndicatorTypes 
) ) {
-                               $ThreeDSecureRules = $this->getGlobal( 
'3DSRules' ); //ha
-                               if ( array_key_exists( $currency, 
$ThreeDSecureRules ) ) {
-                                       if ( !is_array( 
$ThreeDSecureRules[$currency] ) ) {
-                                               if ( 
$ThreeDSecureRules[$currency] === $country ) {
-                                                       $enable3ds = true;
-                                               }
-                                       } else {
-                                               if ( empty( 
$ThreeDSecureRules[$currency] ) || in_array( $country, 
$ThreeDSecureRules[$currency] ) ) {
-                                                       $enable3ds = true;
-                                               }
-                                       }
-                               }
-                       }
-
-                       // FIXME: that's one hell of a staging function.  Move 
this to a do_transaction helper.
-                       if ( $enable3ds ) {
-                               $this->logger->info( "3dSecure enabled for 
$currency in $country" );
-                               
$this->transactions['INSERT_ORDERWITHPAYMENT']['values']['AUTHENTICATIONINDICATOR']
 = '1';
-                       }
-               } else {
-                       if ( !empty( $payment_submethod ) ) {
-                               //everything that isn't cc.
-                               if ( array_key_exists( $payment_submethod, 
$this->payment_submethods ) && isset( 
$this->payment_submethods[$payment_submethod]['paymentproductid'] ) ) {
-                                       $this->staged_data['payment_product'] = 
$this->payment_submethods[$payment_submethod]['paymentproductid'];
-                               } else {
-                                       $this->logger->error( "Could not find a 
payment product for '$payment_submethod' in payment_submethods array" );
-                               }
-                       } else {
-                               $this->logger->debug( "payment_submethod found 
to be empty. Probably okay though." );
-                       }
-               }
-       }
-
-       /**
-        * Stage branch_code for Direct Debit.
-        * Check the data constraints, and zero-pad out to that number where 
possible.
-        * Exceptions for the defaults are set in stage_country so we can see 
them all in the same place
-        */
-       protected function stage_branch_code() {
-               $this->stageAndZeroPad( 'branch_code' );
-       }
-
-       /**
-        * Stage bank_code for Direct Debit.
-        * Check the data constraints, and zero-pad out to that number where 
possible.
-        * Exceptions for the defaults are set in stage_country so we can see 
them all in the same place
-        */
-       protected function stage_bank_code() {
-               $this->stageAndZeroPad( 'bank_code' );
-       }
-
-       /**
-        * Stage account_number for Direct Debit.
-        * Check the data constraints, and zero-pad out to that number where 
possible.
-        * Exceptions for the defaults are set in stage_country so we can see 
them all in the same place
-        */
-       protected function stage_account_number() {
-               $this->stageAndZeroPad( 'account_number' );
-       }
-
-       /**
-        * Helper to stage a zero-padded number
-        */
-       protected function stageAndZeroPad( $key ) {
-               if ( isset( $this->unstaged_data[$key] ) ) {
-                       $newval = DataValidator::getZeroPaddedValue( 
$this->unstaged_data[$key], $this->dataConstraints[$key]['length'] );
-                       if ( $newval ) {
-                               $this->staged_data[$key] = $newval;
-                       }
-               }
-       }
-
-       /**
-        * Stage: setupStagePaymentMethodForDirectDebit
-        *
-        * @param string        $payment_submethod
-        */
-       protected function setupStagePaymentMethodForDirectDebit( 
$payment_submethod ) {
-
-               // DATECOLLECT is required on all Direct Debit
-               $this->addKeyToTransaction('DATECOLLECT');
-
-               $this->staged_data['date_collect'] = gmdate('Ymd');
-               $this->staged_data['direct_debit_text'] = 'Wikimedia 
Foundation';
-
-               $this->var_map['COUNTRYCODEBANK'] = 'country';
-
-               $this->dataConstraints['iban']['length'] = 21;
-
-               // Direct debit has different required fields for each 
paymentproductid.
-               $this->addKeysToTransactionForSubmethod( $payment_submethod );
-       }
-
-       /**
-        * Stage: setupStagePaymentMethodForEWallets
-        *
-        * @param string        $payment_submethod
-        */
-       protected function setupStagePaymentMethodForEWallets( 
$payment_submethod ) {
-
-               // DESCRIPTOR is required on WebMoney, assuming it is required 
for all.
-               $this->addKeyToTransaction('DESCRIPTOR');
-
-               $this->staged_data['descriptor'] = 'Wikimedia 
Foundation/Wikipedia';
-
-               $this->var_map['COUNTRYCODEBANK'] = 'country';
-
-               // eWallets custom keys
-               $this->addKeysToTransactionForSubmethod( $payment_submethod );
-       }
-
-       /**
-        * Stage: payment_method
         *
         * @todo
         * - Need to implement this for credit card if necessary
@@ -2508,101 +2465,19 @@
         * - DATECOLLECT is using gmdate('Ymd')
         * - DIRECTDEBITTEXT will need to be translated. This is what appears 
on the bank statement for donations for a client. This is hardcoded to: 
Wikimedia Foundation
         */
-       protected function stage_payment_method() {
-               $payment_method = array_key_exists( 'payment_method', 
$this->unstaged_data ) ? $this->unstaged_data['payment_method']: false;
-               $payment_submethod = array_key_exists( 'payment_submethod', 
$this->unstaged_data ) ? $this->unstaged_data['payment_submethod']: false;
+       protected function tuneForMethod() {
 
-               //Having to front-load the country in the payment submethod is 
pretty lame.
-               //If we don't have one deliberately set...
-               if (!$payment_submethod){
-                       $trythis = $payment_method . '_' . strtolower( 
$this->getData_Unstaged_Escaped('country') );
-                       if ( array_key_exists( $trythis, 
$this->payment_submethods ) ){
-                               $payment_submethod = $trythis;
-                               $this->staged_data['payment_submethod'] = 
$payment_submethod;
-                       }
-               }
-
-               // These will be grouped and ordered by payment product id
-               switch ( $payment_submethod )  {
-
-                       /* Bank transfer */
-                       case 'bt':
-
-                               // Brazil
-                               if ( $this->unstaged_data['country'] == 'BR' ) {
-                                       
$this->dataConstraints['direct_debit_text']['city'] = 50;
-                               }
-
-                               // Korea - Manual does not specify North or 
South
-                               if ( $this->unstaged_data['country'] == 'KR' ) {
-                                       
$this->dataConstraints['direct_debit_text']['city'] = 50;
-                               }
-                               break;
-
-                       /* Direct Debit */
-                       case 'dd_de':
-                               
$this->dataConstraints['account_number']['length'] = 10;
-                               $this->dataConstraints['bank_code']['length'] = 
8;
-                               break;
-                       case 'dd_nl':
-                               
$this->dataConstraints['account_name']['length'] = 30;
-                               
$this->dataConstraints['account_number']['length'] = 10;
-                               
$this->dataConstraints['direct_debit_text']['length'] = 32;
-                               $this->staged_data['transaction_type'] = '01';
-                               break;
-                       case 'dd_gb':
-                               $this->staged_data['transaction_type'] = '01';
-                               break;
-                       case 'dd_at':
-                               
$this->dataConstraints['account_name']['length'] = 30;
-                               $this->dataConstraints['bank_code']['length'] = 
5;
-                               
$this->dataConstraints['direct_debit_text']['length'] = 28;
-                               break;
-                       case 'dd_es':
-                               
$this->dataConstraints['account_name']['length'] = 30;
-                               
$this->dataConstraints['account_number']['length'] = 10;
-                               $this->dataConstraints['bank_code']['length'] = 
4;
-                               $this->dataConstraints['branch_code']['length'] 
= 4;
-                               
$this->dataConstraints['direct_debit_text']['length'] = 40;
-                               break;
-                       case 'dd_fr':
-                               
$this->dataConstraints['direct_debit_text']['length'] = 18;
-                               break;
-                       case 'dd_it':
-                               
$this->dataConstraints['account_name']['length'] = 30;
-                               
$this->dataConstraints['account_number']['length'] = 12;
-                               
$this->dataConstraints['bank_check_digit']['length'] = 1;
-                               $this->dataConstraints['bank_code']['length'] = 
5;
-                               
$this->dataConstraints['direct_debit_text']['length'] = 32;
-                               break;
-
-                       /* Cash payments */
-                        case 'cash_boleto':
-                               $this->addKeyToTransaction('FISCALNUMBER');
-                               break;
-
-                       case 'rtbt_eps':
-                       case 'rtbt_ideal':
-
-                               $this->addKeysToTransactionForSubmethod( 
$payment_submethod );
-
-                               $this->addKeyToTransaction('ISSUERID');
-                               break;
-
-                       /* Default Case */
-                       default:
-                               // Nothing is done in the default case.
-                               // It's worth noting that at this point, it 
might not be an error.
-                               break;
-               }
-
-               switch ($payment_method) {
+               switch ( $this->getData_Unstaged_Escaped( 'payment_method' ) ) {
                case 'dd':
-                       $this->setupStagePaymentMethodForDirectDebit( 
$payment_submethod );
-                       break;
                case 'ew':
-                       $this->setupStagePaymentMethodForEWallets( 
$payment_submethod );
+                       // TODO: Review.  Why is this set to country_bank_code 
in other cases?
+                       $this->var_map['COUNTRYCODEBANK'] = 'country';
                        break;
+               }
+
+               // Use staged data so we pick up tricksy -_country variants
+               if ( !empty( $this->staged_data['payment_submethod'] ) ) {
+                       $this->addKeysToTransactionForSubmethod( 
$this->staged_data['payment_submethod'] );
                }
        }
 
@@ -2611,7 +2486,7 @@
         * Adds the recurring payment pieces to the structure of
         * INSERT_ORDERWITHPAYMENT if the recurring field is populated.
         */
-       protected function stage_recurring(){
+       protected function tuneForRecurring(){
                if ( !$this->getData_Unstaged_Escaped( 'recurring' ) ) {
                        return;
                } else {
@@ -2625,54 +2500,29 @@
         * This should be a catch-all for establishing weird country-based 
rules.
         * Right now, we only have the one, but there could be more here later.
         */
-       protected function stage_country() {
+       protected function tuneForCountry() {
                switch ( $this->getData_Unstaged_Escaped( 'country' ) ){
-                       case 'AR' :
-                               
$this->transactions['INSERT_ORDERWITHPAYMENT']['request']['REQUEST']['PARAMS']['ORDER'][]
 = 'USAGETYPE';
-                               
$this->transactions['INSERT_ORDERWITHPAYMENT']['request']['REQUEST']['PARAMS']['ORDER'][]
 = 'PURCHASETYPE';
-                               
$this->transactions['INSERT_ORDERWITHPAYMENT']['values']['USAGETYPE'] = '0';
-                               
$this->transactions['INSERT_ORDERWITHPAYMENT']['values']['PURCHASETYPE'] = '1';
-                               break;
+               case 'AR' :
+                       
$this->transactions['INSERT_ORDERWITHPAYMENT']['request']['REQUEST']['PARAMS']['ORDER'][]
 = 'USAGETYPE';
+                       
$this->transactions['INSERT_ORDERWITHPAYMENT']['request']['REQUEST']['PARAMS']['ORDER'][]
 = 'PURCHASETYPE';
+                       
$this->transactions['INSERT_ORDERWITHPAYMENT']['values']['USAGETYPE'] = '0';
+                       
$this->transactions['INSERT_ORDERWITHPAYMENT']['values']['PURCHASETYPE'] = '1';
+                       break;
                }
        }
 
        /**
         * Add keys to transaction for submethod
-        *
         */
        protected function addKeysToTransactionForSubmethod( $payment_submethod 
) {
 
                // If there are no keys to add, do not proceed.
-               if ( !is_array( $this->payment_submethods[ $payment_submethod 
]['keys'] ) ) {
-
+               if ( empty( 
$this->payment_submethods[$payment_submethod]['keys'] ) ) {
                        return;
                }
 
-               foreach ( $this->payment_submethods[ $payment_submethod 
]['keys'] as $key ) {
-
+               foreach ( $this->payment_submethods[$payment_submethod]['keys'] 
as $key ) {
                        $this->addKeyToTransaction( $key );
-               }
-       }
-
-       /**
-        * Stage: returnto
-        */
-       protected function stage_returnto() {
-               // Get the default returnto
-               $returnto = $this->getData_Unstaged_Escaped( 'returnto' );
-
-               if ( $this->getData_Unstaged_Escaped( 'payment_method' ) === 
'cc' ) {
-                       // Add order ID to the returnto URL, only if it's not 
already there.
-                       //TODO: This needs to be more robust (like actually 
pulling the
-                       //qstring keys, resetting the values, and putting it 
all back)
-                       //but for now it'll keep us alive.
-                       if ( $this->getOrderIDMeta( 'generate' ) && !is_null( 
$returnto ) && !strpos( $returnto, 'order_id' ) ) {
-                               $queryArray = array( 'order_id' => 
$this->unstaged_data['order_id'] );
-                               $this->staged_data['returnto'] = wfAppendQuery( 
$returnto, $queryArray );
-                       }
-               } else {
-                       // FIXME: Do we want to set this here?
-                       $this->staged_data['returnto'] = 
ResultPages::getThankYouPage( $this );
                }
        }
 
diff --git a/tests/DonationInterfaceTestCase.php 
b/tests/DonationInterfaceTestCase.php
index 6752c22..df2c9e3 100644
--- a/tests/DonationInterfaceTestCase.php
+++ b/tests/DonationInterfaceTestCase.php
@@ -133,7 +133,7 @@
 
                $this->setUpRequest( $options );
                $expected = $this->getExpectedXmlRequestForGlobalCollect( 
$optionsForTestData, $options );
-               
+
                $this->assertEquals( $expected, $request, 'The constructed XML 
for payment_method [' . $optionsForTestData['payment_method'] . '] and 
payment_submethod [' . $optionsForTestData['payment_submethod'] . '] does not 
match our expected request.' );
        }
 
@@ -395,12 +395,12 @@
                // If we're doing Direct Debit...
                //@TODO: go ahead and split this out into a "Get the direct 
debit I_OWP XML block function" the second this gets even slightly annoying.
                if ( $optionsForTestData['payment_method'] === 'dd' ) {
-                       $expected .= '<DATECOLLECT>' . gmdate( 'Ymd' ) . 
'</DATECOLLECT>'; //is this cheating? Probably.
                        $expected .= '<ACCOUNTNAME>' . 
$optionsForTestData['account_name'] . '</ACCOUNTNAME>';
                        $expected .= '<ACCOUNTNUMBER>' . 
$optionsForTestData['account_number'] . '</ACCOUNTNUMBER>';
                        $expected .= '<BANKCODE>' . 
$optionsForTestData['bank_code'] . '</BANKCODE>';
                        $expected .= '<BRANCHCODE>' . 
$optionsForTestData['branch_code'] . '</BRANCHCODE>';
                        $expected .= '<BANKCHECKDIGIT>' . 
$optionsForTestData['bank_check_digit'] . '</BANKCHECKDIGIT>';
+                       $expected .= '<DATECOLLECT>' . gmdate( 'Ymd' ) . 
'</DATECOLLECT>'; //is this cheating? Probably.
                        $expected .= '<DIRECTDEBITTEXT>' . 
$optionsForTestData['direct_debit_text'] . '</DIRECTDEBITTEXT>';
                }
 

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

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

Reply via email to