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

Change subject: Add recurring PayPal test
......................................................................


Add recurring PayPal test

Change-Id: I5b1cb4155928ed801c930cd0bc243c5637e1e7da
---
M PaymentProviders/PayPal/Job.php
M PaymentProviders/PayPal/PayPalPaymentsAPI.php
M PaymentProviders/PayPal/Tests/Data/subscr_payment.json
A PaymentProviders/PayPal/Tests/Data/subscr_signup.json
M PaymentProviders/PayPal/Tests/MockPayPalPaymentsAPI.php
M PaymentProviders/PayPal/Tests/config_test.yaml
M PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php
7 files changed, 128 insertions(+), 64 deletions(-)

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



diff --git a/PaymentProviders/PayPal/Job.php b/PaymentProviders/PayPal/Job.php
index 00cb5cf..43e5abb 100644
--- a/PaymentProviders/PayPal/Job.php
+++ b/PaymentProviders/PayPal/Job.php
@@ -44,7 +44,7 @@
                // FIXME this could just be an array, but we need compat with
                // keyedopaque* until activemq goes away
                $new_msg = new Message;
-               // FIXME hack because the recurring consumer doesn't want
+               // FIXME hacks because the recurring consumer doesn't want
                // a normalized message
                if ( $msg_type === 'recurring' ) {
                        foreach ( $request as $key => $val ) {
diff --git a/PaymentProviders/PayPal/PayPalPaymentsAPI.php 
b/PaymentProviders/PayPal/PayPalPaymentsAPI.php
index ec2c6c8..9dac247 100644
--- a/PaymentProviders/PayPal/PayPalPaymentsAPI.php
+++ b/PaymentProviders/PayPal/PayPalPaymentsAPI.php
@@ -15,8 +15,7 @@
         * @return boolean
         */
        function validate( $post_fields ) {
-               $url = Configuration::getDefaultConfig()
-                       ->val( 'postback-url' );
+               $url = Configuration::getDefaultConfig()->val( 'postback-url' );
                $ch = curl_init();
                curl_setopt( $ch, CURLOPT_URL, $url );
                curl_setopt( $ch, CURLOPT_HEADER, 0 );
diff --git a/PaymentProviders/PayPal/Tests/Data/subscr_payment.json 
b/PaymentProviders/PayPal/Tests/Data/subscr_payment.json
index 1543a13..f4bafc6 100644
--- a/PaymentProviders/PayPal/Tests/Data/subscr_payment.json
+++ b/PaymentProviders/PayPal/Tests/Data/subscr_payment.json
@@ -1,32 +1,42 @@
 {
-    "transaction_subject": "Donation to the Wikimedia Foundation"
-    "payment_date": "01:00:26 Aug 13, 2016 PDT"
-    "txn_type": "subscr_payment"
-    "subscr_id": "S-WWWWWWWWWWWWWWWWW"
-    "last_name": "Doe"
-    "residence_country": "US"
-    "item_name": "Donation to the Wikimedia Foundation"
-    "payment_gross": "10.00"
-    "mc_currency": "USD"
-    "business": "nob...@wikimedia.org"
-    "payment_type": "instant"
-    "protection_eligibility": "Ineligible"
-    "verify_sign": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
-    "payer_status": "unverified"
-    "payer_email": "nob...@example.com"
-    "txn_id": "YYYYYYYYYYYYYYYYY"
-    "receiver_email": "nob...@wikimedia.org"
-    "first_name": "John"
-    "payer_id": "ZZZZZZZZZZZZZ"
-    "receiver_id": "AAAAAAAAAAAAA"
-    "item_number": "DONATE"
-    "payment_status": "Completed"
-    "payment_fee": "0.42"
-    "mc_fee": "0.42"
-    "mc_gross": "10.00"
-    "custom": "33333333"
-    "charset": "UTF-8"
-    "notify_version": "3.8"
-    "ipn_track_id": "8888888888888"
+    "mc_gross": "1.03",
+    "protection_eligibility": "Eligible",
+    "address_status": "confirmed",
+    "payer_id": "XXXXXXXXXXXXX",
+    "address_street": "123 Only Kidding",
+    "payment_date": "16:03:13 Sep 21, 2016 PDT",
+    "payment_status": "Completed",
+    "charset": "UTF-8",
+    "address_zip": "99999",
+    "first_name": "Joe",
+    "mc_fee": "0.27",
+    "address_country_code": "US",
+    "address_name": "Joe Camel",
+    "notify_version": "3.8",
+    "subscr_id": "S-XXXXXXXXXXXXXXXXX",
+    "custom": "7373",
+    "payer_status": "verified",
+    "business": "nob...@wikimedia.org",
+    "address_country": "United States",
+    "address_city": "Maynardsville",
+    "verify_sign": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
+    "payer_email": "i...@google.net",
+    "txn_id": "77777777777777777",
+    "payment_type": "instant",
+    "payer_business_name": "Joe Camel",
+    "last_name": "Camel",
+    "address_state": "CA",
+    "receiver_email": "nob...@wikimedia.org",
+    "payment_fee": "0.27",
+    "receiver_id": "7777777777777",
+    "txn_type": "subscr_payment",
+    "item_name": "Donation to the Wikimedia Foundation",
+    "mc_currency": "USD",
+    "item_number": "DONATE",
+    "residence_country": "US",
+    "transaction_subject": "7373",
+    "payment_gross": "1.03",
+    "ipn_track_id": "7777777777777",
+    "date": "",
+    "gateway": "paypal"
 }
-
diff --git a/PaymentProviders/PayPal/Tests/Data/subscr_signup.json 
b/PaymentProviders/PayPal/Tests/Data/subscr_signup.json
new file mode 100644
index 0000000..8a3b197
--- /dev/null
+++ b/PaymentProviders/PayPal/Tests/Data/subscr_signup.json
@@ -0,0 +1,37 @@
+{
+    "amount3": "1.03",
+    "address_status": "confirmed",
+    "subscr_date": "16:03:11 Sep 21, 2016 PDT",
+    "payer_id": "XXXXXXXXXXXXX",
+    "address_street": "123 Only Joking",
+    "mc_amount3": "1.03",
+    "charset": "UTF-8",
+    "address_zip": "99999",
+    "first_name": "Joe",
+    "reattempt": "1",
+    "address_country_code": "US",
+    "address_name": "Joe Camel",
+    "notify_version": "3.8",
+    "subscr_id": "S-XXXXXXXXXXXXXXXXX",
+    "custom": "7373",
+    "payer_status": "verified",
+    "business": "nob...@wikimedia.org",
+    "address_country": "United States",
+    "address_city": "Scranton",
+    "verify_sign": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
+    "payer_email": "i...@google.net",
+    "payer_business_name": "Joe Camel",
+    "last_name": "Camel",
+    "address_state": "CA",
+    "receiver_email": "nob...@wikimedia.org",
+    "recurring": "1",
+    "txn_type": "subscr_signup",
+    "item_name": "Donation to the Wikimedia Foundation",
+    "mc_currency": "USD",
+    "item_number": "DONATE",
+    "residence_country": "US",
+    "period3": "1 M",
+    "ipn_track_id": "7777777777777",
+    "date": "",
+    "gateway": "paypal"
+}
diff --git a/PaymentProviders/PayPal/Tests/MockPayPalPaymentsAPI.php 
b/PaymentProviders/PayPal/Tests/MockPayPalPaymentsAPI.php
index 74ed15b..ac0ef67 100644
--- a/PaymentProviders/PayPal/Tests/MockPayPalPaymentsAPI.php
+++ b/PaymentProviders/PayPal/Tests/MockPayPalPaymentsAPI.php
@@ -4,9 +4,9 @@
 
 class MockPayPalPaymentsAPI extends PayPalPaymentsAPI {
        protected function curl ( $ch, $post_fields ) {
-               // XXX Not sure if too twisted.
-               if ( CaptureIncomingMessageTest::$verified_msg === $post_fields 
) {
-                       return 'VERIFIED';
+               if ( CaptureIncomingMessageTest::$fail_verification ) {
+                       return 'INVALID';
                }
+               return 'VERIFIED';
        }
 }
diff --git a/PaymentProviders/PayPal/Tests/config_test.yaml 
b/PaymentProviders/PayPal/Tests/config_test.yaml
index 233ac68..aaa8df9 100644
--- a/PaymentProviders/PayPal/Tests/config_test.yaml
+++ b/PaymentProviders/PayPal/Tests/config_test.yaml
@@ -8,18 +8,21 @@
             constructor-parameters:
                 -
                     connection_string: 'sqlite::memory:'
-                    queue: 'verified'
+                    queue: verified
 
         jobs-paypal:
             class: PHPQueue\Backend\PDO
             constructor-parameters:
                 -
                     connection_string: 'sqlite::memory:'
-                    queue: 'jobs-paypal'
+                    queue: jobs-paypal
 
         recurring:
-            class: SmashPig\Tests\MockDataStore
-            constructor-parameters: []
+            class: PHPQueue\Backend\PDO
+            constructor-parameters:
+                -
+                    connection_string: 'sqlite::memory:'
+                    queue: recurring
 
         refund:
             class: SmashPig\Tests\MockDataStore
diff --git 
a/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php 
b/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php
index 251780e..8b7e59f 100644
--- a/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php
+++ b/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php
@@ -21,16 +21,27 @@
         * @var Configuration
         */
        public $config;
-       static $verified_msg;
+
+       static $fail_verification = false;
+
+       static $message_locations = array(
+               'verified' => 'web_accept.json',
+               'recurring' => 'subscr_signup.json',
+               'recurring' => 'subscr_payment.json'
+       );
+
+       static $messages = array();
 
        public function setUp() {
                parent::setUp();
                $this->config = PayPalTestConfiguration::get();
                Context::initWithLogger( $this->config );
-               self::$verified_msg = json_decode(
-                       file_get_contents( __DIR__ . '/../Data/web_accept.json' 
),
-                       true
-               );
+               foreach ( self::$message_locations as $type => $file ) {
+                       self::$messages[$type] = json_decode(
+                               file_get_contents( __DIR__ . '/../Data/' . 
$file ),
+                               true
+                       );
+               }
        }
 
        private function capture ( $msg ) {
@@ -41,42 +52,46 @@
        }
 
        public function testCapture() {
+               foreach ( self::$messages as $type => $msg ) {
 
-               $this->capture( self::$verified_msg );
+                       $this->capture( $msg );
 
-               $jobQueue = $this->config->object( 'data-store/jobs-paypal' );
-               $jobMessage = $jobQueue->pop();
+                       $jobQueue = $this->config->object( 
'data-store/jobs-paypal' );
+                       $jobMessage = $jobQueue->pop();
 
-               $this->assertEquals( $jobMessage['php-message-class'],
-                       'SmashPig\PaymentProviders\PayPal\Job' );
+                       $this->assertEquals( $jobMessage['php-message-class'],
+                               'SmashPig\PaymentProviders\PayPal\Job' );
 
-               $this->assertEquals( $jobMessage['payload'], 
self::$verified_msg );
+                       $this->assertEquals( $jobMessage['payload'], $msg );
 
+               }
        }
 
        public function testConsume () {
+               foreach ( self::$messages as $type => $msg ) {
+                       $this->capture( $msg );
 
-               $this->capture( self::$verified_msg );
+                       $jobQueue = $this->config->object( 
'data-store/jobs-paypal' );
+                       $jobMessage = $jobQueue->pop();
 
-               $jobQueue = $this->config->object( 'data-store/jobs-paypal' );
-               $jobMessage = $jobQueue->pop();
+                       $job = KeyedOpaqueStorableObject::fromJsonProxy(
+                               $jobMessage['php-message-class'],
+                               json_encode( $jobMessage )
+                       );
 
-               $job = KeyedOpaqueStorableObject::fromJsonProxy(
-                       $jobMessage['php-message-class'],
-                       json_encode( $jobMessage )
-               );
+                       $job->execute();
 
-               $job->execute();
+                       $queue = $this->config->object( 'data-store/' . $type );
+                       $message = $queue->pop();
 
-               $verifiedQueue = $this->config->object( 'data-store/verified' );
-               $verifiedMessage = $verifiedQueue->pop();
+                       $this->assertNotEmpty( $message );
 
-               $this->assertNotEmpty( $verifiedMessage );
-
+               }
        }
 
        public function testFailedConsume () {
-               $jobMessage = array('just' => 'some', 'old' => 'message' );
+               self::$fail_verification = true;
+               $jobMessage = array( 'txn_type' => 'fail' );
                $jobClass = 'SmashPig\PaymentProviders\PayPal\Job';
                $job = KeyedOpaqueStorableObject::fromJsonProxy(
                        $jobClass,

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5b1cb4155928ed801c930cd0bc243c5637e1e7da
Gerrit-PatchSet: 4
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Cdentinger <cdentin...@wikimedia.org>
Gerrit-Reviewer: Awight <awi...@wikimedia.org>
Gerrit-Reviewer: Ejegg <eeggles...@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