jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/342896 )
Change subject: Detect normalized paypal messages in queue consumer
......................................................................
Detect normalized paypal messages in queue consumer
Once this is deployed, the queue consumer should be able to deal with
both old style raw messages and new style normalized messages. After
the IPN and audit changes are deployed, we should delete the code that
deals with raw messages.
Bug: T107372
Change-Id: Iabb137015452c8b77c75719b242eb2bc89112a5c
---
M sites/all/modules/queue2civicrm/recurring/RecurringQueueConsumer.php
M sites/all/modules/queue2civicrm/tests/includes/Message.php
M sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php
3 files changed, 96 insertions(+), 4 deletions(-)
Approvals:
XenoRyet: Looks good to me, approved
jenkins-bot: Verified
diff --git
a/sites/all/modules/queue2civicrm/recurring/RecurringQueueConsumer.php
b/sites/all/modules/queue2civicrm/recurring/RecurringQueueConsumer.php
index e6ac6df..b37b404 100644
--- a/sites/all/modules/queue2civicrm/recurring/RecurringQueueConsumer.php
+++ b/sites/all/modules/queue2civicrm/recurring/RecurringQueueConsumer.php
@@ -83,8 +83,12 @@
if ( isset( $msg['gateway'] ) && $msg['gateway'] === 'amazon' )
{
// should not require special normalization
} else if ( !isset( $msg[ 'contribution_tracking_id' ]) ) {
- // we can safely assume we have a raw msg from paypal
if contribution_tracking_id isn't set
- $msg = $this->normalizePaypalMessage( $msg );
+ $msg_normalized[ 'contribution_tracking_id' ] =
recurring_get_contribution_tracking_id( $msg );
+ // TODO: remove this after deploying audit and IPN
updates to do message normalization there
+ if ( isset( $msg['payer_email'] ) ) {
+ // This is an old-school non-normalized PayPal
message.
+ $msg = $this->normalizePaypalMessage( $msg );
+ }
} else {
$msg['contribution_tracking_update'] = false;
}
@@ -125,7 +129,6 @@
// the subscription id
$msg_normalized[ 'subscr_id' ] = $msg[ 'subscr_id' ];
$msg_normalized[ 'txn_type' ] = $msg[ 'txn_type' ];
- $msg_normalized[ 'contribution_tracking_id' ] =
recurring_get_contribution_tracking_id( $msg );
$msg_normalized[ 'email' ] = $msg[ 'payer_email' ];
// Premium info
@@ -325,8 +328,14 @@
// update subscription record with next payment date
$api = civicrm_api_classapi();
+ if ( isset( $msg['date'] ) ) {
+ $date = $msg['date'];
+ } else {
+ // TODO: Remove this when audit and IPN are sending
normalized messages
+ $date = $msg[ 'payment_date' ];
+ }
$update_params = array(
- 'next_sched_contribution_date' =>
wmf_common_date_unix_to_civicrm( strtotime( "+" .
$recur_record->frequency_interval . " " . $recur_record->frequency_unit, $msg[
'payment_date' ] )),
+ 'next_sched_contribution_date' =>
wmf_common_date_unix_to_civicrm( strtotime( "+" .
$recur_record->frequency_interval . " " . $recur_record->frequency_unit, $date
)),
'id' => $recur_record->id,
'version' => 3,
diff --git a/sites/all/modules/queue2civicrm/tests/includes/Message.php
b/sites/all/modules/queue2civicrm/tests/includes/Message.php
index a789e21..c1d46dd 100644
--- a/sites/all/modules/queue2civicrm/tests/includes/Message.php
+++ b/sites/all/modules/queue2civicrm/tests/includes/Message.php
@@ -141,6 +141,16 @@
}
}
+class NormalizedSubscriptionPaymentMessage extends TransactionMessage {
+ function __construct( $values = array() ) {
+ $this->loadDefaults( "subscr_payment_normalized" );
+
+ $this->txn_id_key = 'gateway_txn_id';
+
+ parent::__construct( $values );
+ }
+}
+
class RecurringSignupMessage extends TransactionMessage {
function __construct( $values = array() ) {
$this->loadDefaults( "recurring_signup" );
@@ -149,6 +159,14 @@
}
}
+class NormalizedRecurringSignupMessage extends TransactionMessage {
+ function __construct( $values = array() ) {
+ $this->loadDefaults( "subscr_signup_normalized" );
+
+ parent::__construct( $values );
+ }
+}
+
/**
* Class AmazonDonationMessage Sparse message format pointing to donor
* details in the pending database
diff --git
a/sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php
b/sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php
index 8038970..7c1dbd5 100644
--- a/sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php
+++ b/sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php
@@ -315,6 +315,52 @@
->execute();
}
+ public function testNormalizedRecurring() {
+ civicrm_initialize();
+ $subscr_id = mt_rand();
+ $values = $this->processNormalizedRecurringSignup($subscr_id);
+
+ $message = new NormalizedSubscriptionPaymentMessage( $values );
+
+ $payment_time = $message->get( 'date' );
+ exchange_rate_cache_set( 'USD', $payment_time, 1 );
+ exchange_rate_cache_set( $message->get( 'currency' ),
$payment_time, 2 );
+
+ db_insert( 'contribution_tracking' )
+ ->fields( array( 'id' => $message->get(
'contribution_tracking_id' ) ) )
+ ->execute();
+
+ $this->recurringConsumer->processMessage( $message->getBody() );
+
+ $recur_record = wmf_civicrm_get_recur_record( $subscr_id );
+ $this->assertNotEquals( false, $recur_record );
+
+ $contributions = wmf_civicrm_get_contributions_from_gateway_id(
$message->getGateway(), $message->getGatewayTxnId() );
+ $this->assertEquals( 1, count( $contributions ) );
+ $this->assertEquals( $recur_record->id,
$contributions[0]['contribution_recur_id']);
+
+ $addresses = $this->callAPISuccess('Address', 'get',
array('contact_id' => $contributions[0]['contact_id']));
+ $this->assertEquals(1, $addresses['count']);
+
+ $emails = $this->callAPISuccess('Email', 'get',
array('contact_id' => $contributions[0]['contact_id']));
+ $this->assertEquals(1, $addresses['count']);
+ $this->assertEquals('[email protected]',
$emails['values'][$emails['id']]['email']);
+
+ db_delete( 'contribution_tracking' )
+ ->condition('id', $message->get(
'contribution_tracking_id' ) )
+ ->execute();
+ CRM_Core_DAO::executeQuery("
+ DELETE FROM civicrm_contribution
+ WHERE id = %1",
+ array( 1 => array( $contributions[0]['id'], 'Positive'
) )
+ );
+ CRM_Core_DAO::executeQuery("
+ DELETE FROM civicrm_contact
+ WHERE id = %1",
+ array( 1 => array( $contributions[0]['contact_id'],
'Positive' ) )
+ );
+ }
+
/**
* Test that the a blank address is not written to the DB.
*/
@@ -346,6 +392,9 @@
$this->assertEquals(1, $addresses['count']);
// The address created by the sign up (Lockwood Rd) should not have been
overwritten by the blank.
$this->assertEquals('5109 Lockwood Rd',
$addresses['values'][0]['street_address']);
+ db_delete( 'contribution_tracking' )
+ ->condition('id', $messageBody['custom'])
+ ->execute();
}
/**
@@ -509,4 +558,20 @@
$this->recurringConsumer->processMessage($signup_message->getBody());
return $values;
}
+
+ /**
+ * Process the original recurring sign up message.
+ *
+ * @param string $subscr_id
+ * @return array
+ */
+ private function processNormalizedRecurringSignup($subscr_id) {
+ $values = array('subscr_id' => $subscr_id);
+ $signup_message = new NormalizedRecurringSignupMessage($values);
+ $subscr_time = $signup_message->get('date');
+ exchange_rate_cache_set('USD', $subscr_time, 1);
+ exchange_rate_cache_set($signup_message->get('currency'),
$subscr_time, 2);
+
$this->recurringConsumer->processMessage($signup_message->getBody());
+ return $values;
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/342896
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iabb137015452c8b77c75719b242eb2bc89112a5c
Gerrit-PatchSet: 5
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: Ejegg <[email protected]>
Gerrit-Reviewer: XenoRyet <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits