Index: branches/fundraising/extensions/DonationInterface/gateway_forms/TwoStepAmount.php |
— | — | @@ -27,6 +27,7 @@ |
28 | 28 | global $wgOut; |
29 | 29 | |
30 | 30 | $form_data['transaction_type'] = 'BANK_TRANSFER'; |
| 31 | + //Debug::puke($form_data, eval(DUMP) . "\$form_data"); |
31 | 32 | parent::__construct( $form_data, $form_errors, $gateway ); |
32 | 33 | |
33 | 34 | // 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 @@ |
2 | 2 | <?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 | + */ |
3 | 19 | |
| 20 | +/** |
| 21 | + * GatewayType Interface |
| 22 | + * |
| 23 | + */ |
4 | 24 | interface GatewayType { |
5 | 25 | //all the particulars of the child classes. Aaaaall. |
6 | 26 | |
— | — | @@ -36,7 +56,7 @@ |
37 | 57 | |
38 | 58 | /** |
39 | 59 | * Should be a list of our variables that need special staging. |
40 | | - * Define $this->staged_vars |
| 60 | + * @see $this->staged_vars |
41 | 61 | */ |
42 | 62 | function defineStagedVars(); |
43 | 63 | |
— | — | @@ -74,6 +94,10 @@ |
75 | 95 | function defineReturnValueMap(); |
76 | 96 | } |
77 | 97 | |
| 98 | +/** |
| 99 | + * GatewayAdapter |
| 100 | + * |
| 101 | + */ |
78 | 102 | abstract class GatewayAdapter implements GatewayType { |
79 | 103 | |
80 | 104 | //Contains the map of THEIR var names, to OURS. |
— | — | @@ -91,6 +115,14 @@ |
92 | 116 | * @see GatewayForm::execute() |
93 | 117 | */ |
94 | 118 | 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 | + |
95 | 127 | protected $return_value_map; |
96 | 128 | protected $postdata; |
97 | 129 | protected $postdatadefaults; |
— | — | @@ -108,20 +140,44 @@ |
109 | 141 | const COMMUNICATION_TYPE = 'xml'; //this needs to be either 'xml' or 'namevalue' |
110 | 142 | const GLOBAL_PREFIX = 'wgDonationGateway'; //...for example. |
111 | 143 | |
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 | + |
113 | 166 | if ( !self::getGlobal( 'Test' ) ) { |
114 | 167 | $this->url = self::getGlobal( 'URL' ); |
| 168 | + |
| 169 | + // Only submit test data if we are in test mode. |
| 170 | + $testData = false; |
115 | 171 | } else { |
116 | 172 | $this->url = self::getGlobal( 'TestingURL' ); |
117 | 173 | } |
118 | 174 | |
119 | | - $this->dataObj = new DonationData( get_called_class(), self::getGlobal( 'Test' ) ); |
| 175 | + $this->dataObj = new DonationData( get_called_class(), self::getGlobal( 'Test' ), $testData ); |
120 | 176 | |
121 | 177 | $this->postdata = $this->dataObj->getData(); |
122 | 178 | //TODO: Fix this a bit. |
123 | 179 | $this->posted = $this->dataObj->wasPosted(); |
124 | 180 | |
125 | | - $this->setPostDefaults(); |
| 181 | + $this->setPostDefaults( $postDefaults ); |
126 | 182 | $this->defineTransactions(); |
127 | 183 | $this->defineVarMap(); |
128 | 184 | $this->defineAccountInfo(); |
— | — | @@ -134,17 +190,23 @@ |
135 | 191 | /** |
136 | 192 | * Override this in children if you want different defaults. |
137 | 193 | */ |
138 | | - function setPostDefaults() { |
139 | | - $returnTitle = Title::newFromText( 'Special:GlobalCollectGatewayResult' ); |
140 | | - $returnto = $returnTitle->getFullURL(); |
| 194 | + function setPostDefaults( $options = array() ) { |
141 | 195 | |
| 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 | + |
142 | 204 | $this->postdatadefaults = array( |
143 | 205 | 'order_id' => '112358' . rand(), |
144 | 206 | 'amount' => '11.38', |
145 | 207 | 'currency' => 'USD', |
146 | 208 | 'language' => 'en', |
147 | 209 | 'country' => 'US', |
148 | | - 'returnto' => $returnto, |
| 210 | + 'returnto' => $returnTo, |
149 | 211 | 'user_ip' => ( self::getGlobal( 'Test' ) ) ? '12.12.12.12' : wfGetIP(), // current user's IP address |
150 | 212 | 'card_type' => 'visa', |
151 | 213 | ); |
— | — | @@ -933,6 +995,8 @@ |
934 | 996 | /** |
935 | 997 | * Set the transaction type |
936 | 998 | * |
| 999 | + * @see GatewayAdapter::currentTransaction() |
| 1000 | + * |
937 | 1001 | * @param string|false $transaction_type |
938 | 1002 | */ |
939 | 1003 | public function setTransactionType( $transaction_type ) { |
— | — | @@ -940,6 +1004,8 @@ |
941 | 1005 | $transaction_type = empty( $transaction_type ) ? false : $transaction_type; |
942 | 1006 | |
943 | 1007 | $this->transaction_type = $transaction_type; |
| 1008 | + |
| 1009 | + $this->currentTransaction( $this->transaction_type ); |
944 | 1010 | } |
945 | 1011 | |
946 | 1012 | public function getTransactionAllResults() { |