Eileen has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/329642 )

Change subject: Add support for importing campaign source, medium for CoinBase.
......................................................................

Add support for importing campaign source, medium for CoinBase.

Bug: T153791
Change-Id: I74bf90ab001044e8b29ae87d2d4855bf9d934ac7
---
M sites/all/modules/offline2civicrm/CoinbaseFile.php
M sites/all/modules/offline2civicrm/tests/CoinBaseTest.php
R sites/all/modules/offline2civicrm/tests/ContributionConversionTest.php
M sites/all/modules/offline2civicrm/tests/data/coinbase.csv
M sites/all/modules/wmf_civicrm/wmf_civicrm.module
5 files changed, 17 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/42/329642/1

diff --git a/sites/all/modules/offline2civicrm/CoinbaseFile.php 
b/sites/all/modules/offline2civicrm/CoinbaseFile.php
index 2bfe8c6..1f604f4 100644
--- a/sites/all/modules/offline2civicrm/CoinbaseFile.php
+++ b/sites/all/modules/offline2civicrm/CoinbaseFile.php
@@ -12,7 +12,6 @@
         return array(
             'BTC Price',
             'Currency',
-            //'Custom',
             'Customer Email',
             'Native Price',
             'Phone Number',
@@ -41,6 +40,9 @@
         $msg['gateway'] = 'coinbase';
         $msg['contribution_type'] = 'cash';
         $msg['payment_instrument'] = 'Bitcoin';
+        // It seems that payment_method is used for creating the 
contribution_tracking source
+        // whereas payment_instrument is used for CiviCRM contributions 
payment_instrument_id field.
+        $msg['payment_method'] = 'bitcoin';
 
         list($msg['first_name'], $msg['last_name']) = 
wmf_civicrm_janky_split_name( $msg['full_name'] );
 
@@ -71,10 +73,12 @@
 
     protected function getFieldMapping() {
         return array(
+            'Banner' => 'utm_source',
+            'Campaign' => 'utm_campaign',
             //'BTC Price' => 'original_gross',
             'Currency' => 'currency',
-            //'Custom' => 'contribution_tracking', // TODO
             'Customer Email' => 'email',
+            'Medium' => 'utm_medium',
             // FIXME: this will destroy recurring subscription import, for now.
             'Native Price' => 'gross',
             'Phone Number' => 'phone', // TODO: not stored
diff --git a/sites/all/modules/offline2civicrm/tests/CoinBaseTest.php 
b/sites/all/modules/offline2civicrm/tests/CoinBaseTest.php
index 91e1744..e7f9f78 100644
--- a/sites/all/modules/offline2civicrm/tests/CoinBaseTest.php
+++ b/sites/all/modules/offline2civicrm/tests/CoinBaseTest.php
@@ -24,8 +24,9 @@
         $importer->import();
 
         $contribution = 
wmf_civicrm_get_contributions_from_gateway_id($this->gateway, $this->trxn_id);
-        $this->assertEquals( 1, count( $contribution ) );
-        $this->assertEquals( 'COINBASE PLUTO', $contribution[0]['trxn_id'] );
+        $this->assertEquals(1, count($contribution));
+        $this->assertEquals('COINBASE PLUTO', $contribution[0]['trxn_id']);
+        $this->assertEquals('online', db_query("SELECT {utm_medium} from 
{contribution_tracking} WHERE contribution_id = 
{$contribution[0]['id']}")->fetchField());
     }
 
 }
diff --git 
a/sites/all/modules/offline2civicrm/tests/ContributionConversion.test 
b/sites/all/modules/offline2civicrm/tests/ContributionConversionTest.php
similarity index 100%
rename from sites/all/modules/offline2civicrm/tests/ContributionConversion.test
rename to sites/all/modules/offline2civicrm/tests/ContributionConversionTest.php
diff --git a/sites/all/modules/offline2civicrm/tests/data/coinbase.csv 
b/sites/all/modules/offline2civicrm/tests/data/coinbase.csv
index b336848..d0c8678 100644
--- a/sites/all/modules/offline2civicrm/tests/data/coinbase.csv
+++ b/sites/all/modules/offline2civicrm/tests/data/coinbase.csv
@@ -1,2 +1,2 @@
-BTC Price,Currency,Customer Email,Native Price,Phone Number,Recurring Payment 
ID,Refund Transaction ID,Shipping Address 1,Shipping Address 2,Shipping 
City,Shipping Country,Shipping Name,Shipping Postal Code,Shipping 
State,Status,Timestamp,Tracking Code
-5.0009,BTC,mic...@mouse.com,1,456 789,,,52 Disney Lane,,Disneyland,US,Mickey 
Mouse,,,,2016-09-15,Pluto
+BTC Price,Currency,Customer Email,Native Price,Phone Number,Recurring Payment 
ID,Refund Transaction ID,Shipping Address 1,Shipping Address 2,Shipping 
City,Shipping Country,Shipping Name,Shipping Postal Code,Shipping 
State,Status,Timestamp,Tracking Code,Campaign,Medium,Banner
+5.0009,BTC,mic...@mouse.com,1,456 789,,,52 Disney Lane,,Disneyland,US,Mickey 
Mouse,,,,2016-09-15,Pluto,Planet drive,online,mouse-drive
diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module 
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index a3e8b65..c7ea3bc 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
@@ -1755,9 +1755,13 @@
 
     // if we're missing a contrib id, insert new record to the table
     // this can happen if a user somehow makes a trxn from outside the normal 
workflow
-    // checks are ignored as they were completely offline
+    // Historically checks have been  ignored as they are completely offline.
+    // T146295 has raised some questions about this.
+    // code change respects previous recognition of 'payment_method' as being 
a little bit magic,
+    // but also assumes that if you are setting utm_medium or utm_source in 
your import you intend them to be recorded.
     if ( !isset( $msg[ 'contribution_tracking_id' ] ) ) {
-        if ( array_key_exists( 'payment_method', $msg ) && strtoupper( 
$msg['payment_method'] ) != "CHECK" ) {
+        if (!empty($msg['utm_medium'] || !empty($msg['utm_source']))
+          || array_key_exists( 'payment_method', $msg ) && strtoupper( 
$msg['payment_method'] ) != "CHECK" ) {
 
             watchdog( 'wmf_civicrm', 'Contribution missing 
contribution_tracking_id', array(), WATCHDOG_DEBUG );
             //@fixme: For the regular transactions, this has been moved to the 
staging function. This needs to happen in recurring also, and then it can be 
removed here.

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I74bf90ab001044e8b29ae87d2d4855bf9d934ac7
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Eileen <emcnaugh...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to