Ejegg has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/381490 )
Change subject: Prefer 'invoice_id' to 'order_id' for importing invoice_id
......................................................................
Prefer 'invoice_id' to 'order_id' for importing invoice_id
Bug: T171349
Change-Id: I9e58c6012abb7a3e32b721e0c694d187aa8576c6
---
M sites/all/modules/queue2civicrm/tests/includes/Message.php
M sites/all/modules/queue2civicrm/tests/phpunit/DonationQueueTest.php
M sites/all/modules/wmf_civicrm/wmf_civicrm.module
3 files changed, 62 insertions(+), 9 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm
refs/changes/90/381490/1
diff --git a/sites/all/modules/queue2civicrm/tests/includes/Message.php
b/sites/all/modules/queue2civicrm/tests/includes/Message.php
index cb64acf..98fd90e 100644
--- a/sites/all/modules/queue2civicrm/tests/includes/Message.php
+++ b/sites/all/modules/queue2civicrm/tests/includes/Message.php
@@ -82,11 +82,14 @@
function __construct( $values = array() ) {
$this->loadDefaults( "donation" );
+ $ct_id = mt_rand();
- parent::__construct( array(
+ parent::__construct( $values + array(
$this->txn_id_key => mt_rand(),
'order_id' => mt_rand(),
- ) + $values );
+ 'contribution_tracking_id' => $ct_id,
+ 'invoice_id' => "$ct_id.1",
+ ) );
}
function getGateway() {
diff --git
a/sites/all/modules/queue2civicrm/tests/phpunit/DonationQueueTest.php
b/sites/all/modules/queue2civicrm/tests/phpunit/DonationQueueTest.php
index 6059718..3e6f7ba 100644
--- a/sites/all/modules/queue2civicrm/tests/phpunit/DonationQueueTest.php
+++ b/sites/all/modules/queue2civicrm/tests/phpunit/DonationQueueTest.php
@@ -58,7 +58,7 @@
'financial_type' => 'Cash',
'contribution_status' => 'Completed',
'payment_instrument' => 'Credit Card: Visa',
- 'invoice_id' => $message->get('order_id'),
+ 'invoice_id' => $message->get('invoice_id'),
$campaignField => '',
);
$returnFields = array_keys( $expected );
@@ -98,7 +98,7 @@
'financial_type' => 'Cash',
'contribution_status' => 'Completed',
'payment_instrument' => 'Credit Card: Visa',
- 'invoice_id' => $message2->get('order_id'),
+ 'invoice_id' => $message2->get('invoice_id'),
$campaignField => 'Benefactor Gift',
);
$this->assertArraySubset( $expected, $contribution2 );
@@ -106,6 +106,52 @@
}
/**
+ * Missing Invoice ID should be filled with order ID
+ */
+ public function testDonationNoInvoiceId() {
+ $message = new TransactionMessage(
+ array( 'gross' => 400, 'original_gross' => 400,
'original_currency' => 'USD' )
+ );
+ $message->set( array( 'invoice_id' => null ) );
+ exchange_rate_cache_set( 'USD', $message->get( 'date' ), 1 );
+
+ $this->queueConsumer->processMessage( $message->getBody() );
+
+ $campaignField = wmf_civicrm_get_custom_field_name( 'campaign'
);
+
+ $expected = array(
+ 'contact_type' => 'Individual',
+ 'sort_name' => 'laast, firrst',
+ 'display_name' => 'firrst laast',
+ 'first_name' => 'firrst',
+ 'last_name' => 'laast',
+ 'currency' => 'USD',
+ 'total_amount' => '400.00',
+ 'fee_amount' => '0.00',
+ 'net_amount' => '400.00',
+ 'trxn_id' => 'GLOBALCOLLECT ' .
$message->getGatewayTxnId(),
+ 'contribution_source' => 'USD 400',
+ 'financial_type' => 'Cash',
+ 'contribution_status' => 'Completed',
+ 'payment_instrument' => 'Credit Card: Visa',
+ 'invoice_id' => $message->get( 'order_id' ),
+ $campaignField => '',
+ );
+ $returnFields = array_keys( $expected );
+
+ $contribution = civicrm_api3(
+ 'Contribution',
+ 'getsingle',
+ array(
+ wmf_civicrm_get_custom_field_name(
'gateway_txn_id' ) => $message->getGatewayTxnId(),
+ 'return' => $returnFields
+ )
+ );
+
+ $this->assertArraySubset( $expected, $contribution );
+ }
+
+ /**
* Process an ordinary (one-time) donation message with an UTF campaign.
*/
public function testDonationWithUTFCampaignOption() {
diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index 8888087..a838866 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
@@ -356,11 +356,15 @@
}
// Store the identifier we generated on payments
- if ( !empty( $msg['order_id'] ) ) {
- $contribution['invoice_id'] = $msg['order_id'];
- // The invoice_id column has a unique constraint
- if ( $msg['recurring'] ) {
- $contribution['invoice_id'] .= '|recur-' .
UtcDate::getUtcTimestamp();
+ $invoice_fields = array( 'invoice_id', 'order_id' );
+ foreach ( $invoice_fields as $invoice_field ) {
+ if ( !empty( $msg[$invoice_field] ) ) {
+ $contribution['invoice_id'] = $msg[$invoice_field];
+ // The invoice_id column has a unique constraint
+ if ( $msg['recurring'] ) {
+ $contribution['invoice_id'] .= '|recur-' .
UtcDate::getUtcTimestamp();
+ }
+ break;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/381490
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9e58c6012abb7a3e32b721e0c694d187aa8576c6
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits