Awight has submitted this change and it was merged.

Change subject: (FR #1819) Updated Coinbase report format
......................................................................


(FR #1819) Updated Coinbase report format

Handles subscriptions and refunds.

Change-Id: I117624bc6b3b4b7c406d618592fbf337d77a6d24
---
M sites/all/modules/offline2civicrm/ChecksFile.php
M sites/all/modules/offline2civicrm/CoinbaseFile.php
M sites/all/modules/offline2civicrm/offline2civicrm.module
M sites/all/modules/offline2civicrm/upload_form.js
4 files changed, 65 insertions(+), 31 deletions(-)

Approvals:
  Ejegg: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/sites/all/modules/offline2civicrm/ChecksFile.php 
b/sites/all/modules/offline2civicrm/ChecksFile.php
index 8034a71..a4a110e 100644
--- a/sites/all/modules/offline2civicrm/ChecksFile.php
+++ b/sites/all/modules/offline2civicrm/ChecksFile.php
@@ -45,7 +45,7 @@
 
         $num_successful = 0;
         $num_duplicates = 0;
-        $this->row_index = -1;
+        $this->row_index = -1 + $this->numSkippedRows;
 
         while( ( $row = fgetcsv( $file, 0, ',', '"', '\\')) !== FALSE) {
             $this->row_index++;
@@ -60,6 +60,26 @@
 
             try {
                 $msg = $this->parseRow( $data );
+
+                // check to see if we have already processed this check
+                if ( $existing = 
wmf_civicrm_get_contributions_from_gateway_id( $msg['gateway'], 
$msg['gateway_txn_id'] ) ){
+                    // if so, move on
+                    watchdog( 'offline2civicrm', 'Contribution matches 
existing contribution (id: @id), skipping it.', array( '@id' => 
$existing[0]['id'] ), WATCHDOG_INFO );
+                    $num_duplicates++;
+                    continue;
+                }
+
+                // tha business.
+                $contribution = wmf_civicrm_contribution_message_import( $msg 
);
+                $this->mungeContribution( $contribution );
+
+                watchdog( 'offline2civicrm',
+                    'Import checks: Contribution imported successfully (@id): 
!msg', array(
+                        '@id' => $contribution['id'],
+                        '!msg' => print_r( $msg, true ),
+                    ), WATCHDOG_INFO
+                );
+                $num_successful++;
             } catch ( EmptyRowException $ex ) {
                 continue;
             } catch ( WmfException $ex ) {
@@ -67,25 +87,6 @@
                 $errorMsg = "Import aborted due to error at row {$rowNum}: 
{$ex->getMessage()}, after {$num_successful} records were stored successfully 
and {$num_duplicates} duplicates encountered.";
                 throw new Exception($errorMsg);
             }
-
-            // check to see if we have already processed this check
-            if ( $existing = wmf_civicrm_get_contributions_from_gateway_id( 
$msg['gateway'], $msg['gateway_txn_id'] ) ){
-                // if so, move on
-                watchdog( 'offline2civicrm', 'Contribution matches existing 
contribution (id: @id), skipping it.', array( '@id' => $existing[0]['id'] ), 
WATCHDOG_INFO );
-                $num_duplicates++;
-                continue;
-            }
-
-            // tha business.
-            $contribution = wmf_civicrm_contribution_message_import( $msg );
-
-            watchdog( 'offline2civicrm',
-                'Import checks: Contribution imported successfully (@id): 
!msg', array(
-                    '@id' => $contribution['id'],
-                    '!msg' => print_r( $msg, true ),
-                ), WATCHDOG_INFO
-            );
-            $num_successful++;
         }
 
         $message = t( "Checks import complete. @successful imported, not 
including @duplicates duplicates.", array( '@successful' => $num_successful, 
'@duplicates' => $num_duplicates ) );
@@ -222,6 +223,16 @@
         ) );
     }
 
+    /**
+     * Do fancy stuff with the contribution we just created
+     *
+     * FIXME: We need to wrap each loop iteration in a transaction to
+     * make this safe.  Otherwise we can easily die before adding the
+     * second message, and skip it when resuming the import.
+     */
+    protected function mungeContribution( $contribution ) {
+    }
+
     protected function getDefaultValues() {
         return array(
             'contact_source' => 'check',
diff --git a/sites/all/modules/offline2civicrm/CoinbaseFile.php 
b/sites/all/modules/offline2civicrm/CoinbaseFile.php
index 0d35560..30c78f5 100644
--- a/sites/all/modules/offline2civicrm/CoinbaseFile.php
+++ b/sites/all/modules/offline2civicrm/CoinbaseFile.php
@@ -6,7 +6,8 @@
  * See https://coinbase.com/reports
  */
 class CoinbaseFile extends ChecksFile {
-    protected $numSkippedRows = 3;
+    protected $numSkippedRows = 2;
+    protected $refundLastTransaction = false;
 
     protected function getRequiredColumns() {
         return array(
@@ -16,6 +17,8 @@
             'Customer Email',
             'Native Price',
             'Phone Number',
+            'Recurring Payment ID',
+            'Refund Transaction ID',
             'Shipping Address 1',
             'Shipping Address 2',
             'Shipping City',
@@ -35,8 +38,6 @@
             'gross',
             'currency',
             'gateway_txn_id',
-            'original_currency',
-            'original_gross',
         );
     }
 
@@ -45,13 +46,30 @@
         $msg['contribution_type'] = 'cash';
         $msg['payment_instrument'] = 'Bitcoin';
 
-        $msg['original_currency'] = 'BTC';
-        $msg['original_gross'] = rtrim( number_format( floatval( 
$msg['original_gross'] ), 10 ), '0' );
-
         $msg['first_name'] = $msg['full_name'];
 
-        if ( $msg['gross'] < 0 ) {
-            $msg['contribution_type'] = 'refund';
+        if ( !empty( $msg['gateway_refund_id'] ) ) {
+            $this->refundLastTransaction = true;
+            unset( $msg['gateway_refund_id'] );
+        }
+
+        if ( !empty( $msg['subscr_id'] ) ) {
+            $msg['recurring'] = true;
+        }
+    }
+
+    protected function mungeContribution( $contribution ) {
+        if ( $this->refundLastTransaction ) {
+            wmf_civicrm_mark_refund(
+                $contribution['id'],
+                'refund',
+                true
+            );
+            watchdog( 'offline2civicrm', 'Refunding contribution @id', array(
+                '@id' => $contribution['id'],
+            ), WATCHDOG_INFO );
+
+            $this->refundLastTransaction = false;
         }
     }
 
@@ -64,14 +82,17 @@
             'date' => 'Timestamp',
             'email' => 'Customer Email',
             'full_name' => 'Shipping Name',
-            //'gateway_status_raw' => 'Status', // TODO
+            'gateway_status_raw' => 'Status',
             'gateway_txn_id' => 'Tracking Code',
+            'gateway_refund_id' => 'Refund Transaction ID',
             'gross' => 'Native Price',
-            'original_gross' => 'BTC Price',
+            // FIXME: this will destroy recurring subscription import, for now.
+            //'original_gross' => 'BTC Price',
             'phone' => 'Phone Number', // TODO: not stored
             'postal_code' => 'Shipping Postal Code',
             'state_province' => 'Shipping State',
             'street_address' => 'Shipping Address 1',
+            'subscr_id' => 'Recurring Payment ID',
             'supplemental_address_1' => 'Shipping Address 2',
         );
     }
diff --git a/sites/all/modules/offline2civicrm/offline2civicrm.module 
b/sites/all/modules/offline2civicrm/offline2civicrm.module
index 6ed0442..d8d02fa 100644
--- a/sites/all/modules/offline2civicrm/offline2civicrm.module
+++ b/sites/all/modules/offline2civicrm/offline2civicrm.module
@@ -169,6 +169,8 @@
  * If the contribution was a check, it adds the check to a "Review" group for 
manual review
  * by the Development/Major Gifts team.
  *
+ * FIXME: kill this.
+ *
  * Implementation of hook_queue2civicrm_import
  *
  * @param $contribution_info
diff --git a/sites/all/modules/offline2civicrm/upload_form.js 
b/sites/all/modules/offline2civicrm/upload_form.js
index 92b995a..54a2e10 100644
--- a/sites/all/modules/offline2civicrm/upload_form.js
+++ b/sites/all/modules/offline2civicrm/upload_form.js
@@ -11,7 +11,7 @@
             if ( uploadFile ) {
                 $submitButton.removeAttr( "disabled" );
 
-                if ( /Coinbase|Orders-Report/.test( uploadFile ) ) {
+                if ( /Coinbase|Orders-Report|\(Orders\)/.test( uploadFile ) ) {
                     fileType = "coinbase";
                 } else if ( /JPMorgan/.test( uploadFile ) ) {
                     fileType = "jpmorgan";

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I117624bc6b3b4b7c406d618592fbf337d77a6d24
Gerrit-PatchSet: 5
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: Mwalker <[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