jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/366167 )

Change subject: Ingenico Connect: getHostedCheckoutStatus
......................................................................


Ingenico Connect: getHostedCheckoutStatus

Bug: T163948
Change-Id: I3d11fba2d4c900752c6e35d2182f412d95735696
---
M globalcollect_gateway/config/var_map.yaml
M globalcollect_gateway/globalcollect.adapter.php
M ingenico_gateway/config/var_map.yaml
M ingenico_gateway/ingenico.adapter.php
M tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php
5 files changed, 108 insertions(+), 20 deletions(-)

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



diff --git a/globalcollect_gateway/config/var_map.yaml 
b/globalcollect_gateway/config/var_map.yaml
index 60fd28c..abb616a 100644
--- a/globalcollect_gateway/config/var_map.yaml
+++ b/globalcollect_gateway/config/var_map.yaml
@@ -50,6 +50,7 @@
 RETURNURL: returnto
 SPECIALID: special_id
 STATE: state_province
+STATUSID: gateway_status
 STREET: street_address
 SURNAME: last_name
 SWIFTCODE: swift_code
diff --git a/globalcollect_gateway/globalcollect.adapter.php 
b/globalcollect_gateway/globalcollect.adapter.php
index 4acb35d..36eab0b 100644
--- a/globalcollect_gateway/globalcollect.adapter.php
+++ b/globalcollect_gateway/globalcollect.adapter.php
@@ -372,6 +372,7 @@
                                'AMOUNT',
                                'AVSRESULT',
                                'CVVRESULT',
+                               'STATUSID',
                        ),
                );
 
