Index: trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php |
— | — | @@ -1377,18 +1377,41 @@ |
1378 | 1378 | } |
1379 | 1379 | } |
1380 | 1380 | |
1381 | | - function findCodeAction( $transaction, $key, $code ) { |
| 1381 | + /** |
| 1382 | + * findCodeAction |
| 1383 | + * |
| 1384 | + * @param string $transaction |
| 1385 | + * @param string $key The key to lookup in the transaction such as STATUSID |
| 1386 | + * @param integer|string $code This gets converted to an integer if the values is numeric. |
| 1387 | + * |
| 1388 | + * @return null|string Returns the code action if a valid code is supplied. Otherwise, the return is null. |
| 1389 | + */ |
| 1390 | + public function findCodeAction( $transaction, $key, $code ) { |
| 1391 | + |
1382 | 1392 | $this->getStopwatch( __FUNCTION__, true ); |
1383 | | - if ( !array_key_exists( $transaction, $this->return_value_map ) || !array_key_exists( $key, $this->return_value_map[$transaction] ) ) { |
| 1393 | + |
| 1394 | + // Do not allow anything that is not numeric |
| 1395 | + if ( !is_numeric( $code ) ) { |
1384 | 1396 | return null; |
1385 | 1397 | } |
1386 | | - if ( !is_array( $this->return_value_map[$transaction][$key] ) ) { |
| 1398 | + |
| 1399 | + // Cast the code as an integer |
| 1400 | + settype( $code, 'integer'); |
| 1401 | + |
| 1402 | + // Check to see if the transaction is defined |
| 1403 | + if ( !array_key_exists( $transaction, $this->return_value_map ) ) { |
1387 | 1404 | return null; |
1388 | 1405 | } |
| 1406 | + |
| 1407 | + // Verify the key exists within the transaction |
| 1408 | + if ( !array_key_exists( $key, $this->return_value_map[ $transaction ] ) || !is_array( $this->return_value_map[ $transaction ][ $key ] ) ) { |
| 1409 | + return null; |
| 1410 | + } |
| 1411 | + |
1389 | 1412 | //sort the array so we can do this quickly. |
1390 | | - ksort( $this->return_value_map[$transaction][$key], SORT_NUMERIC ); |
| 1413 | + ksort( $this->return_value_map[ $transaction ][ $key ], SORT_NUMERIC ); |
1391 | 1414 | |
1392 | | - $ranges = $this->return_value_map[$transaction][$key]; |
| 1415 | + $ranges = $this->return_value_map[ $transaction ][ $key ]; |
1393 | 1416 | //so, you have a code, which is a number. You also have a numerically sorted array. |
1394 | 1417 | //loop through until you find an upper >= your code. |
1395 | 1418 | //make sure it's in the range, and return the action. |