Eileen has submitted this change and it was merged.

Change subject: Don't error on bad contribution source
......................................................................


Don't error on bad contribution source

Make it possible to add event payments, which automatically populate
the contribution source field with the event name.

Change-Id: I1fa30ec5a5a16aef0fd563f4cc7b3ac6e40237bd
---
M sites/all/modules/wmf_civicrm/wmf_civicrm.module
1 file changed, 19 insertions(+), 5 deletions(-)

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



diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module 
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index c61af39..3ca0d1d 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
@@ -2054,8 +2054,13 @@
 
                if ( $contribution->source ) {
                        list( $original_currency, $original_amount ) = explode( 
" ", $contribution->source );
-                       $extra['original_currency'] = $original_currency;
-                       $extra['original_amount'] = $original_amount;
+                       if ( is_numeric( $original_amount ) && 
wmf_civicrm_is_valid_currency( $original_currency ) ) {
+                               $extra['original_currency'] = 
$original_currency;
+                               $extra['original_amount'] = $original_amount;
+                       } else {
+                               $extra['original_currency'] = 'USD';
+                               $extra['original_amount'] = 
$contribution->total_amount;
+                       }
                }
 
                if ( $extra ) {
@@ -2224,9 +2229,7 @@
         $source = $fields['source'];
         if ( preg_match( '/^([a-z]{3}) [0-9]+(\.[0-9]+)?$/i', $source, 
$matches ) ) {
             $currency = strtoupper( $matches[1] );
-            // TODO: stick a get_currency_codes function someplace
-            $all_currencies = array_keys( CurrencyRates::getCurrencyRates() );
-            if ( !in_array( $currency, $all_currencies ) ) {
+            if ( !wmf_civicrm_is_valid_currency( $currency ) ) {
                 $errors['source'] = t( 'Please set a supported currency code' 
);
             }
         } else {
@@ -2487,3 +2490,14 @@
   ");
 
 }
+
+/**
+ * Determine if a code represents a supported currency. Uses the
+ * DonationInterface currency list as a canonical source.
+ * @param string $currency should be an ISO 4217 code
+ * @return bool true if it's a real currency that we can handle
+ */
+function wmf_civicrm_is_valid_currency( $currency ) {
+       $all_currencies = array_keys( CurrencyRates::getCurrencyRates() );
+       return in_array( $currency, $all_currencies );
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1fa30ec5a5a16aef0fd563f4cc7b3ac6e40237bd
Gerrit-PatchSet: 3
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Eileen <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to