Index: trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php |
— | — | @@ -102,6 +102,17 @@ |
103 | 103 | abstract class GatewayAdapter implements GatewayType { |
104 | 104 | |
105 | 105 | /** |
| 106 | + * $dataConstraints provides information on how to handle variables. |
| 107 | + * |
| 108 | + * <code> |
| 109 | + * 'account_holder' => array( 'type' => 'alphanumeric', 'length' => 50, ) |
| 110 | + * </code> |
| 111 | + * |
| 112 | + * @var array $dataConstraints |
| 113 | + */ |
| 114 | + protected $dataConstraints = array(); |
| 115 | + |
| 116 | + /** |
106 | 117 | * $error_map maps gateway errors to client errors |
107 | 118 | * |
108 | 119 | * The index of each error should map to a translation: |
— | — | @@ -216,6 +227,7 @@ |
217 | 228 | $this->defineTransactions(); |
218 | 229 | $this->defineErrorMap(); |
219 | 230 | $this->defineVarMap(); |
| 231 | + $this->defineDataConstraints(); |
220 | 232 | $this->defineAccountInfo(); |
221 | 233 | $this->defineReturnValueMap(); |
222 | 234 | |
— | — | @@ -1509,7 +1521,7 @@ |
1510 | 1522 | * @param type $type Whatever types of staging you feel like having in your child class. |
1511 | 1523 | * ...but usually request and response. I think. |
1512 | 1524 | */ |
1513 | | - function stageData( $type = 'request' ) { |
| 1525 | + public function stageData( $type = 'request' ) { |
1514 | 1526 | $this->defineStagedVars(); |
1515 | 1527 | $this->smooshVarsForStaging(); //yup, we do need to do this seperately. |
1516 | 1528 | //If we tried to piggyback off the same loop, all the vars wouldn't be ready, and some staging functions will require |
— | — | @@ -1518,8 +1530,44 @@ |
1519 | 1531 | $function_name = 'stage_' . $field; |
1520 | 1532 | $this->executeIfFunctionExists( $function_name, $type ); |
1521 | 1533 | } |
| 1534 | + |
| 1535 | + // Format the staged data |
| 1536 | + $this->formatStagedData(); |
| 1537 | + |
1522 | 1538 | } |
1523 | 1539 | |
| 1540 | + /** |
| 1541 | + * Format staged data |
| 1542 | + * |
| 1543 | + * Formatting: |
| 1544 | + * - trim - all strings |
| 1545 | + * - truncate - all strings to the maximum length permitted by the gateway |
| 1546 | + */ |
| 1547 | + public function formatStagedData() { |
| 1548 | + |
| 1549 | + foreach ( $this->staged_data as $field => $value ) { |
| 1550 | + |
| 1551 | + // Trim all values if they are a string |
| 1552 | + $value = is_string( $value ) ? trim( $value ) : $value; |
| 1553 | + |
| 1554 | + if ( isset( $this->dataConstraints[ $field ] ) && is_string( $value ) ) { |
| 1555 | + |
| 1556 | + // Truncate the field if it has a length specified |
| 1557 | + $length = isset( $this->dataConstraints[ $field ]['length']) ? (integer) $this->dataConstraints[ $field ]['length'] : false; |
| 1558 | + |
| 1559 | + if ( !empty( $length ) && !empty( $value ) ) { |
| 1560 | + $value = substr( $value, 0, $length ); |
| 1561 | + } |
| 1562 | + } |
| 1563 | + else { |
| 1564 | + |
| 1565 | + $this->log( 'Field does not exist in $this->dataConstraints[ ' . ( string ) $field . ' ]', LOG_DEBUG ); |
| 1566 | + } |
| 1567 | + |
| 1568 | + $this->staged_data[ $field ] = $value; |
| 1569 | + } |
| 1570 | + } |
| 1571 | + |
1524 | 1572 | function getPaypalRedirectURL() { |
1525 | 1573 | $currency = $this->getData_Raw( 'currency_code' ); |
1526 | 1574 | |