jenkins-bot has submitted this change and it was merged.

Change subject: Log completed donations
......................................................................


Log completed donations

This is to debug an active issue where the queue message body is missing, so we
circumvent the possibly buggy getStompTransaction.

Bug: T140515
Change-Id: Iab065e0d70184040e47260d6d54334daa5db88ca
---
M README.txt
M extension.json
M gateway_common/gateway.adapter.php
A tests/LoggingTest.php
A tests/includes/Responses/globalcollect/DO_FINISHPAYMENT_200.testresponse
M tests/includes/Responses/globalcollect/GET_ORDERSTATUS.testresponse
A tests/includes/Responses/globalcollect/GET_ORDERSTATUS_200.testresponse
A tests/includes/Responses/globalcollect/SET_PAYMENT.testresponse
A tests/includes/Responses/globalcollect/SET_PAYMENT_200.testresponse
9 files changed, 263 insertions(+), 2 deletions(-)

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



diff --git a/README.txt b/README.txt
index 8f33d8f..9ff6972 100644
--- a/README.txt
+++ b/README.txt
@@ -132,6 +132,10 @@
 
 $wgDonationInterfaceCurlVerboseLog = false
 
+As donations are sent to the "completed" queue, also log the json blob.
+
+$wgDonationInterfaceLogCompleted = false
+
 ==== Currency and amounts ====
 
 Configure price ceiling and floor for valid contribution amount.  Values
diff --git a/extension.json b/extension.json
index e150795..3ea22ba 100644
--- a/extension.json
+++ b/extension.json
@@ -399,6 +399,7 @@
                "DonationInterfaceUseSyslog": false,
                "DonationInterfaceSaveCommStats": false,
                "DonationInterfaceCurlVerboseLog": false,
+               "DonationInterfaceLogCompleted": false,
                "DonationInterfaceTimeout": 5,
                "DonationInterfaceFallbackCurrency": false,
                "DonationInterfaceFallbackCurrencyByCountry": false,
