Mwalker has submitted this change and it was merged.

Change subject: Allow the Form Chooser to know about Currencies :)
......................................................................


Allow the Form Chooser to know about Currencies :)

The Form Chooser can now add '+' rules if they aren't explicitly
specified that detail all about the currencies an adapter can
accept.

Change-Id: I45dcd60433a2bedcb7157a30d095dbcec08bccda
---
M DonationInterface.php
M special/GatewayFormChooser.php
2 files changed, 21 insertions(+), 4 deletions(-)

Approvals:
  jenkins-bot: Verified



diff --git a/DonationInterface.php b/DonationInterface.php
index 93bfe98..bf05e14 100644
--- a/DonationInterface.php
+++ b/DonationInterface.php
@@ -96,6 +96,8 @@
 /**
  * CLASSES
  */
+$wgDonationInterfaceClassMap = array();
+
 $wgAutoloadClasses['DonationData'] = $donationinterface_dir . 
'gateway_common/DonationData.php';
 $wgAutoloadClasses['GatewayAdapter'] = $donationinterface_dir . 
'gateway_common/gateway.adapter.php';
 $wgAutoloadClasses['GatewayForm'] = $donationinterface_dir . 
'gateway_common/GatewayForm.php';
@@ -109,6 +111,7 @@
 
 //GlobalCollect gateway classes
 if ( $optionalParts['GlobalCollect'] === true ){
+       $wgDonationInterfaceClassMap['globalcollect'] = 'GlobalCollectAdapter';
        $wgAutoloadClasses['GlobalCollectGateway'] = $donationinterface_dir . 
'globalcollect_gateway/globalcollect_gateway.body.php';
        $wgAutoloadClasses['GlobalCollectGatewayResult'] = 
$donationinterface_dir . 
'globalcollect_gateway/globalcollect_resultswitcher.body.php';
 
@@ -121,22 +124,26 @@
 
 //PayflowPro gateway classes
 if ( $optionalParts['PayflowPro'] === true ){
+       $wgDonationInterfaceClassMap['payflopro'] = 'PayflowProAdapter';
        $wgAutoloadClasses['PayflowProGateway'] = $donationinterface_dir . 
'payflowpro_gateway/payflowpro_gateway.body.php';
        $wgAutoloadClasses['PayflowProAdapter'] = $donationinterface_dir . 
'payflowpro_gateway/payflowpro.adapter.php';
 }
 
 if ( $optionalParts['Amazon'] === true ){
+       $wgDonationInterfaceClassMap['amazon'] = 'AmazonAdapter';
        $wgAutoloadClasses['AmazonGateway'] = $donationinterface_dir . 
'amazon_gateway/amazon_gateway.body.php';
        $wgAutoloadClasses['AmazonAdapter'] = $donationinterface_dir . 
'amazon_gateway/amazon.adapter.php';
 }
 
 if ( $optionalParts['Adyen'] === true ){
+       $wgDonationInterfaceClassMap['adyen'] = 'AdyenAdapter';
        $wgAutoloadClasses['AdyenGateway'] = $donationinterface_dir . 
'adyen_gateway/adyen_gateway.body.php';
        $wgAutoloadClasses['AdyenGatewayResult'] = $donationinterface_dir . 
'adyen_gateway/adyen_resultswitcher.body.php';
        $wgAutoloadClasses['AdyenAdapter'] = $donationinterface_dir . 
'adyen_gateway/adyen.adapter.php';
 }
 
 if ( $optionalParts['Paypal'] === true ){
+       $wgDonationInterfaceClassMap['paypal'] = 'PaypalAdapter';
        $wgAutoloadClasses['PaypalGateway'] = $donationinterface_dir . 
'paypal_gateway/paypal_gateway.body.php';
        $wgAutoloadClasses['PaypalGatewayResult'] = $donationinterface_dir . 
'paypal_gateway/paypal_resultswitcher.body.php';
        $wgAutoloadClasses['PaypalAdapter'] = $donationinterface_dir . 
'paypal_gateway/paypal.adapter.php';
diff --git a/special/GatewayFormChooser.php b/special/GatewayFormChooser.php
index 96dbeb1..61db9f3 100644
--- a/special/GatewayFormChooser.php
+++ b/special/GatewayFormChooser.php
@@ -86,7 +86,7 @@
        static function getAllValidForms( $country = null, $currency = null, 
$payment_method = null,
                $payment_submethod = null, $recurring = false, $gateway = null
        ) {
-               global $wgDonationInterfaceAllowedHtmlForms;
+               global $wgDonationInterfaceAllowedHtmlForms, 
$wgDonationInterfaceClassMap;
                $forms = $wgDonationInterfaceAllowedHtmlForms;
                
                // First get all the valid and enabled gateways capable of 
processing shtuff
@@ -101,7 +101,7 @@
                }
 
                // then remove the forms that we don't want.
-               foreach ( $forms as $name => $meta ) {
+               foreach ( $forms as $name => &$meta ) {
                        // Prefilter for sillyness
                        foreach ( array( 'gateway', 'payment_methods' ) as 
$paramName ) {
                                if ( !array_key_exists( $paramName, $meta ) ) {
@@ -115,6 +115,9 @@
                                }
                        }
 
+                       /** @var GatewayAdapter $adapterName */
+                       $adapterName = 
$wgDonationInterfaceClassMap[$meta['gateway']];
+
                        // filter on enabled gateways
                        if ( !DataValidator::value_appears_in( 
$meta['gateway'], $valid_gateways ) ) {
                                unset( $forms[$name] );
@@ -127,8 +130,15 @@
                                continue;
                        }
 
-                       //filter on currency
-                       if ( !is_null( $currency ) && 
!DataValidator::value_appears_in( $currency, $meta['currencies'] ) ) {
+                       // Filter on currency; and if it's too generic we add 
what the adapter thinks it can support
+                       if ( $meta['currencies'] === 'ALL' ) {
+                               $meta['currencies'] = array( '+' => 
$adapterName::getCurrencies() );
+                       } elseif( array_key_exists( '-', $meta['currencies'] ) 
&& !array_key_exists( '+', $meta['currencies'] ) ) {
+                               $meta['currencies']['+'] = 
$adapterName::getCurrencies();
+                       }
+
+                       if ( !is_null( $currency ) && 
!DataValidator::value_appears_in( $currency, $meta['currencies'] )
+                       ) {
                                unset( $forms[$name] );
                                continue;
                        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I45dcd60433a2bedcb7157a30d095dbcec08bccda
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Mwalker <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to