Cdentinger has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/312175

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

Add recurring PayPal test

Also fix a notice about date not being set.
And use a foreach loop to run different test docs. Too much?

Change-Id: I5b1cb4155928ed801c930cd0bc243c5637e1e7da
---
M PaymentProviders/PayPal/Job.php
M PaymentProviders/PayPal/PayPalPaymentsAPI.php
M PaymentProviders/PayPal/Tests/Data/subscr_payment.json
M PaymentProviders/PayPal/Tests/MockPayPalPaymentsAPI.php
M PaymentProviders/PayPal/Tests/config_test.yaml
M PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php
6 files changed, 76 insertions(+), 55 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/SmashPig 
refs/changes/75/312175/1

diff --git a/PaymentProviders/PayPal/Job.php b/PaymentProviders/PayPal/Job.php
index 703f905..040b725 100644
--- a/PaymentProviders/PayPal/Job.php
+++ b/PaymentProviders/PayPal/Job.php
@@ -50,6 +50,9 @@
                        foreach ( $request as $key => $val ) {
                                $new_msg->$key = $val;
                        }
+                       // FIXME represent special case as var_map config 
override?
+                       // will require recurring consumer to accept normalized 
msg
+                       $new_msg->date = $request['subscr_id'];
                } else {
                        $map = $this->config->val( 'var_map' );
                        foreach ( $map as $rx => $tx ) {
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..fd311cd 100644
--- a/PaymentProviders/PayPal/Tests/Data/subscr_payment.json
+++ b/PaymentProviders/PayPal/Tests/Data/subscr_payment.json
@@ -1,32 +1,36 @@
 {
-    "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"
+    "p":"paypal/listener",
+    "amount":"1.03",
+    "address_status":"confirmed",
+    "subscr_date":"16:03:11 Sep 21, 2016 PDT",
+    "payer_id":"XXXXXXXXXXXXX",
+    "address_street":"123 False Rd",
+    "mc_amount":"1.03",
+    "charset":"UTF-8",
+    "address_zip":"99999",
+    "first_name":"Bob",
+    "reattempt":"1",
+    "address_country_code":"US",
+    "address_name":"Bob Loblaw",
+    "notify_version":"3.8",
+    "subscr_id":"S-XXXXXXXXXXXXXXXXX",
+    "custom":"7373",
+    "payer_status":"verified",
+    "business":"nob...@wikimedia.org",
+    "address_country":"United States",
+    "address_city":"Springfield",
+    "verify_sign":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
+    "payer_email":"i...@internet.net",
+    "payer_business_name":"Bob Loblaw",
+    "last_name":"Loblaw",
+    "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":"XXXXXXXXXXXXXX"
 }
-
diff --git a/PaymentProviders/PayPal/Tests/MockPayPalPaymentsAPI.php 
b/PaymentProviders/PayPal/Tests/MockPayPalPaymentsAPI.php
index 74ed15b..1bd83ab 100644
--- a/PaymentProviders/PayPal/Tests/MockPayPalPaymentsAPI.php
+++ b/PaymentProviders/PayPal/Tests/MockPayPalPaymentsAPI.php
@@ -4,8 +4,7 @@
 
 class MockPayPalPaymentsAPI extends PayPalPaymentsAPI {
        protected function curl ( $ch, $post_fields ) {
-               // XXX Not sure if too twisted.
-               if ( CaptureIncomingMessageTest::$verified_msg === $post_fields 
) {
+               if ( CaptureIncomingMessageTest::$current_message === 
$post_fields ) {
                        return 'VERIFIED';
                }
        }
diff --git a/PaymentProviders/PayPal/Tests/config_test.yaml 
b/PaymentProviders/PayPal/Tests/config_test.yaml
index 233ac68..62ca6ab 100644
--- a/PaymentProviders/PayPal/Tests/config_test.yaml
+++ b/PaymentProviders/PayPal/Tests/config_test.yaml
@@ -18,8 +18,11 @@
                     queue: 'jobs-paypal'
 
         recurring:
-            class: SmashPig\Tests\MockDataStore
-            constructor-parameters: []
+            class: PHPQueue\Backend\PDO
+            constructor-parameters:
+                -
+                    connection_string: 'sqlite::memory:'
+                    queue: 'jobs-paypal'
 
         refund:
             class: SmashPig\Tests\MockDataStore
diff --git 
a/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php 
b/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php
index 251780e..7879092 100644
--- a/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php
+++ b/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php
@@ -21,14 +21,21 @@
         * @var Configuration
         */
        public $config;
-       static $verified_msg;
+
+       static $messages = array();
+
+       static $current_message;
 
        public function setUp() {
                parent::setUp();
                $this->config = PayPalTestConfiguration::get();
                Context::initWithLogger( $this->config );
-               self::$verified_msg = json_decode(
+               self::$messages['verified'] = json_decode(
                        file_get_contents( __DIR__ . '/../Data/web_accept.json' 
),
+                       true
+               );
+               self::$messages['recurring'] = json_decode(
+                       file_get_contents( __DIR__ . 
'/../Data/subscr_payment.json' ),
                        true
                );
        }
@@ -41,38 +48,44 @@
        }
 
        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 )
-               );
+                       // This is so the mock API has something to pretend 
verify against.
+                       self::$current_message = $msg;
 
-               $job->execute();
+                       $job->execute();
 
-               $verifiedQueue = $this->config->object( 'data-store/verified' );
-               $verifiedMessage = $verifiedQueue->pop();
+                       $verifiedQueue = $this->config->object( 'data-store/' . 
$type );
+                       $verifiedMessage = $verifiedQueue->pop();
 
-               $this->assertNotEmpty( $verifiedMessage );
+                       $this->assertNotEmpty( $verifiedMessage );
 
+               }
        }
 
        public function testFailedConsume () {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5b1cb4155928ed801c930cd0bc243c5637e1e7da
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Cdentinger <cdentin...@wikimedia.org>

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

Reply via email to