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

Change subject: PayPal EC recurring: initial charge is part of subscription
......................................................................

PayPal EC recurring: initial charge is part of subscription

We were originally doing a kludgey workaround that had an initial
standalone payment, then a subscription starting in a month. That
made it really hard for Donor Services to find subscriptions.

Bug: T170478
Change-Id: Ifebc76e0e501303381ff8c73000d02e36cdb796c
---
M paypal_gateway/express_checkout/config/var_map.yaml
M paypal_gateway/express_checkout/paypal_express.adapter.php
A 
tests/phpunit/includes/Responses/paypal_ec/CreateRecurringPaymentsProfile_10486.testresponse
M 
tests/phpunit/includes/Responses/paypal_ec/CreateRecurringPaymentsProfile_Recurring-OK.testresponse
4 files changed, 23 insertions(+), 29 deletions(-)


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

diff --git a/paypal_gateway/express_checkout/config/var_map.yaml 
b/paypal_gateway/express_checkout/config/var_map.yaml
index 40e9b9f..1b7032f 100644
--- a/paypal_gateway/express_checkout/config/var_map.yaml
+++ b/paypal_gateway/express_checkout/config/var_map.yaml
@@ -24,6 +24,7 @@
 PROFILEID: subscr_id
 PROFILEREFERENCE: contribution_tracking_id
 PROFILESTARTDATE: date
+TRANSACTIONID: gateway_txn_id
 # TODO: discuss whether to capture
 #PHONENUM: phone
 RETURNURL: returnto
diff --git a/paypal_gateway/express_checkout/paypal_express.adapter.php 
b/paypal_gateway/express_checkout/paypal_express.adapter.php
index c614407..527c093 100644
--- a/paypal_gateway/express_checkout/paypal_express.adapter.php
+++ b/paypal_gateway/express_checkout/paypal_express.adapter.php
@@ -200,7 +200,7 @@
                                'NOSHIPPING' => 1,
                                'L_BILLINGTYPE0' => 'RecurringPayments',
                                // FIXME: Sad!  The thank-you message would be 
perfect here,
-                               // but it seems the exlamation mark is not 
supported, even when
+                               // but it seems the exclamation mark is not 
supported, even when
                                // urlencoded properly.
                                //'L_BILLINGAGREEMENTDESCRIPTION0' => 
WmfFramework::formatMessage( 
'donate_interface-donate-error-thank-you-for-your-support' ),
                                'L_BILLINGAGREEMENTDESCRIPTION0' => 
WmfFramework::formatMessage( 'donate_interface-monthly-donation-description' ),
@@ -408,8 +408,12 @@
                        case 'CreateRecurringPaymentsProfile':
                                $this->checkResponseAck( $response );
 
-                               // Grab the subscription ID.
+                               // Grab the subscription ID and transaction ID 
for the
+                               // initial charge.
                                $this->addResponseData( $this->unstageKeys( 
$response ) );
+                               // FIXME: Silly.
+                               
$this->transaction_response->setGatewayTransactionId(
+                                       $this->getData_Unstaged_Escaped( 
'gateway_txn_id' ) );
 
                                // FIXME: Not a satisfying ending.  Parse the 
PROFILESTATUS
                                // response and sort it into complete or 
pending.
@@ -446,15 +450,9 @@
                                        $this->getData_Unstaged_Escaped( 
'gateway_txn_id' ) );
                                $status = $this->findCodeAction( 
'DoExpressCheckoutPayment',
                                        'PAYMENTINFO_0_ERRORCODE', 
$response['PAYMENTINFO_0_ERRORCODE'] );
-                               // For recurring payments, we don't want to 
finalize or send the queue
-                               // message just yet
-                               if (
-                                       $status === FinalStatus::FAILED ||
-                                       !$this->getData_Unstaged_Escaped( 
'recurring' )
-                               ) {
-                                       $this->finalizeInternalStatus( $status 
);
-                                       $this->postProcessDonation();
-                               }
+
+                               $this->finalizeInternalStatus( $status );
+                               $this->postProcessDonation();
                                break;
                        }
 