@@ -641,7 +642,7 @@
                $status_response = null;
 
                for ( $loops = 0; $loops < $loopcount && !$cancelflag && 
!$problemflag; ++$loops ) {
-                       $status_result = $this->do_transaction( 
'GET_ORDERSTATUS' );
+                       $status_result = $this->getOrderStatusFromProcessor();
                        $validationAction = $this->getValidationAction();
                        $cvv_result = $this->getData_Unstaged_Escaped( 
'cvv_result' );
                        $gotCVV = strlen( $cvv_result ) > 0;
@@ -667,13 +668,12 @@
 
                        $order_status_results = false;
                        if ( !$cancelflag && !$problemflag ) {
-       // $order_status_results = $this->getFinalStatus();
-                               $txn_data = $this->getTransactionData();
-                               if ( isset( $txn_data['STATUSID'] ) ) {
+                               $statusCode = $this->getData_Unstaged_Escaped( 
'gateway_status' );
+                               if ( $statusCode ) {
                                        if ( is_null( $original_status_code ) ) 
{
-                                               $original_status_code = 
$txn_data['STATUSID'];
+                                               $original_status_code = 
$statusCode;
                                        }
-                                       $order_status_results = 
$this->findCodeAction( 'GET_ORDERSTATUS', 'STATUSID', $txn_data['STATUSID'] );
+                                       $order_status_results = 
$this->findCodeAction( 'GET_ORDERSTATUS', 'STATUSID', $statusCode );
                                }
                                if ( $loops === 0 && $is_orphan && !is_null( 
$original_status_code ) ) {
                                        // save stats.
@@ -704,7 +704,7 @@
                                                }
 
                                                // none of this should ever 
execute for a transaction that doesn't use 3d secure...
-                                               if ( $txn_data['STATUSID'] === 
'200' && ( $loops < $loopcount - 1 ) ) {
+                                               if ( $statusCode === '200' && ( 
$loops < $loopcount - 1 ) ) {
                                                        $this->logger->info( 
"Running DO_FINISHPAYMENT ($loops)" );
 
                                                        $dopayment_result = 
$this->do_transaction( 'DO_FINISHPAYMENT' );
@@ -724,7 +724,7 @@
                                                        break;
                                                }
 
-                                               if ( $txn_data['STATUSID'] !== 
'200' ) {
+                                               if ( $statusCode !== '200' ) {
                                                        break 2; // no need to 
loop.
                                                }
                                                // FIXME: explicit that we want 
to fall through?
@@ -801,6 +801,10 @@
 
 // return something better... if we need to!
                return $status_result;
+       }
+
+       protected function getOrderStatusFromProcessor() {
+               return $this->do_transaction( 'GET_ORDERSTATUS' );
        }
 
        /**
@@ -1322,7 +1326,7 @@
                // set the transaction result message
                $responseStatus = isset( $data['STATUSID'] ) ? 
$data['STATUSID'] : '';
                $this->transaction_response->setTxnMessage( "Response Status: " 
. $responseStatus ); // TODO: Translate for GC.
-               $this->transaction_response->setGatewayTransactionId( 
$this->getData_Unstaged_Escaped( 'order_id' ) );
+               $this->setGatewayTransactionId();
 
                $retErrCode = null;
                $retryVars = array();
@@ -1778,4 +1782,8 @@
                        return false;
                }
        }
+
+       protected function setGatewayTransactionId() {
+               $this->transaction_response->setGatewayTransactionId( 
$this->getData_Unstaged_Escaped( 'order_id' ) );
+       }
 }
diff --git a/ingenico_gateway/config/var_map.yaml 
b/ingenico_gateway/config/var_map.yaml
index 79c88d8..bd45196 100644
--- a/ingenico_gateway/config/var_map.yaml
+++ b/ingenico_gateway/config/var_map.yaml
@@ -14,3 +14,7 @@
 surname: last_name
 merchantReference: order_id
 hostedCheckoutId: gateway_session_id
+id: gateway_txn_id
+statusCode: gateway_status
+avsResult: avs_result
+cvvResult: cvv_result
diff --git a/ingenico_gateway/ingenico.adapter.php 
b/ingenico_gateway/ingenico.adapter.php
index 8bf03a4..be7f522 100644
--- a/ingenico_gateway/ingenico.adapter.php
+++ b/ingenico_gateway/ingenico.adapter.php
@@ -91,6 +91,29 @@
                                'hostedCheckoutId'
                        )
                );
+
+               $this->transactions['getHostedCheckoutStatus'] = array(
+                       'request' => array( 'hostedCheckoutId' ),
+                       'response' => array(
+                               'id',
+                               'amount',
+                               'currencyCode',
+                               'avsResult',
+                               'cvvResult',
+                               'statusCode',
+                       )
+               );
+
+               $this->transactions['getPaymentStatus'] = array(
+                       'request' => array( 'id' ),
+                       'response' => array(
+                               'amount',
+                               'currencyCode',
+                               'avsResult',
+                               'cvvResult',
+                               'statusCode',
+                       )
+               );
        }
 
        /**
@@ -108,6 +131,12 @@
                );
        }
 
+       /**
+        * Make an API call to Ingenico Connect.
+        *
+        * @param array $data parameters for the transaction
+        * @return bool whether the API call succeeded
+        */
        public function curl_transaction( $data ) {
                $email = $this->getData_Unstaged_Escaped( 'email' );
                $this->logger->info( "Making API call for donor $email" );
@@ -121,11 +150,18 @@
                switch ( $this->getCurrentTransaction() ) {
                        case 'createHostedCheckout':
                                $result = $provider->createHostedPayment( $data 
);
-                               $this->transaction_response->setRawResponse( 
json_encode( $result ) );
-                               return true;
+                               break;
+                       case 'getHostedCheckoutStatus':
+                               $result = $provider->getHostedPaymentStatus(
+                                       $data['hostedCheckoutId']
+                               );
+                               break;
                        default:
                                return false;
                }
+
+               $this->transaction_response->setRawResponse( json_encode( 
$result ) );
+               return true;
        }
 
        public function getBasedir() {
@@ -133,11 +169,7 @@
        }
 
        public function do_transaction( $transaction ) {
-               // If this is not our first call, get a fresh order ID
-               // FIXME: This is repeated in four places. Maybe always 
regenerate in incrementSequenceNumber?
-               if ( $this->session_getData( 'sequence' ) ) {
-                       $this->regenerateOrderID();
-               }
+               $this->ensureUniqueOrderID();
                if ( $transaction === 'createHostedCheckout' ) {
                        $this->incrementSequenceNumber();
                }
@@ -161,12 +193,54 @@
        }
 
        public function parseResponseData( $response ) {
-               if ( isset( $response['partialRedirectUrl'] ) ) {
+               // Flatten the whole darn nested thing.
+               // FIXME: This should probably happen in the SmashPig library 
where
+               // we can flatten in a custom way per transaction type. Or we 
should
+               // expand var_map to work with nested stuff.
+               $flattened = array();
+               $squashMe = function( $sourceData, $squashMe ) use ( 
&$flattened ) {
+                       foreach( $sourceData as $key => $value ) {
+                               if ( is_array( $value ) ) {
+                                       call_user_func( $squashMe, $value, 
$squashMe );
+                               } else {
+                                       // Hmm, we might be clobbering something
+                                       $flattened[$key] = $value;
+                               }
+                       }
+               };
+               $squashMe( $response, $squashMe );
+               if ( isset( $flattened['partialRedirectUrl'] ) ) {
                        $provider = $this->getPaymentProvider();
-                       $response['FORMACTION'] = 
$provider->getHostedPaymentUrl(
-                               $response['partialRedirectUrl']
+                       $flattened['FORMACTION'] = 
$provider->getHostedPaymentUrl(
+                               $flattened['partialRedirectUrl']
                        );
                }
-               return $response;
+               return $flattened;
+       }
+
+       public function processDonorReturn( $requestValues ) {
+               // FIXME: make sure we're processing the order ID we expect!
+
+               $response = $this->do_transaction( 'Confirm_CreditCard' );
+               return PaymentResult::fromResults(
+                       $response,
+                       $this->getFinalStatus()
+               );
+       }
+
+       protected function getOrderStatusFromProcessor() {
+               // FIXME: sometimes we should use getPayment
+               return $this->do_transaction( 'getHostedCheckoutStatus' );
+       }
+
+       protected function post_process_getHostedCheckoutStatus() {
+               return parent::post_process_get_orderstatus();
+       }
+
+       protected function setGatewayTransactionId() {
+               // FIXME: See 'Silly' comment in PayPal Express adapter
+               $this->transaction_response->setGatewayTransactionId(
+                       $this->getData_Unstaged_Escaped( 'gateway_txn_id' )
+               );
        }
 }
diff --git a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php 
b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php
index e22e241..c04b7bb 100644
--- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php
+++ b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php
@@ -340,6 +340,7 @@
                        'PAYMENTREFERENCE' => 'payment_reference',
                        'PROVINCIA' => 'provincia',
                        'SPECIALID' => 'special_id',
+                       'STATUSID' => 'gateway_status',
                        'SWIFTCODE' => 'swift_code',
                        'TRANSACTIONTYPE' => 'transaction_type',
                        'FISCALNUMBER' => 'fiscal_number',

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I3d11fba2d4c900752c6e35d2182f412d95735696
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <ej...@ejegg.com>
Gerrit-Reviewer: AndyRussG <andrew.green...@gmail.com>
Gerrit-Reviewer: Cdentinger <cdentin...@wikimedia.org>
Gerrit-Reviewer: Ejegg <ej...@ejegg.com>
Gerrit-Reviewer: Mepps <me...@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