Index: trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php |
— | — | @@ -277,6 +277,23 @@ |
278 | 278 | */ |
279 | 279 | public function addData( $dataArray ) { |
280 | 280 | $this->dataObj->addData( $dataArray ); |
| 281 | + |
| 282 | + $calculated_fields = $this->dataObj->getCalculatedFields(); |
| 283 | + $data_fields = array_keys( $dataArray ); |
| 284 | + $data_fields = array_merge( $data_fields, $calculated_fields ); |
| 285 | + |
| 286 | + foreach ( $data_fields as $value){ |
| 287 | + $this->refreshGatewayValueFromSource( $value ); |
| 288 | + } |
| 289 | + |
| 290 | + //and now check to see if you have to re-stage. |
| 291 | + //I'd fire off individual staging functions by value, but that's a |
| 292 | + //really bad idea, as multiple staged vars could be used in any staging |
| 293 | + //function, to calculate any other staged var. |
| 294 | + $changed_staged_vars = array_intersect( $this->staged_vars, $data_fields ); |
| 295 | + if ( count( $changed_staged_vars ) ) { |
| 296 | + $this->stageData(); |
| 297 | + } |
281 | 298 | } |
282 | 299 | |
283 | 300 | /** |
— | — | @@ -1313,24 +1330,15 @@ |
1314 | 1331 | } |
1315 | 1332 | |
1316 | 1333 | function getPaypalRedirectURL() { |
1317 | | - $utm_source = $this->getData( 'utm_source' ); |
| 1334 | + $currency = $this->getData( 'currency' ); |
1318 | 1335 | |
1319 | 1336 | // update the utm source to set the payment instrument to pp rather than cc |
1320 | 1337 | $data['payment_method'] = 'pp'; |
1321 | | - $data['currency_code'] = isset( $data['currency'] ) ? $data['currency'] : 'USD'; |
| 1338 | + $data['currency_code'] = ( !is_null( $currency ) ) ? $currency : 'USD'; |
1322 | 1339 | |
1323 | | - // Add our response vars to the data object. |
1324 | | - $this->dataObj->addData( $data ); //addData will, among other things, rebuild the utm_[stuff]. |
1325 | | - // refresh our data |
1326 | | - foreach ( $data as $key => $value){ |
1327 | | - $this->refreshGatewayValueFromSource( $key ); |
1328 | | - } |
1329 | | - //TODO: Make an array of calculated fields in DonationData... |
1330 | | - //in other words: Fields that will get recalculated on a normalizeAndSanitize()... |
1331 | | - //so we don't have to _know_ to do this, when we add data. |
1332 | | - //In fact, put that in addData, and restage anything that's either the explicit key, |
1333 | | - //or any of the calculated keys. |
1334 | | - $this->refreshGatewayValueFromSource( 'utm_source' ); //calculated field! |
| 1340 | + // Add our response vars to the data object, and restage if necessary. |
| 1341 | + $this->addData( $data ); |
| 1342 | + |
1335 | 1343 | //update contribution tracking |
1336 | 1344 | $this->dataObj->updateContributionTracking( true ); |
1337 | 1345 | |
Index: trunk/extensions/DonationInterface/gateway_common/DonationData.php |
— | — | @@ -245,7 +245,33 @@ |
246 | 246 | unset( $this->normalized[$key] ); |
247 | 247 | } |
248 | 248 | } |
| 249 | + |
| 250 | + /** |
| 251 | + * Returns an array of all the fields that get re-calculated during a |
| 252 | + * normalizeAndSanitize. |
| 253 | + * This will most likely be used on the outside when in the process of |
| 254 | + * adding data. |
| 255 | + * @return array An array of values matching all recauculated fields. |
| 256 | + */ |
| 257 | + function getCalculatedFields() { |
| 258 | + $fields = array( |
| 259 | + 'utm_source', |
| 260 | + 'amount', |
| 261 | + 'order_id', |
| 262 | + 'i_order_id', |
| 263 | + 'gateway', |
| 264 | + 'optout', |
| 265 | + 'anonymous', |
| 266 | + 'language', |
| 267 | + 'contribution_tracking_id', //sort of... |
| 268 | + ); |
| 269 | + return $fields; |
| 270 | + } |
249 | 271 | |
| 272 | + /** |
| 273 | + * Normalizes and Sanitizes the current set of data, just after it's been |
| 274 | + * pulled (or re-pulled) from a source. |
| 275 | + */ |
250 | 276 | function normalizeAndSanitize() { |
251 | 277 | if ( !empty( $this->normalized ) ) { |
252 | 278 | $this->setUtmSource(); |