Mepps has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/369996 )
Change subject: WIP rectify orphan function ...................................................................... WIP 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 3 files changed, 99 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/96/369996/1 diff --git a/gateway_common/gateway.adapter.php b/gateway_common/gateway.adapter.php index 4dcdebe..088ab7b 100644 --- a/gateway_common/gateway.adapter.php +++ b/gateway_common/gateway.adapter.php @@ -167,6 +167,7 @@ protected $action; protected $risk_score = 0; public $debugarray; + public $canRectifyOrphan; /** * A boolean that will tell us if we've posted to ourselves. A little more telling than @@ -226,6 +227,8 @@ $this->payment_init_logger = DonationLoggerFactory::getLogger( $this, '_payment_init' ); $this->profiler = DonationLoggerFactory::getProfiler( $this ); + + $this->canRectifyOrphan = false; $this->logger->info( "Creating a new adapter of type: [{$this->getGatewayName()}]" ); @@ -3721,6 +3724,52 @@ return array_merge_recursive( $requiredRules, $transformerRules ); } + public function confirm() { + } + + public function cancel() { + } + + /** + * @return bool is_rectified + * FIXME: Note this will be called by drush <gateway> <date> + */ + public function rectifyOrphan($normalized, $transaction){ + if (!$this->canRectifyOrphan) { + return false; + } + if ( $normalized['payment_method'] !== 'cc' ) { + // Skip other payment methods which shouldn't be in the pending + // queue anyway. See https://phabricator.wikimedia.org/T161160 + $this->logger->info( "Skipping non-credit card pending record." ); + return false; + } + $this->logger->info( "Rectifying orphan: {$normalized['order_id']}" ); + $is_rectified = false; + $this->dataObj = new DonationData( $this, $normalized ); + $this->unstaged_data = $this->dataObj->getData(); + switch ($transaction) { + case 'confirm': + $result = $this->confirm(); + + break; + case 'cancel': + $result = $this->cancel(); + break; + default: + $this->logger->info("$transaction is not a valid transaction"); + return false; + break; + } + $message = $result->getMessage(); + $this->logger->info( "Result message: {$message}" ); + if ($result->getCommunicationStatus()){ + $this->logger->info( $normalized['contribution_tracking_id'] . ': FINAL: ' . $this->adapter->getValidationAction() ); + $is_rectified = true; + } + return $is_rectified; + } + /** * @return PaymentTransactionResponse */ diff --git a/paypal_gateway/express_checkout/paypal_express.adapter.php b/paypal_gateway/express_checkout/paypal_express.adapter.php index 5c6f0fd..e15a7f2 100644 --- a/paypal_gateway/express_checkout/paypal_express.adapter.php +++ b/paypal_gateway/express_checkout/paypal_express.adapter.php @@ -587,4 +587,12 @@ public function getTransactionGatewayTxnID() { return $this->getData_Unstaged_Escaped( 'gateway_txn_id' ); } + + public function confirm() { + $this->do_transaction('DoExpressCheckoutPayment'); + } + + public function cancel() { + //$this->do_transaction + } } diff --git a/tests/phpunit/Adapter/GatewayAdapterTest.php b/tests/phpunit/Adapter/GatewayAdapterTest.php index fceb832..87cde34 100644 --- a/tests/phpunit/Adapter/GatewayAdapterTest.php +++ b/tests/phpunit/Adapter/GatewayAdapterTest.php @@ -17,6 +17,7 @@ */ use Wikimedia\TestingAccessWrapper; +use SmashPig\Core\DataStores\PendingDatabase; /** * TODO: Test everything. @@ -37,6 +38,8 @@ */ class DonationInterface_Adapter_GatewayAdapterTest extends DonationInterfaceTestCase { + public $pendingDb; + /** * @param $name string The name of the test case * @param $data array Any parameters read from a dataProvider @@ -47,6 +50,12 @@ global $wgDonationInterfaceTest; $wgDonationInterfaceTest = true; parent::__construct( $name, $data, $dataName ); + //FIXME: not sure why this isn't working + try { + $this->pendingDb = PendingDatabase::get(); + } catch (Exception $e) { + print_r($e->getMessage()); + } } public function setUp() { @@ -334,5 +343,38 @@ $gateway->setValidationAction( 'process' ); $this->assertEquals( 'reject', $gateway->getValidationAction(), 'De-escalating action without reset!' ); } + + public function testRectifyOrphan(){ + $data = $this->getDonorTestData(); + $gateway = $this->getFreshGatewayObject($data); + $gateway->canRectifyOrphan = true; + $normalized = $this->createOrphan($gateway::IDENTIFIER); + $is_rectified = $gateway->rectifyOrphan($normalized, 'confirm'); + $this->assertEquals($is_rectified, true, 'Orphan was rectified'); + //FIXME: delete orphan + } + + public function createOrphan( $gateway = 'default' ){ + $uniq = mt_rand(); + $message = array( + 'contribution_tracking_id' => $uniq, + 'country' => 'US', + 'first_name' => 'Flighty', + 'last_name' => 'Dono', + 'email' => 'test+...@eff.org', + 'gateway' => $gateway, + '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', + ); + $this->pendingDb->storeMessage( $message ); + + } } -- To view, visit https://gerrit.wikimedia.org/r/369996 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1a2a68772b6ae0fea8377bf12ac1efd1b338618d 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