Ejegg has submitted this change and it was merged.

Change subject: Use unforked DonationInterface for recurring GC
......................................................................


Use unforked DonationInterface for recurring GC

Change-Id: I188d507817a7b59d1dbe42db673c2bb0e7205e9c
---
M sites/all/modules/recurring_globalcollect/recurring_globalcollect.module
M sites/all/modules/wmf_civicrm/DonationInterface.php
2 files changed, 43 insertions(+), 36 deletions(-)

Approvals:
  Ejegg: Looks good to me, approved



diff --git 
a/sites/all/modules/recurring_globalcollect/recurring_globalcollect.module 
b/sites/all/modules/recurring_globalcollect/recurring_globalcollect.module
index a78d6ab..34d6a87 100644
--- a/sites/all/modules/recurring_globalcollect/recurring_globalcollect.module
+++ b/sites/all/modules/recurring_globalcollect/recurring_globalcollect.module
@@ -83,20 +83,6 @@
     '#description' => t( 'The url to the local server to test the connection. 
This should point to your CiviCRM host.' ),
   );
   
-  // Get the path of the file to make sure it is installed.
-  $standalone_globalcollect_adapter_path = 
variable_get('standalone_globalcollect_adapter_path', null);
-
-  // Flag to tell the user to install the library
-  $standalone_globalcollect_adapter_installed = is_dir( 
$standalone_globalcollect_adapter_path ) ? '<span 
style="color:green;">Installed</span>' : '<span style="color:red;">Please 
install</span>';
-
-  $form['standalone_globalcollect_adapter_path'] = array(
-    '#type' => 'textfield',
-    '#title' => t('StandaloneGlobalCollectAdapter Path'),
-    '#required' => TRUE,
-    '#default_value' => $standalone_globalcollect_adapter_path,
-    '#description' => t($standalone_globalcollect_adapter_installed . ' Link: 
') . l(t('Current version of payment_library'), 
"https://svn.wikimedia.org/viewvc/wikimedia/trunk/fundraising-misc/payment_library/";),
-  );
-
   $form['recurring_globalcollect_merchant_id'] = array(
     '#type' => 'textfield',
     '#title' => t('Global Collect Merchant ID'),
@@ -320,11 +306,16 @@
       'order_id' => $transaction->gateway_txn_id,
       'currency_code' => $subscription->currency,
       'payment_product' => '',
+      'language' => 'en',
+      // We just need to avoid some ContributionTracking MediaWiki extension 
code,
+      // it's possible to look the actual ID, but it should not be necessary.
+      'contribution_tracking_id' => '123456',
+      // Avoiding some more code.
+      'referrer' => 'dummy',
   );
-  $instance = DonationInterface::getAdapter( 'GlobalCollect' );
-  $instance->load_request_data( $values );
-  $result = $instance->do_transaction('Recurring_Charge');
-  
+  $adapter = DonationInterface::createAdapter( 'GlobalCollect', $values );
+  $result = $adapter->do_transaction('Recurring_Charge');
+
   // If success, add a record to the contribution table and send a thank you 
email.
   if ($result['status'] && empty($result['errors'])) {
     // Mark this donation as successful, and reschedule it for next month
diff --git a/sites/all/modules/wmf_civicrm/DonationInterface.php 
b/sites/all/modules/wmf_civicrm/DonationInterface.php
index 48e35cf..9fa57d2 100644
--- a/sites/all/modules/wmf_civicrm/DonationInterface.php
+++ b/sites/all/modules/wmf_civicrm/DonationInterface.php
@@ -1,30 +1,46 @@
 <?php
 
 class DonationInterface {
-    static public function getAdapter( $type, $options = array() ) {
-        // TODO: Doesn't DI have this already:
-        // switch ( $type ) {
-        // case 'GlobalCollect':
-        // default:
-        //     throw new WmfException( 'CIVI_CONFIG', 'Unknown gateway adapter 
requested: ' . $type );
-
+    static public function createAdapter( $type, $data ) {
         // Configure DonationInterface according to Drupal settings.
-        // TODO: make variable names less crazy
-        $adapterOptions = array();
+        $adapterOptions = array(
+            'batch_mode' => true,
+            'external_data' => $data,
 
-        global $wgGlobalCollectGatewayMerchantID;
+            // Avoid Title code in GlobalCollectAdapter::setGatewayDefaults().
+            'returnTitle' => 'dummy',
+            // Unnecessary avoidance of wfAppendQuery call in stage_returnto,
+            // which should never be hit anyway cos returnto is not in these 
APIs.
+            'returnTo' => 'dumber',
+        );
+
+        // Yeah, I know... this is a consequence of not running the main
+        // initializations in the extension's DonationInterface.php.  We
+        // could clean it up by moving initialization to a function which
+        // is safe to call from Drupal.
+        global $wgDonationInterfaceForbiddenCountries,
+            $wgDonationInterfacePriceFloor,
+            $wgDonationInterfacePriceCeiling,
+            $wgGlobalCollectGatewayAccountInfo,
+            $wgGlobalCollectGatewayURL,
+            $wgGlobalCollectGatewayMerchantID;
+
+        // Adapt Drupal configuration into MediaWiki globals.
         $wgGlobalCollectGatewayMerchantID = 
variable_get('recurring_globalcollect_merchant_id', 0);
 
-        global $wgGlobalCollectGatewayURL;
+        $wgGlobalCollectGatewayAccountInfo['default'] = array(
+            'MerchantID' => $wgGlobalCollectGatewayMerchantID,
+        );
+
         $wgGlobalCollectGatewayURL = variable_get( 'globalcollect_url', '' );
 
-        $standalone_globalcollect_adapter_path = 
variable_get('standalone_globalcollect_adapter_path', null);
-        $path = implode( DIRECTORY_SEPARATOR, array(
-            $standalone_globalcollect_adapter_path,
-            'globalcollect.adapter.php'
-        ) );
-        require_once $path;
+        $wgDonationInterfaceForbiddenCountries = array();
 
-        return new GlobalCollectAdapter( $options );
+        $wgDonationInterfacePriceFloor = 1.00;
+        $wgDonationInterfacePriceCeiling = 10000.00;
+
+        $className = "{$type}Adapter";
+        $adapter = new $className( $adapterOptions );
+        return $adapter;
     }
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I188d507817a7b59d1dbe42db673c2bb0e7205e9c
Gerrit-PatchSet: 7
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: Katie Horn <[email protected]>
Gerrit-Reviewer: Ssmith <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to