r98479 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98478‎ | r98479 | r98480 >
Date:22:27, 29 September 2011
Author:jpostlethwaite
Status:resolved (Comments)
Tags:fundraising 
Comment:
Added helper execute methods to process different transaction types. The new type added was BANK_TRANSFER.
Modified paths:
  • /branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php (modified) (history)

Diff [purge]

Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php
@@ -13,6 +13,11 @@
1414 /**
1515 * Show the special page
1616 *
 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+ *
1722 * @param $par Mixed: parameter passed to the page or null
1823 */
1924 public function execute( $par ) {
@@ -56,7 +61,24 @@
5762 //TODO: This is short-circuiting what I really want to do here.
5863 //so stop it.
5964 $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+
6183 // dispatch forms/handling
6284 if ( $this->adapter->checkTokens() ) {
6385 if ( $this->adapter->posted && $data['payment_method'] == 'processed' ) {
@@ -66,40 +88,51 @@
6789 // increase the count of attempts
6890 //++$data['numAttempt'];
6991 // 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 );
71110
 111+ //$form_errors = $this->fnValidateForm( $data, $this->errors );
 112+
72113 // If there were errors, redisplay form, otherwise proceed to next step
73114 if ( $form_errors ) {
 115+
74116 $this->displayForm( $data, $this->errors );
75117 } else { // The submitted form data is valid, so process it
76118 // 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' );
80119
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 );
100135 }
101136
102 -
103 -
104137 // self::log( $data[ 'order_id' ] . " Preparing to query MaxMind" );
105138 // wfRunHooks( 'PayflowGatewayValidate', array( &$this, &$data ) );
106139 // self::log( $data[ 'order_id' ] . ' Finished querying Maxmind' );
@@ -156,6 +189,52 @@
157190 }
158191
159192 /**
 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+ /**
160239 * Interpret response code, return
161240 * 1 if approved
162241 * 2 if declined

Follow-up revisions

RevisionCommit summaryAuthorDate
r99279Using global variable for $wgOut instead of passing a reference. See r98479.jpostlethwaite22:56, 7 October 2011

Comments

#Comment by Awjrichards (talk | contribs)   22:38, 7 October 2011
public function executeBankTransfer( &$wgOut ) {

Why are you passing $wgOut by reference here? It doesn't appear to be used in this function.

+	public function executeInsertOrderWithPayment( &$wgOut ) {

Similar question. The typical convention would be to do:

public function executeInsertOrderWithPayment() {
    global $wgOut;
    ....
#Comment by Jpostlethwaite (talk | contribs)   22:58, 7 October 2011

Using global variable for $wgOut instead of passing a reference. See r98479.

Status & tagging log