Mepps has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/386537 )

Change subject: Handle PaymentActionCompleted in batch mode
......................................................................

Handle PaymentActionCompleted in batch mode

Change-Id: I3c0cd53715b30e37b9ac728bf40ebcd6f1e1683a
---
M paypal_gateway/express_checkout/paypal_express.adapter.php
M tests/phpunit/Adapter/PayPal/PayPalExpressTest.php
A 
tests/phpunit/includes/Responses/paypal_ec/GetExpressCheckoutDetails_Complete.testresponse
3 files changed, 46 insertions(+), 17 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/37/386537/1

diff --git a/paypal_gateway/express_checkout/paypal_express.adapter.php 
b/paypal_gateway/express_checkout/paypal_express.adapter.php
index a509b37..3565b03 100644
--- a/paypal_gateway/express_checkout/paypal_express.adapter.php
+++ b/paypal_gateway/express_checkout/paypal_express.adapter.php
@@ -439,12 +439,17 @@
                                break;
                        case 'GetExpressCheckoutDetails':
                                $this->checkResponseAck( $response );
-
                                // Merge response into our transaction data.
                                // TODO: Use getFormattedData instead.
                                // FIXME: We don't want to allow overwriting of 
ctid, need a
                                // blacklist of protected fields.
                                $this->addResponseData( $this->unstageKeys( 
$response ) );
+
+                               // Complete if payment already finalized
+                               if ( $this->isBatchProcessor() && 
$response['CHECKOUTSTATUS'] && $response['CHECKOUTSTATUS'] === 
'PaymentActionCompleted' ) {
+                                       $this->finalizeInternalStatus( 
FinalStatus::COMPLETE );
+                                       break;
+                               }
 
                                $this->runAntifraudFilters();
                                if ( $this->getValidationAction() !== 'process' 
) {
@@ -555,22 +560,24 @@
                                ResponseCodes::UNKNOWN );
                }
 