@@ -484,7 +482,8 @@
                                        case '10486':
                                                // Donor's first funding method 
failed, but they might have another
                                                
$this->transaction_response->setRedirect(
-                                                       
$this->account_config['RedirectURL'] . $response['TOKEN']
+                                                       
$this->account_config['RedirectURL'] .
+                                                       
$this->getData_Unstaged_Escaped( 'gateway_session_id' )
                                                );
                                                $fatal = false;
                                                break;
@@ -540,30 +539,23 @@
                                ResponseCodes::UNKNOWN );
                }
 
-               // One-time payment, or initial payment in a subscription.
-               $resultData = $this->do_transaction( 'DoExpressCheckoutPayment' 
);
-               if ( !$resultData->getCommunicationStatus() ) {
-                       $this->finalizeInternalStatus( FinalStatus::FAILED );
-                       return PaymentResult::newFailure();
-               }
-
-               // Silly conditional. What we really want to know is if the
-               // DoExpressCheckoutPayment txn was successful.
-               if (
-                       !$resultData->getRedirect() &&
-                       !$resultData->getErrors() &&
-                       $this->getData_Unstaged_Escaped( 'recurring' )
-               ) {
+               if ( $this->getData_Unstaged_Escaped( 'recurring' ) ) {
                        // Set up recurring billing agreement.
                        $this->addRequestData( array(
-                               // Start in a month; we're making today's 
payment as an one-time charge.
-                               'date' => time() + 30 * 24 * 3600, // FIXME: 
calendar month
+                               '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(
                        $this->getTransactionResponse(),
diff --git 
a/tests/phpunit/includes/Responses/paypal_ec/CreateRecurringPaymentsProfile_10486.testresponse
 
b/tests/phpunit/includes/Responses/paypal_ec/CreateRecurringPaymentsProfile_10486.testresponse
new file mode 100644
index 0000000..647e408
--- /dev/null
+++ 
b/tests/phpunit/includes/Responses/paypal_ec/CreateRecurringPaymentsProfile_10486.testresponse
@@ -0,0 +1 @@
+TIMESTAMP=2017%2d04%2d20T16%3a59%3a06Z&CORRELATIONID=537ffff0fefa&ACK=Failure&VERSION=204&BUILD=32574509&L_ERRORCODE0=10486&L_SHORTMESSAGE0=This%20transaction%20couldn%27t%20be%20completed%2e&L_LONGMESSAGE0=This%20transaction%20couldn%27t%20be%20completed%2e%20Please%20redirect%20your%20customer%20to%20PayPal%2e&L_SEVERITYCODE0=Error
diff --git 
a/tests/phpunit/includes/Responses/paypal_ec/CreateRecurringPaymentsProfile_Recurring-OK.testresponse
 
b/tests/phpunit/includes/Responses/paypal_ec/CreateRecurringPaymentsProfile_Recurring-OK.testresponse
index 77d7506..7617c93 100644
--- 
a/tests/phpunit/includes/Responses/paypal_ec/CreateRecurringPaymentsProfile_Recurring-OK.testresponse
+++ 
b/tests/phpunit/includes/Responses/paypal_ec/CreateRecurringPaymentsProfile_Recurring-OK.testresponse
@@ -1 +1 @@
-PROFILEID=I%2d88J1M3DLSF0&PROFILESTATUS=ActiveProfile&TIMESTAMP=2017%2d04%2d18T16%3a45%3a29Z&CORRELATIONID=4312c123aa0f2&ACK=Success&VERSION=204&BUILD=25237094
+TRANSACTIONID=5EJ123456T987654S&PROFILEID=I%2d88J1M3DLSF0&PROFILESTATUS=ActiveProfile&TIMESTAMP=2017%2d04%2d18T16%3a45%3a29Z&CORRELATIONID=4312c123aa0f2&ACK=Success&VERSION=204&BUILD=25237094

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifebc76e0e501303381ff8c73000d02e36cdb796c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <ej...@ejegg.com>

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

Reply via email to