diff --git a/gateway_common/gateway.adapter.php 
b/gateway_common/gateway.adapter.php
index 044f530..dd991e5 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -31,6 +31,12 @@
 abstract class GatewayAdapter implements GatewayType, LogPrefixProvider {
 
        /**
+        * Don't change these strings without fixing cross-repo usages.
+        */
+       const REDIRECT_PREFACE = 'Redirecting for transaction: ';
+       const COMPLETED_PREFACE = 'Completed donation: ';
+
+       /**
         * config tree
         */
        protected $config = array();
@@ -1708,6 +1714,7 @@
                        case FinalStatus::COMPLETE:
                                // This transaction completed successfully.  
Send to the CRM
                                // for filing.
+                               $this->logCompletedPayment();
                                $this->pushMessage( 'complete' );
                                break;
 
@@ -3718,7 +3725,17 @@
 
        protected function logPaymentDetails() {
                $details = $this->getStompTransaction();
-               $this->logger->info( 'Redirecting for transaction: ' . 
json_encode( $details ) );
+               $this->logger->info( self::REDIRECT_PREFACE . json_encode( 
$details ) );
+       }
+
+       protected function logCompletedPayment() {
+               if ( $this->getGlobal( 'LogCompleted' ) ) {
+                       // FIXME: We probably want to dial this down to log the 
same fields
+                       // as getStompTransaction, but I'm currently debugging 
that
+                       // function, so dump it all:
+                       $dump = json_encode( $this->getData_Unstaged_Escaped() 
);
+                       $this->logger->info( self::COMPLETED_PREFACE . $dump );
+               }
        }
 
        protected function runApiCallHooks() {
diff --git a/tests/LoggingTest.php b/tests/LoggingTest.php
new file mode 100644
index 0000000..2ff51be
--- /dev/null
+++ b/tests/LoggingTest.php
@@ -0,0 +1,106 @@
+<?php
+/**
+ * Wikimedia Foundation
+ *
+ * LICENSE
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+use Psr\Log\LogLevel;
+
+/**
+ *
+ * @group Fundraising
+ * @group DonationInterface
+ */
+class DonationInterface_LoggingTest extends DonationInterfaceTestCase {
+       public function setUp() {
+               parent::setUp();
+
+               $this->setMwGlobals( array(
+                       'wgDonationInterfaceLogCompleted' => true,
+               ) );
+       }
+
+       /**
+        * @param $name string The name of the test case
+        * @param $data array Any parameters read from a dataProvider
+        * @param $dataName string|int The name or index of the data set
+        */
+       function __construct( $name = null, array $data = array(), $dataName = 
'' ) {
+               parent::__construct( $name, $data, $dataName );
+               $this->testAdapterClass = 'TestingGlobalCollectAdapter';
+       }
+
+       /**
+        * Check that we can log completed transactions
+        */
+       public function testLogCompleted() {
+               $init = $this->getDonorTestData();
+               $init['payment_method'] = 'cc';
+               $init['payment_submethod'] = 'visa';
+               $init['email'] = 'innoc...@manichean.com';
+               $init['ffname'] = 'cc-vmad';
+               $init['unusual_key'] = mt_rand();
+               unset( $init['order_id'] );
+
+               $expectedObject = array(
+                       'amount' => 23.45,
+                       'appeal' => 'JimmyQuote',
+                       'attempt_id' => '2',
+                       'avs_result' => 'M',
+                       'city' => 'San Francisco',
+                       //'contribution_tracking_id' => '1',
+                       'country' => 'US',
+                       'currency_code' => 'EUR',
+                       'cvv_result' => 'P',
+                       'effort_id' => '1',
+                       'email' => 'innoc...@manichean.com',
+                       'ffname' => 'cc-vmad',
+                       'fname' => 'Firstname',
+                       'full_name' => 'Firstname Surname',
+                       'gateway' => 'globalcollect',
+                       'language' => 'en',
+                       'lname' => 'Surname',
+                       //'order_id' => 'ORDER_ID',
+                       'payment_method' => 'cc',
+                       'payment_product' => 1,
+                       'payment_submethod' => 'visa',
+                       'recurring' => '',
+                       'referrer' => 'www.yourmom.com',
+                       //'returnto' => 'http 
=>//payments.dev/index.php/Special 
=>GlobalCollectGatewayResult?order_id=ORDER_ID',
+                       'server_ip' => '127.0.0.1',
+                       'state' => 'CA',
+                       'street' => '123 Fake Street',
+                       'unusual_key' => ( string ) $init['unusual_key'],
+                       'user_ip' => '127.0.0.1',
+                       'utm_source' => '..cc',
+                       'zip' => '94105',
+               );
+
+               $gateway = $this->getFreshGatewayObject( $init );
+               $gateway->setDummyGatewayResponseCode( '200' );
+               $gateway->do_transaction( 'Confirm_CreditCard' );
+               $preface_pattern = '/' . preg_quote( 
GatewayAdapter::COMPLETED_PREFACE ) . '/';
+               $matches = $this->getLogMatches( LogLevel::INFO, 
$preface_pattern );
+               $this->assertTrue( $matches !== false,
+                       'Should log a completion message' );
+
+               $json = str_replace( GatewayAdapter::COMPLETED_PREFACE, '', 
$matches[0] );
+               $actualObject = json_decode( $json, true );
+               unset( $actualObject['order_id'] );
+               unset( $actualObject['returnto'] );
+               unset( $actualObject['contribution_tracking_id'] );
+               $this->assertEquals( $expectedObject, $actualObject,
+                       'Completion message is as expected' );
+       }
+}
diff --git 
a/tests/includes/Responses/globalcollect/DO_FINISHPAYMENT_200.testresponse 
b/tests/includes/Responses/globalcollect/DO_FINISHPAYMENT_200.testresponse
new file mode 100644
index 0000000..6efeaf0
--- /dev/null
+++ b/tests/includes/Responses/globalcollect/DO_FINISHPAYMENT_200.testresponse
@@ -0,0 +1,37 @@
+<?xml version = "1.0"?>
+<!-- FIXME: This was made up from the docs, replace with a sanitized wild 
message. -->
+<XML>
+       <REQUEST>
+               <ACTION>DO_FINISHPAYMENT</ACTION>
+               <META>
+                       <MERCHANTID>test</MERCHANTID>
+                       <IPADDRESS>127.0.0.1</IPADDRESS>
+                       <VERSION>1.0</VERSION>
+               </META>
+               <PARAMS>
+                       <PAYMENT>
+                               <ORDERID>626113410</ORDERID>
+                               <EFFORTID>1</EFFORTID>
+                               <ATTEMPTID>1</ATTEMPTID>
+                       </PAYMENT>
+               </PARAMS>
+               <RESPONSE>
+                       <RESULT>OK</RESULT>
+                       <META>
+                               <REQUESTID>1891851</REQUESTID>
+                               
<RESPONSEDATETIME>20140327165513</RESPONSEDATETIME>
+                       </META>
+                       <ROW>
+                               <AMOUNT>10101</AMOUNT>
+                               <CURRENCYCODE>EUR</CURRENCYCODE>
+                               <STATUSID>800</STATUSID>
+                               <STATUSDATE>20140704021814</STATUSDATE>
+                               <PAYMENTREFERENCE>0</PAYMENTREFERENCE>
+                               <AVSRESULT>Z</AVSRESULT>
+                               <CVVRESULT>M</CVVRESULT>
+                               <FRAUDRESULT>D</FRAUDRESULT>
+                               <FRAUDCODE>0</FRAUDCODE>
+                       </ROW>
+               </RESPONSE>
+       </REQUEST>
+</XML>
diff --git 
a/tests/includes/Responses/globalcollect/GET_ORDERSTATUS.testresponse 
b/tests/includes/Responses/globalcollect/GET_ORDERSTATUS.testresponse
index 1cc717d..889a621 100644
--- a/tests/includes/Responses/globalcollect/GET_ORDERSTATUS.testresponse
+++ b/tests/includes/Responses/globalcollect/GET_ORDERSTATUS.testresponse
@@ -20,7 +20,7 @@
                        </META>
                        <STATUS>
                                <PAYMENTMETHODID>1</PAYMENTMETHODID>
-                               <STATUSID>800</STATUSID>
+                               <STATUSID>600</STATUSID>
                                <CURRENCYCODE>EUR</CURRENCYCODE>
                                <FRAUDRESULT>N</FRAUDRESULT>
                                <EFFORTID>1</EFFORTID>
diff --git 
a/tests/includes/Responses/globalcollect/GET_ORDERSTATUS_200.testresponse 
b/tests/includes/Responses/globalcollect/GET_ORDERSTATUS_200.testresponse
new file mode 100644
index 0000000..c3eb4f7
--- /dev/null
+++ b/tests/includes/Responses/globalcollect/GET_ORDERSTATUS_200.testresponse
@@ -0,0 +1,42 @@
+<XML>
+       <REQUEST>
+               <ACTION>GET_ORDERSTATUS</ACTION>
+               <META>
+                       <MERCHANTID>1</MERCHANTID>
+                       <IPADDRESS>123.123.123.123</IPADDRESS>
+                       <VERSION>2.0</VERSION>
+                       <REQUESTIPADDRESS>123.123.123.123</REQUESTIPADDRESS>
+               </META>
+               <PARAMS>
+                       <ORDER>
+                               <ORDERID>9998890004</ORDERID>
+                       </ORDER>
+               </PARAMS>
+               <RESPONSE>
+                       <RESULT>OK</RESULT>
+                       <META>
+                               <REQUESTID>245</REQUESTID>
+                               
<RESPONSEDATETIME>20100419133351</RESPONSEDATETIME>
+                       </META>
+                       <STATUS>
+                               <PAYMENTMETHODID>1</PAYMENTMETHODID>
+                               <STATUSID>200</STATUSID>
+                               <CURRENCYCODE>EUR</CURRENCYCODE>
+                               <FRAUDRESULT>N</FRAUDRESULT>
+                               <EFFORTID>1</EFFORTID>
+                               
<CREDITCARDNUMBER>************7977</CREDITCARDNUMBER>
+                               <AUTHORISATIONCODE>654321</AUTHORISATIONCODE>
+                               
<PAYMENTREFERENCE>900100000010</PAYMENTREFERENCE>
+                               <ATTEMPTID>2</ATTEMPTID>
+                               <MERCHANTID>1</MERCHANTID>
+                               <AMOUNT>2345</AMOUNT>
+                               <STATUSDATE>20100419132926</STATUSDATE>
+                               <PAYMENTPRODUCTID>1</PAYMENTPRODUCTID>
+                               <CVVRESULT>P</CVVRESULT>
+                               <AVSRESULT>M</AVSRESULT>
+                               <ORDERID>9998890004</ORDERID>
+                               <EXPIRYDATE>1210</EXPIRYDATE>
+                       </STATUS>
+               </RESPONSE>
+       </REQUEST>
+</XML>
diff --git a/tests/includes/Responses/globalcollect/SET_PAYMENT.testresponse 
b/tests/includes/Responses/globalcollect/SET_PAYMENT.testresponse
new file mode 100644
index 0000000..382acfb
--- /dev/null
+++ b/tests/includes/Responses/globalcollect/SET_PAYMENT.testresponse
@@ -0,0 +1,26 @@
+<?xml version = "1.0"?>
+<XML>
+       <REQUEST>
+               <ACTION>SET_PAYMENT</ACTION>
+               <META>
+                       <MERCHANTID>test</MERCHANTID>
+                       <IPADDRESS>127.0.0.1</IPADDRESS>
+                       <VERSION>1.0</VERSION>
+                       <REQUESTIPADDRESS>127.0.0.1</REQUESTIPADDRESS>
+               </META>
+               <PARAMS>
+                       <PAYMENT>
+                               <ORDERID>626113410</ORDERID>
+                               <EFFORTID>1</EFFORTID>
+                               <PAYMENTPRODUCTID>1</PAYMENTPRODUCTID>
+                       </PAYMENT>
+               </PARAMS>
+               <RESPONSE>
+                       <RESULT>OK</RESULT>
+                       <META>
+                               <REQUESTID>1891851</REQUESTID>
+                               
<RESPONSEDATETIME>20140327165513</RESPONSEDATETIME>
+                       </META>
+               </RESPONSE>
+       </REQUEST>
+</XML>
diff --git 
a/tests/includes/Responses/globalcollect/SET_PAYMENT_200.testresponse 
b/tests/includes/Responses/globalcollect/SET_PAYMENT_200.testresponse
new file mode 100644
index 0000000..a88c1d1
--- /dev/null
+++ b/tests/includes/Responses/globalcollect/SET_PAYMENT_200.testresponse
@@ -0,0 +1,28 @@
+<?xml version = "1.0"?>
+<XML>
+       <REQUEST>
+               <ACTION>SET_PAYMENT</ACTION>
+               <META>
+                       <MERCHANTID>test</MERCHANTID>
+                       <IPADDRESS>127.0.0.1</IPADDRESS>
+                       <VERSION>1.0</VERSION>
+               </META>
+               <PARAMS>
+                       <PAYMENT>
+                               <ORDERID>626113410</ORDERID>
+                               <EFFORTID>1</EFFORTID>
+                               <PAYMENTPRODUCTID>1</PAYMENTPRODUCTID>
+                               <AMOUNT>10101</AMOUNT>
+                               <CURRENCYCODE>EUR</CURRENCYCODE>
+                               <MERCHANTREFERENCE>626113410</MERCHANTREFERENCE>
+                       </PAYMENT>
+               </PARAMS>
+               <RESPONSE>
+                       <RESULT>OK</RESULT>
+                       <META>
+                               <REQUESTID>1891851</REQUESTID>
+                               
<RESPONSEDATETIME>20140327165513</RESPONSEDATETIME>
+                       </META>
+               </RESPONSE>
+       </REQUEST>
+</XML>

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iab065e0d70184040e47260d6d54334daa5db88ca
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Awight <awi...@wikimedia.org>
Gerrit-Reviewer: AndyRussG <andrew.green...@gmail.com>
Gerrit-Reviewer: Awight <awi...@wikimedia.org>
Gerrit-Reviewer: Cdentinger <cdentin...@wikimedia.org>
Gerrit-Reviewer: Ejegg <eeggles...@wikimedia.org>
Gerrit-Reviewer: Ssmith <ssm...@wikimedia.org>
Gerrit-Reviewer: XenoRyet <dkozlow...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to