Ejegg has submitted this change and it was merged.
Change subject: Store refund mismatch converted to USD
......................................................................
Store refund mismatch converted to USD
Bug: T127979
Change-Id: I98d02745acbc19a5b0e51a63cbf81f8edad605c2
---
M sites/all/modules/wmf_civicrm/tests/phpunit/RefundTest.php
M sites/all/modules/wmf_civicrm/wmf_civicrm.module
2 files changed, 50 insertions(+), 3 deletions(-)
Approvals:
Ejegg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/sites/all/modules/wmf_civicrm/tests/phpunit/RefundTest.php
b/sites/all/modules/wmf_civicrm/tests/phpunit/RefundTest.php
index e62cdd5..d03486e 100644
--- a/sites/all/modules/wmf_civicrm/tests/phpunit/RefundTest.php
+++ b/sites/all/modules/wmf_civicrm/tests/phpunit/RefundTest.php
@@ -17,10 +17,11 @@
parent::setUp();
civicrm_initialize();
- $results = civicrm_api3( 'contact', 'create', array(
+ $results = $this->callAPISuccess( 'contact', 'create', array(
'contact_type' => 'Individual',
'first_name' => 'Test',
'last_name' => 'Es',
+ 'debug' => 1,
) );
$this->contact_id = $results['id'];
@@ -29,6 +30,8 @@
$this->gateway_txn_id = mt_rand();
$time = time();
$this->trxn_id = "TEST_GATEWAY {$this->gateway_txn_id} {$time}";
+
+ $this->setExchangeRates( $time, array( 'USD' => 1, 'EUR' => 0.5 ) );
$results = civicrm_api3( 'contribution', 'create', array(
'contact_id' => $this->contact_id,
@@ -213,4 +216,43 @@
$this->original_currency, $this->original_amount + 100.00
);
}
+
+ /**
+ * Make a lesser refund in the wrong currency
+ */
+ public function testLesserWrongCurrencyRefund() {
+ $strtime = '04/03/2000';
+ $dbtime = '2000-04-03';
+ $epochtime = wmf_common_date_parse_string( $dbtime );
+ $this->setExchangeRates( $epochtime, array('COP' => .01 ) );
+
+ $result = $this->callAPISuccess('contribution', 'create', array(
+ 'contact_id' => $this->contact_id,
+ 'financial_type_id' => 'Cash',
+ 'total_amount' => 200,
+ 'contribution_source' => 'COP 20000',
+ 'trxn_id' => "TEST_GATEWAY {$this->gateway_txn_id} " . (time() + 20),
+ ));
+
+ wmf_civicrm_mark_refund(
+ $result['id'],
+ 'refund',
+ TRUE,
+ $dbtime,
+ NULL,
+ 'COP',
+ 5000
+ );
+
+ $contributions = $this->callAPISuccess('Contribution', 'get', array(
+ 'contact_id' => $this->contact_id,
+ 'sequential' => TRUE
+ ));
+ $this->assertEquals(3, $contributions['count'], print_r($contributions,
TRUE));
+ $this->assertEquals(200, $contributions['values'][1]['total_amount']);
+ $this->assertEquals('USD', $contributions['values'][2]['currency']);
+ // Exchange rates might move a bit but hopefully it stays less than the
original amount.
+ $this->assertEquals($contributions['values'][2]['total_amount'], 150);
+ }
+
}
diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index 291f74e..6d684dc 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
@@ -1879,14 +1879,19 @@
try {
civicrm_api3('Contribution', 'create', array(
- 'total_amount' => -$amount_scammed,
+ 'total_amount' => round(
+ exchange_rate_convert(
+ $refund_currency,
+ -$amount_scammed,
+ wmf_common_date_parse_string(date('Y-m-d h:i:s',
$refund_date)
+ )), 2),
// New type?
'financial_type_id' => 'Refund',
'contact_id' => $contribution['contact_id'],
'contribution_source' => $refund_currency . " " .
$amount_scammed,
'trxn_id' => $refund_unique_id,
'receive_date' => date('Y-m-d h:i:s', $refund_date),
- 'currency' => $refund_currency,
+ 'currency' => 'USD',
'debug' => 1,
wmf_civicrm_get_custom_field_name('parent_contribution_id') =>
$contribution_id,
wmf_civicrm_get_custom_field_name('no_thank_you') => 1,
--
To view, visit https://gerrit.wikimedia.org/r/277947
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I98d02745acbc19a5b0e51a63cbf81f8edad605c2
Gerrit-PatchSet: 6
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Eileen <[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