-               if ( $this->getData_Unstaged_Escaped( 'recurring' ) ) {
-                       // Set up recurring billing agreement.
-                       $this->addRequestData( array(
-                               'date' => time()
-                       ) );
-                       $resultData = $this->do_transaction( 
'CreateRecurringPaymentsProfile' );
-                       if ( !$resultData->getCommunicationStatus() ) {
-                               throw new ResponseProcessingException(
-                                       'Failed to create a recurring profile', 
ResponseCodes::UNKNOWN );
-                       }
-               } else {
-                       // One-time payment, or initial payment in a 
subscription.
-                       $resultData = $this->do_transaction( 
'DoExpressCheckoutPayment' );
-                       if ( !$resultData->getCommunicationStatus() ) {
-                               $this->finalizeInternalStatus( 
FinalStatus::FAILED );
-                               return PaymentResult::newFailure();
+               if ( $this->getFinalStatus() !== FinalStatus::COMPLETE ) {
+                       if ( $this->getData_Unstaged_Escaped( 'recurring' ) ) {
+                               // Set up recurring billing agreement.
+                               $this->addRequestData( array(
+                                       'date' => time()
+                               ) );
+                               $resultData = $this->do_transaction( 
'CreateRecurringPaymentsProfile' );
+                               if ( !$resultData->getCommunicationStatus() ) {
+                                       throw new ResponseProcessingException(
+                                               'Failed to create a recurring 
profile', ResponseCodes::UNKNOWN );
+                               }
+                       } else {
+                               // One-time payment, or initial payment in a 
subscription.
+                               $resultData = $this->do_transaction( 
'DoExpressCheckoutPayment' );
+                               if ( !$resultData->getCommunicationStatus() ) {
+                                       $this->finalizeInternalStatus( 
FinalStatus::FAILED );
+                                       return PaymentResult::newFailure();
+                               }
                        }
                }
                return PaymentResult::fromResults(
diff --git a/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php 
b/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php
index 5cb91a4..8a719de 100644
--- a/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php
+++ b/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php
@@ -400,6 +400,27 @@
                );
        }
 
+       /*
+     * Check that it does not call doPayment when status is PaymentNotInitiated
+     */
+       public function testProcessDonorReturnPaymentActionCompleted() {
+               $init = $this->getDonorTestData( 'US' );
+               $init['contribution_tracking_id'] = '45931210';
+               $options = array( 'batch_mode' => true );
+               $this->setUpRequest( $init, array( 'Donor' => $init ) );
+
+               $gateway = $this->getFreshGatewayObject( $init, $options );
+               $gateway::setDummyGatewayResponseCode( 'Complete' );
+               $gateway->processDonorReturn( array(
+                       'token' => 'EC%2d4V987654XA123456V',
+                       'PayerID' => 'ASDASD',
+               ) );
+
+               $this->assertEquals( FinalStatus::COMPLETE, 
$gateway->getFinalStatus() );
+               $message = QueueWrapper::getQueue( 'donations' )->pop();
+               $this->assertNull( $message, 'Should not queue a message' );
+       }
+
        /**
         * The result switcher should redirect the donor to the thank you page 
and mark the token as
         * processed.
diff --git 
a/tests/phpunit/includes/Responses/paypal_ec/GetExpressCheckoutDetails_Complete.testresponse
 
b/tests/phpunit/includes/Responses/paypal_ec/GetExpressCheckoutDetails_Complete.testresponse
new file mode 100644
index 0000000..26468a4
--- /dev/null
+++ 
b/tests/phpunit/includes/Responses/paypal_ec/GetExpressCheckoutDetails_Complete.testresponse
@@ -0,0 +1 @@
+TOKEN=EC%2d4V987654XA123456V&BILLINGAGREEMENTACCEPTEDSTATUS=0&CHECKOUTSTATUS=PaymentActionCompleted&TIMESTAMP=2017%2d02%2d01T20%3a07%3a14Z&CORRELATIONID=d70c9a334455e&ACK=Success&VERSION=204&BUILD=28806785&EMAIL=donor%40generous%2enet&PAYERID=8R297FE87CD8S&PAYERSTATUS=unverified&FIRSTNAME=Fezziwig&LASTNAME=Fowl&COUNTRYCODE=US&BILLINGNAME=Fezziwig%20Fowl&STREET=123%20Notta%20Way&CITY=Whoville&STATE=OR&ZIP=97211&COUNTRY=US&COUNTRYNAME=United%20States&ADDRESSID=PayPal&ADDRESSSTATUS=Confirmed&CURRENCYCODE=USD&AMT=1%2e55&ITEMAMT=1%2e55&SHIPPINGAMT=0&HANDLINGAMT=0&TAXAMT=0&CUSTOM=45931210&DESC=Donation%20to%20the%20Wikimedia%20Foundation&INVNUM=45931210%2e1&NOTIFYURL=http%3a%2f%2ffundraising%2ewikimedia%2eorg%2fIPNListener_Standalone%2ephp&INSURANCEAMT=0&SHIPDISCAMT=0&INSURANCEOPTIONOFFERED=false&L_QTY0=1&L_TAXAMT0=0&L_AMT0=1%2e55&L_DESC0=Donation%20to%20the%20Wikimedia%20Foundation&PAYMENTREQUEST_0_CURRENCYCODE=USD&PAYMENTREQUEST_0_AMT=1%2e55&PAYMENTREQUEST_0_ITEMAMT=1%2e55&PAYMENTREQUEST_0_SHIPPINGAMT=0&PAYMENTREQUEST_0_HANDLINGAMT=0&PAYMENTREQUEST_0_TAXAMT=0&PAYMENTREQUEST_0_CUSTOM=45931210&PAYMENTREQUEST_0_DESC=Donation%20to%20the%20Wikimedia%20Foundation&PAYMENTREQUEST_0_INVNUM=45931210%2e1&PAYMENTREQUEST_0_NOTIFYURL=http%3a%2f%2ffundraising%2ewikimedia%2eorg%2fIPNListener_Standalone%2ephp&PAYMENTREQUEST_0_INSURANCEAMT=0&PAYMENTREQUEST_0_SHIPDISCAMT=0&PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID=receiver%40wikimedia%2eorg&PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED=false&PAYMENTREQUEST_0_ADDRESSSTATUS=Confirmed&L_PAYMENTREQUEST_0_QTY0=1&L_PAYMENTREQUEST_0_TAXAMT0=0&L_PAYMENTREQUEST_0_AMT0=1%2e55&L_PAYMENTREQUEST_0_DESC0=Donation%20to%20the%20Wikimedia%20Foundation&PAYMENTREQUESTINFO_0_ERRORCODE=0

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3c0cd53715b30e37b9ac728bf40ebcd6f1e1683a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Mepps <me...@wikimedia.org>

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

Reply via email to