r99253 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99252‎ | r99253 | r99254 >
Date:21:05, 7 October 2011
Author:jpostlethwaite
Status:deferred (Comments)
Tags:fundraising 
Comment:
Adding transaction type code and optional parameters for unit testing.
Modified paths:
  • /branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_forms/TwoStepAmount.php (modified) (history)

Diff [purge]

Index: branches/fundraising/extensions/DonationInterface/gateway_forms/TwoStepAmount.php
@@ -27,6 +27,7 @@
2828 global $wgOut;
2929
3030 $form_data['transaction_type'] = 'BANK_TRANSFER';
 31+ //Debug::puke($form_data, eval(DUMP) . "\$form_data");
3132 parent::__construct( $form_data, $form_errors, $gateway );
3233
3334 // we only want to load this JS if the form is being rendered
Index: branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -1,5 +1,25 @@
22 <?php
 3+/**
 4+ * Wikimedia Foundation
 5+ *
 6+ * LICENSE
 7+ *
 8+ * This program is free software; you can redistribute it and/or modify
 9+ * it under the terms of the GNU General Public License as published by
 10+ * the Free Software Foundation; either version 2 of the License, or
 11+ * (at your option) any later version.
 12+ *
 13+ * This program is distributed in the hope that it will be useful,
 14+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 16+ * GNU General Public License for more details.
 17+ *
 18+ */
319
 20+/**
 21+ * GatewayType Interface
 22+ *
 23+ */
424 interface GatewayType {
525 //all the particulars of the child classes. Aaaaall.
626
@@ -36,7 +56,7 @@
3757
3858 /**
3959 * Should be a list of our variables that need special staging.
40 - * Define $this->staged_vars
 60+ * @see $this->staged_vars
4161 */
4262 function defineStagedVars();
4363
@@ -74,6 +94,10 @@
7595 function defineReturnValueMap();
7696 }
7797
 98+/**
 99+ * GatewayAdapter
 100+ *
 101+ */
78102 abstract class GatewayAdapter implements GatewayType {
79103
80104 //Contains the map of THEIR var names, to OURS.
@@ -91,6 +115,14 @@
92116 * @see GatewayForm::execute()
93117 */
94118 protected $transaction_type = false;
 119+
 120+ /**
 121+ * Staged variables. This is affected by the transaction type.
 122+ *
 123+ * @var array $staged_vars
 124+ */
 125+ protected $staged_vars = array();
 126+
95127 protected $return_value_map;
96128 protected $postdata;
97129 protected $postdatadefaults;
@@ -108,20 +140,44 @@
109141 const COMMUNICATION_TYPE = 'xml'; //this needs to be either 'xml' or 'namevalue'
110142 const GLOBAL_PREFIX = 'wgDonationGateway'; //...for example.
111143
112 - public function __construct() {
 144+ /**
 145+ * Constructor
 146+ *
 147+ * @param array $options
 148+ * OPTIONAL - You may set options for testing
 149+ * - testData - Submit test data
 150+ *
 151+ * @see DonationData
 152+ */
 153+ public function __construct( $options = array() ) {
 154+
 155+ // Extract the options
 156+ extract( $options );
 157+
 158+ $testData = isset( $testData ) ? $testData : false;
 159+ $postDefaults = isset( $postDefaults ) ? $postDefaults : false;
 160+ $transactionType = isset( $transactionType ) ? $transactionType : false;
 161+
 162+ if ( $transactionType ) {
 163+ $this->setTransactionType( $transactionType );
 164+ }
 165+
113166 if ( !self::getGlobal( 'Test' ) ) {
114167 $this->url = self::getGlobal( 'URL' );
 168+
 169+ // Only submit test data if we are in test mode.
 170+ $testData = false;
115171 } else {
116172 $this->url = self::getGlobal( 'TestingURL' );
117173 }
118174
119 - $this->dataObj = new DonationData( get_called_class(), self::getGlobal( 'Test' ) );
 175+ $this->dataObj = new DonationData( get_called_class(), self::getGlobal( 'Test' ), $testData );
120176
121177 $this->postdata = $this->dataObj->getData();
122178 //TODO: Fix this a bit.
123179 $this->posted = $this->dataObj->wasPosted();
124180
125 - $this->setPostDefaults();
 181+ $this->setPostDefaults( $postDefaults );
126182 $this->defineTransactions();
127183 $this->defineVarMap();
128184 $this->defineAccountInfo();
@@ -134,17 +190,23 @@
135191 /**
136192 * Override this in children if you want different defaults.
137193 */
138 - function setPostDefaults() {
139 - $returnTitle = Title::newFromText( 'Special:GlobalCollectGatewayResult' );
140 - $returnto = $returnTitle->getFullURL();
 194+ function setPostDefaults( $options = array() ) {
141195
 196+ // Extract the options
 197+ if ( is_array( $options )) {
 198+ extract( $options );
 199+ }
 200+
 201+ $returnTitle = isset( $returnTitle ) ? $returnTitle : Title::newFromText( 'Special:GlobalCollectGatewayResult' );
 202+ $returnTo = isset( $returnTo ) ? $returnTo : $returnTitle->getFullURL();
 203+
142204 $this->postdatadefaults = array(
143205 'order_id' => '112358' . rand(),
144206 'amount' => '11.38',
145207 'currency' => 'USD',
146208 'language' => 'en',
147209 'country' => 'US',
148 - 'returnto' => $returnto,
 210+ 'returnto' => $returnTo,
149211 'user_ip' => ( self::getGlobal( 'Test' ) ) ? '12.12.12.12' : wfGetIP(), // current user's IP address
150212 'card_type' => 'visa',
151213 );
@@ -933,6 +995,8 @@
934996 /**
935997 * Set the transaction type
936998 *
 999+ * @see GatewayAdapter::currentTransaction()
 1000+ *
9371001 * @param string|false $transaction_type
9381002 */
9391003 public function setTransactionType( $transaction_type ) {
@@ -940,6 +1004,8 @@
9411005 $transaction_type = empty( $transaction_type ) ? false : $transaction_type;
9421006
9431007 $this->transaction_type = $transaction_type;
 1008+
 1009+ $this->currentTransaction( $this->transaction_type );
9441010 }
9451011
9461012 public function getTransactionAllResults() {

Follow-up revisions

RevisionCommit summaryAuthorDate
r99255Adding transaction type code and optional parameters for unit testing.jpostlethwaite21:06, 7 October 2011

Comments

#Comment by Jpostlethwaite (talk | contribs)   21:11, 7 October 2011

TwoStepAmount.php was not supposed to be committed with debugging information. Debug code was removed.

Status & tagging log