Awight has uploaded a new change for review.

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

Change subject: WIP Playing with payment method, trying to understand how to 
fix the two-level method hierarchy.
......................................................................

WIP Playing with payment method, trying to understand how to fix the two-level 
method hierarchy.

Change-Id: Iaa9044e898b4135decdeaeb961924c6a9473c778
---
M gateway_common/PaymentMethod.php
M gateway_common/gateway.adapter.php
M gateway_forms/Mustache.php
R gateway_forms/mustache/choose_issuer.html.mustache
M gateway_forms/mustache/payment_method.html.mustache
5 files changed, 48 insertions(+), 32 deletions(-)


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

diff --git a/gateway_common/PaymentMethod.php b/gateway_common/PaymentMethod.php
index feaf44d..ae0ffbb 100644
--- a/gateway_common/PaymentMethod.php
+++ b/gateway_common/PaymentMethod.php
@@ -52,13 +52,12 @@
                $method->is_recurring = $is_recurring;
 
                try {
-                       // FIXME: I don't like that we're couple to the gateway 
already.
                        $spec = array();
                        if ( $method_name ) {
                                $spec = $gateway->getPaymentMethodMeta( 
$method_name );
                        }
                        // When we have a more specific method, child metadata 
supercedes
-                       // parent metadata
+                       // parent metadata.  Submethod is not required.
                        if ( $submethod_name ) {
                                $spec = array_replace_recursive(
                                        $spec,
@@ -67,7 +66,7 @@
                        }
                        $method->spec = $spec;
                } catch ( Exception $ex ) {
-                       // Return empty method.
+                       // Return empty method.  FIXME: Throw exception instead.
                        $method->name = "none";
                        $method->spec = array();
                }
@@ -164,4 +163,32 @@
                }
                return $source;
        }
+
+       /**
+        * @return array Hash from submethod id to PaymentMethod for each
+        * submethod, which are part of this method's family and would be
+        * supported by the adapter for the current country.
+        *
+        * TODO: Generalize beyond "sub"method.
+        */
+       public function getSubmethods() {
+               $available_submethods = array();
+               foreach( $this->gateway->getSubmethods() as $key => $submethod 
) {
+                       $group = $submethod['group'];
+                       if ( $this->name !== $group ) {
+                               continue; // skip anything not part of the 
selected method
+                       }
+
+                       $country = $this->gateway->getData_Unstaged_Escaped( 
'country' );
+                       if ( isset( $submethod['countries'] )
+                               // if the list exists, the current country key 
needs to exist and have a true value
+                               && empty( $submethod['countries'][$country] )
+                       ) {
+                               continue; // skip 'em if they're not allowed 
round here
+                       }
+                       $available_submethods[$key] = self::newFromCompoundName(
+                               $this->gateway, $this->name, $submethod, 
$this->is_recurring );
+               }
+               return $available_submethods;
+       }
 }
diff --git a/gateway_common/gateway.adapter.php 
b/gateway_common/gateway.adapter.php
index 86f230f..b9981f8 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -3599,29 +3599,15 @@
         * in LocalSettings.  Idea: same metadata array structure as used in
         * definePaymentMethods, overrides cascade from
         * methodMeta -> submethodMeta -> settingsMethodMeta -> 
settingsSubmethodMeta
-        * @return array with available submethods
-        *      'visa' => array( 'label' => 'Visa' )
+        *
+        * @return array map from submethod id to PaymentMethod
         */
        function getAvailableSubmethods() {
-               $method = $this->getPaymentMethod();
-
-               $submethods = array();
-               foreach( $this->payment_submethods as $key => 
$available_submethod ) {
-                       $group = $available_submethod['group'];
-                       if ( $method !== $group ) {
-                               continue; // skip anything not part of the 
selected method
-                       }
-                       if (
-                               $this->unstaged_data // need data for country 
filter
-                               && isset( $available_submethod['countries'] )
-                               // if the list exists, the current country key 
needs to exist and have a true value
-                               && empty( 
$available_submethod['countries'][$this->getData_Unstaged_Escaped( 'country' )] 
)
-                       ) {
-                               continue; // skip 'em if they're not allowed 
round here
-                       }
-                       $submethods[$key] = $available_submethod;
-               }
-               return $submethods;
+               $method = PaymentMethod::newFromCompoundName( $this,
+                       $this->getPaymentMethod(), $this->getPaymentSubmethod(),
+                       $this->getData_Unstaged_Escaped( 'recurring' )
+               );
+               return $method->getSubmethods();
        }
 
        /**
diff --git a/gateway_forms/Mustache.php b/gateway_forms/Mustache.php
index d3855e8..9b7ca59 100644
--- a/gateway_forms/Mustache.php
+++ b/gateway_forms/Mustache.php
@@ -89,19 +89,22 @@
                $data['appeal_text'] = $output->parse( '{{' . 
$appealWikiTemplate . '}}' );
 
                $availableSubmethods = $this->gateway->getAvailableSubmethods();
+               // FIXME: Provide an override or better, have the gateway 
determine
+               // sibling methods and submethods per method.
                $data['show_submethods'] = ( count( $availableSubmethods ) > 1 
);
                if ( $data['show_submethods'] ) {
                        // Need to add submethod key to its array 'cause 
mustache doesn't get keys
                        $data['submethods'] = array();
                        foreach ( $availableSubmethods as $key => $submethod ) {
-                               $submethod['key'] = $key;
-                               if ( isset( $submethod['logo'] ) ) {
-                                       $submethod['logo'] = 
"{$data['script_path']}/extensions/DonationInterface/gateway_forms/includes/{$submethod['logo']}";
+                               $spec = $submethod->getMethodMeta();
+                               $spec['key'] = $key;
+                               if ( isset( $spec['logo'] ) ) {
+                                       $spec['logo'] = 
"{$data['script_path']}/extensions/DonationInterface/gateway_forms/includes/{$spec['logo']}";
                                }
-                               if ( isset( $submethod['sub_text_key'] ) ) {
-                                       $submethod['has_sub_text'] = true;
+                               if ( isset( $spec['sub_text_key'] ) ) {
+                                       $spec['has_sub_text'] = true;
                                }
-                               $data['submethods'][] = $submethod;
+                               $data['submethods'][] = $spec;
                        }
 
                        $data['button_class'] = count( $data['submethods'] ) % 
4 === 0
diff --git a/gateway_forms/mustache/ideal_issuers.html.mustache 
b/gateway_forms/mustache/choose_issuer.html.mustache
similarity index 88%
rename from gateway_forms/mustache/ideal_issuers.html.mustache
rename to gateway_forms/mustache/choose_issuer.html.mustache
index cf1fe5b..3aad199 100644
--- a/gateway_forms/mustache/ideal_issuers.html.mustache
+++ b/gateway_forms/mustache/choose_issuer.html.mustache
@@ -1,4 +1,5 @@
 <select style="margin-top: 15px;" id="issuer_id" name="issuer_id" value="{{ 
issuer }}">
+{{! TODO: list of hashes or of method names? in two groups or artificial 
separator? }}
        <option value="">{{ l10n "donate_interface-rtbt-issuer_id" 
}}...</option>
        <optgroup>
                <option value="31">ABN AMRO</option>
diff --git a/gateway_forms/mustache/payment_method.html.mustache 
b/gateway_forms/mustache/payment_method.html.mustache
index d001497..95d7c4d 100644
--- a/gateway_forms/mustache/payment_method.html.mustache
+++ b/gateway_forms/mustache/payment_method.html.mustache
@@ -23,8 +23,7 @@
                                                                        </dd>
                                                                </dl>
 {{# issuer_required }}
-{{! FIXME: support any type of issuer }}
-{{> ideal_issuers }}
+{{> choose_issuer }}
 {{/ issuer_required }}
                                                                <div 
id="paymentContinue" {{^ show_submethods }}class="force"{{/ show_submethods }}> 
<input class="btn enabled" id="paymentContinueBtn" type="button" value="{{ l10n 
"donate_interface-continue" }}" /></div>
                                                                <div 
id="paymentSubmit" > <input class="btn enabled" id="paymentSubmitBtn" 
type="button" value="{{ l10n "donate_interface-submit-button" }}" /></div>

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

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