jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/369996 )
Change subject: Rectify orphan function
......................................................................
Rectify orphan function
Change-Id: I1a2a68772b6ae0fea8377bf12ac1efd1b338618d
---
M gateway_common/gateway.adapter.php
M paypal_gateway/express_checkout/paypal_express.adapter.php
M tests/phpunit/Adapter/GatewayAdapterTest.php
M tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanRectifierTest.php
M tests/phpunit/Adapter/PayPal/PayPalExpressTest.php
M tests/phpunit/DonationInterfaceTestCase.php
6 files changed, 112 insertions(+), 26 deletions(-)
Approvals:
jenkins-bot: Verified
Ejegg: Looks good to me, approved
diff --git a/gateway_common/gateway.adapter.php
b/gateway_common/gateway.adapter.php
index 4dcdebe..22afb96 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -3722,6 +3722,47 @@
}
/**
+ * Takes normalized data and creates adapter specific params for
processDonorReturn
+ * @return array
+ */
+ public function createDonorReturnParams() {
+ return array();
+ }
+
+ /**
+ * Allows adapters to specify logic as to whether an orphan can be
rectified
+ * @return bool
+ */
+ public function shouldRectifyOrphan(){
+ return false;
+ }
+
+ /**
+ * Looks at message to see if it should be rectified
+ * Allows exit if the adapter should not rectify the orphan
+ * Then tries to see if the orphan can be matched
+ * @return PaymentResult
+ */
+ public function rectifyOrphan(){
+ if (!$this->shouldRectifyOrphan()){
+ // Skip other payment methods which shouldn't be in the
pending
+ // queue anyway. See
https://phabricator.wikimedia.org/T161160
+ $this->logger->info( "Skipping pending record." );
+ return PaymentResult::newEmpty();
+ }
+ $this->logger->info( "Rectifying orphan:
{$this->getData_Staged( 'order_id' )}" );
+ $params = $this->createDonorReturnParams();
+ $paymentResult = $this->processDonorReturn( $params );
+ if (!$paymentResult->isFailed()){
+ $this->logger->info(
$this->getData_Staged('contribution_tracking_id') . ': FINAL: ' . $status );
+ return $paymentResult;
+ } else {
+
$this->errorState->addErrors($paymentResult->getErrors());
+
$this->logger->error($this->getData_Staged('contribution_tracking_id') . ':
ERRORS ' . print_r($this->errorState, true) );}
+ return $paymentResult;
+ }
+
+ /**
* @return PaymentTransactionResponse
*/
protected function getFailedValidationResponse() {
diff --git a/paypal_gateway/express_checkout/paypal_express.adapter.php
b/paypal_gateway/express_checkout/paypal_express.adapter.php
index 1369134..89069b9 100644
--- a/paypal_gateway/express_checkout/paypal_express.adapter.php
+++ b/paypal_gateway/express_checkout/paypal_express.adapter.php
@@ -529,18 +529,23 @@
public function processDonorReturn( $requestValues ) {
if (
- empty( $requestValues['token'] ) ||
- empty( $requestValues['PayerID'] )
+ empty( $requestValues['token'] )
) {
throw new ResponseProcessingException(
'Missing required parameters in request',
ResponseCodes::MISSING_REQUIRED_DATA
);
}
- $this->addRequestData( array(
- 'gateway_session_id' => $requestValues['token'],
- 'payer_id' => $requestValues['PayerID'],
- ) );
+ $requestData = array();
+ $requestData['gateway_session_id'] = $requestValues['token'];
+ if (
+ empty( $requestValues['PayerID'] )
+ ) {
+ $this->logger->info('Notice missing PayerID in
PaypalExpressAdapater::ProcessDonorReturn');
+ } else {
+ $requestData['payer_id'] = $requestValues['PayerID'];
+ }
+ $this->addRequestData( $requestData );
$resultData = $this->do_transaction(
'GetExpressCheckoutDetails' );
if ( !$resultData->getCommunicationStatus() ) {
throw new ResponseProcessingException( 'Failed to get
customer details',
@@ -592,4 +597,20 @@
public function getTransactionGatewayTxnID() {
return $this->getData_Unstaged_Escaped( 'gateway_txn_id' );
}
+
+ /*
+ * TODO: add test
+ */
+ public function createDonorReturnParams() {
+ return array('token' =>
$this->getData_Staged('gateway_session_id'));
+ }
+
+ /*
+ * Returns true becaues all payment methods can be rectified
+ * FIXME: Add handling for session expiration limits?
+ */
+ public function shouldRectifyOrphan()
+ {
+ return true;
+ }
}
diff --git a/tests/phpunit/Adapter/GatewayAdapterTest.php
b/tests/phpunit/Adapter/GatewayAdapterTest.php
index fceb832..230d916 100644
--- a/tests/phpunit/Adapter/GatewayAdapterTest.php
+++ b/tests/phpunit/Adapter/GatewayAdapterTest.php
@@ -334,5 +334,13 @@
$gateway->setValidationAction( 'process' );
$this->assertEquals( 'reject', $gateway->getValidationAction(),
'De-escalating action without reset!' );
}
+
+ public function testRectifyOrphan(){
+ $orphan = $this->createOrphan(array('gateway' => 'donation'));
+ $gateway = $this->getFreshGatewayObject($orphan);
+ //FIXME: dummy communication status, currently returns false
because orpphan can't be rectifiied!
+ $is_rectified = $gateway->rectifyOrphan();
+ $this->assertEquals(PaymentResult::newEmpty(), $is_rectified,
'rectifyOrphan did not return empty PaymentResult');
+ }
}
diff --git
a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanRectifierTest.php
b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanRectifierTest.php
index 0874bc2..a892c08 100644
--- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanRectifierTest.php
+++ b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanRectifierTest.php
@@ -157,28 +157,9 @@
/**
* Create an orphaned tranaction and store it to the pending database.
- *
- * TODO: Reuse SmashPigBaseTest#createMessage
*/
public function createOrphan( $overrides = array() ) {
- $uniq = mt_rand();
- $message = $overrides + array(
- 'contribution_tracking_id' => $uniq,
- 'country' => 'US',
- 'first_name' => 'Flighty',
- 'last_name' => 'Dono',
- 'email' => '[email protected]',
- 'gateway' => 'globalcollect',
- 'gateway_txn_id' => "txn-{$uniq}",
- 'order_id' => "order-{$uniq}",
- 'gateway_account' => 'default',
- 'payment_method' => 'cc',
- 'payment_submethod' => 'mc',
- // Defaults to a magic 25 minutes ago, within the
process window.
- 'date' => time() - 25 * 60,
- 'gross' => 123,
- 'currency' => 'EUR',
- );
+ $message = parent::createOrphan($overrides);
$this->pendingDb->storeMessage( $message );
return $message;
}
diff --git a/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php
b/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php
index ccb3dfc..1a92a8f 100644
--- a/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php
+++ b/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php
@@ -334,4 +334,11 @@
$messages = self::getLogMatches( 'info', '/Preparing to send
.*/' );
$this->assertEmpty( $messages );
}
+
+ public function testShouldRectifyOrphan(){
+ $message = $this->createOrphan(array('gateway' => 'paypal',
'payment_method' => 'paypal'));
+ $this->gatewayAdapter = $this->getFreshGatewayObject($message);
+ $result = $this->gatewayAdapter->shouldRectifyOrphan();
+ $this->assertEquals($result, true, 'shouldRectifyOrphan returning
false.');
+ }
}
diff --git a/tests/phpunit/DonationInterfaceTestCase.php
b/tests/phpunit/DonationInterfaceTestCase.php
index 7e4c42d..b8f7840 100644
--- a/tests/phpunit/DonationInterfaceTestCase.php
+++ b/tests/phpunit/DonationInterfaceTestCase.php
@@ -722,4 +722,32 @@
unset( $message[$field] );
}
}
+
+ /**
+ * Create an orphaned tranaction.
+ *
+ * TODO: Reuse SmashPigBaseTest#createMessage
+ */
+ public function createOrphan( $overrides = array() ) {
+ $uniq = mt_rand();
+ $message = $overrides + array(
+ 'contribution_tracking_id' => $uniq,
+ 'country' => 'US',
+ 'first_name' => 'Flighty',
+ 'last_name' => 'Dono',
+ 'email' => '[email protected]',
+ 'gateway' => 'globalcollect',
+ 'gateway_txn_id' => "txn-{$uniq}",
+ 'order_id' => "order-{$uniq}",
+ 'gateway_account' => 'default',
+ 'payment_method' => 'cc',
+ 'payment_submethod' => 'mc',
+ // Defaults to a magic 25 minutes ago, within the process
window.
+ 'date' => time() - 25 * 60,
+ 'gross' => 123,
+ 'currency' => 'EUR',
+ );
+ return $message;
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/369996
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1a2a68772b6ae0fea8377bf12ac1efd1b338618d
Gerrit-PatchSet: 31
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Mepps <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: Mepps <[email protected]>
Gerrit-Reviewer: XenoRyet <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits