| Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php |
| — | — | @@ -13,6 +13,11 @@ |
| 14 | 14 | /** |
| 15 | 15 | * Show the special page |
| 16 | 16 | * |
| | 17 | + * @todo |
| | 18 | + * - Add transaction type handler |
| | 19 | + * - What should a failure on transaction_type issues do? log & message client |
| | 20 | + * - Set up BANK_TRANSFER: Story #308 |
| | 21 | + * |
| 17 | 22 | * @param $par Mixed: parameter passed to the page or null |
| 18 | 23 | */ |
| 19 | 24 | public function execute( $par ) { |
| — | — | @@ -56,7 +61,24 @@ |
| 57 | 62 | //TODO: This is short-circuiting what I really want to do here. |
| 58 | 63 | //so stop it. |
| 59 | 64 | $data = $this->adapter->getDisplayData(); |
| 60 | | - |
| | 65 | + |
| | 66 | + /* |
| | 67 | + * The $transactionType should default to false. |
| | 68 | + * |
| | 69 | + * This is being introduced after INSERT_ORDERWITHPAYMENT was built. |
| | 70 | + * Until all INSERT_ORDERWITHPAYMENT can be set in the proper forms, it |
| | 71 | + * will be set as the default. |
| | 72 | + */ |
| | 73 | + $transactionType = false; |
| | 74 | + $transactionType = 'INSERT_ORDERWITHPAYMENT'; |
| | 75 | + $data['transaction_type'] = isset( $data['transaction_type'] ) ? $data['transaction_type'] : $transactionType; |
| | 76 | + $this->adapter->setTransactionType( $data['transaction_type'] ); |
| | 77 | + unset( $transactionType ); |
| | 78 | + |
| | 79 | + $this->adapter->log( '$transactionType: Default is set to: INSERT_ORDERWITHPAYMENT, this is a temporary hack for backwards compatibility.' ); |
| | 80 | + $this->adapter->log( 'Setting transaction type: ' . (string) $data['transaction_type'] ); |
| | 81 | + |
| | 82 | + |
| 61 | 83 | // dispatch forms/handling |
| 62 | 84 | if ( $this->adapter->checkTokens() ) { |
| 63 | 85 | if ( $this->adapter->posted && $data['payment_method'] == 'processed' ) { |
| — | — | @@ -66,40 +88,51 @@ |
| 67 | 89 | // increase the count of attempts |
| 68 | 90 | //++$data['numAttempt']; |
| 69 | 91 | // Check form for errors |
| 70 | | - $form_errors = $this->fnValidateForm( $data, $this->errors ); |
| | 92 | + |
| | 93 | + $options = array(); |
| | 94 | + switch ( $this->adapter->getTransactionType() ) { |
| | 95 | + |
| | 96 | + case 'BANK_TRANSFER': |
| | 97 | + $options['creditCard'] = false; |
| | 98 | + break; |
| | 99 | + |
| | 100 | + case 'INSERT_ORDERWITHPAYMENT': |
| | 101 | + $options['creditCard'] = true; |
| | 102 | + break; |
| | 103 | + |
| | 104 | + default: |
| | 105 | + $options['creditCard'] = true; |
| | 106 | + } |
| | 107 | + |
| | 108 | + $form_errors = $this->validateForm( $data, $this->errors, $options ); |
| | 109 | + unset( $options ); |
| 71 | 110 | |
| | 111 | + //$form_errors = $this->fnValidateForm( $data, $this->errors ); |
| | 112 | + |
| 72 | 113 | // If there were errors, redisplay form, otherwise proceed to next step |
| 73 | 114 | if ( $form_errors ) { |
| | 115 | + |
| 74 | 116 | $this->displayForm( $data, $this->errors ); |
| 75 | 117 | } else { // The submitted form data is valid, so process it |
| 76 | 118 | // allow any external validators to have their way with the data |
| 77 | | - $result = $this->adapter->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); |
| 78 | | - $this->adapter->addDonorDataToSession(); |
| 79 | | - //$result = $this->adapter->do_transaction( 'TEST_CONNECTION' ); |
| 80 | 119 | |
| 81 | | - $this->displayResultsForDebug( $result ); |
| 82 | | - |
| 83 | | - if ( !empty( $result['data'] ) ) { |
| 84 | | - |
| 85 | | - if ( array_key_exists( 'FORMACTION', $result['data'] ) ) { |
| 86 | | - $paymentFrame = Xml::openElement( 'iframe', array( |
| 87 | | - 'id' => 'globalcollectframe', |
| 88 | | - 'name' => 'globalcollectframe', |
| 89 | | - 'width' => '680', |
| 90 | | - 'height' => '300', |
| 91 | | - 'frameborder' => '0', |
| 92 | | - 'style' => 'display:block;', |
| 93 | | - 'src' => $result['data']['FORMACTION'] |
| 94 | | - ) |
| 95 | | - ); |
| 96 | | - $paymentFrame .= Xml::closeElement( 'iframe' ); |
| 97 | | - |
| 98 | | - $wgOut->addHTML( $paymentFrame ); |
| 99 | | - } |
| | 120 | + // Execute the proper transaction code: |
| | 121 | + switch ( $this->adapter->getTransactionType() ) { |
| | 122 | + |
| | 123 | + case 'BANK_TRANSFER': |
| | 124 | + $this->executeBankTransfer( $wgOut ); |
| | 125 | + break; |
| | 126 | + |
| | 127 | + case 'INSERT_ORDERWITHPAYMENT': |
| | 128 | + $this->executeInsertOrderWithPayment( $wgOut ); |
| | 129 | + break; |
| | 130 | + |
| | 131 | + default: |
| | 132 | + |
| | 133 | + $message = 'The transaction type [ ' . $this->adapter->getTransactionType() . ' ] was not found.'; |
| | 134 | + throw new Exception( $message ); |
| 100 | 135 | } |
| 101 | 136 | |
| 102 | | - |
| 103 | | - |
| 104 | 137 | // self::log( $data[ 'order_id' ] . " Preparing to query MaxMind" ); |
| 105 | 138 | // wfRunHooks( 'PayflowGatewayValidate', array( &$this, &$data ) ); |
| 106 | 139 | // self::log( $data[ 'order_id' ] . ' Finished querying Maxmind' ); |
| — | — | @@ -156,6 +189,52 @@ |
| 157 | 190 | } |
| 158 | 191 | |
| 159 | 192 | /** |
| | 193 | + * Execute BANK_TRANSFER |
| | 194 | + * |
| | 195 | + * @param OutputPage $wgOut |
| | 196 | + */ |
| | 197 | + public function executeBankTransfer( &$wgOut ) { |
| | 198 | + |
| | 199 | + $result = $this->adapter->do_transaction( 'BANK_TRANSFER' ); |
| | 200 | + $this->adapter->addDonorDataToSession(); |
| | 201 | + |
| | 202 | + $this->displayResultsForDebug( $result ); |
| | 203 | + } |
| | 204 | + |
| | 205 | + /** |
| | 206 | + * Execute INSERT_ORDERWITHPAYMENT |
| | 207 | + * |
| | 208 | + * @param OutputPage $wgOut |
| | 209 | + */ |
| | 210 | + public function executeInsertOrderWithPayment( &$wgOut ) { |
| | 211 | + |
| | 212 | + $result = $this->adapter->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); |
| | 213 | + $this->adapter->addDonorDataToSession(); |
| | 214 | + //$result = $this->adapter->do_transaction( 'TEST_CONNECTION' ); |
| | 215 | + |
| | 216 | + $this->displayResultsForDebug( $result ); |
| | 217 | + |
| | 218 | + if ( !empty( $result['data'] ) ) { |
| | 219 | + |
| | 220 | + if ( array_key_exists( 'FORMACTION', $result['data'] ) ) { |
| | 221 | + $paymentFrame = Xml::openElement( 'iframe', array( |
| | 222 | + 'id' => 'globalcollectframe', |
| | 223 | + 'name' => 'globalcollectframe', |
| | 224 | + 'width' => '680', |
| | 225 | + 'height' => '300', |
| | 226 | + 'frameborder' => '0', |
| | 227 | + 'style' => 'display:block;', |
| | 228 | + 'src' => $result['data']['FORMACTION'] |
| | 229 | + ) |
| | 230 | + ); |
| | 231 | + $paymentFrame .= Xml::closeElement( 'iframe' ); |
| | 232 | + |
| | 233 | + $wgOut->addHTML( $paymentFrame ); |
| | 234 | + } |
| | 235 | + } |
| | 236 | + } |
| | 237 | + |
| | 238 | + /** |
| 160 | 239 | * Interpret response code, return |
| 161 | 240 | * 1 if approved |
| 162 | 241 | * 2 if declined |