http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73833
Revision: 73833
Author: awjrichards
Date: 2010-09-27 23:11:21 +0000 (Mon, 27 Sep 2010)
Log Message:
-----------
Updated utm_source handling code in gateway assign single-step cc form as
landing page and assign payment type to utm_source if not already set; Added
some clearer commenting for gwStomp hook; form cleanup fixes; removed static
delimiters for regexes in filters; values for comment options now carry over on
two column letter form; opt-in options on forms decoupled from opt-out options
in contrib_tracking table
Modified Paths:
--------------
trunk/extensions/DonationInterface/payflowpro_gateway/extras/custom_filters/filters/referrer/referrer.body.php
trunk/extensions/DonationInterface/payflowpro_gateway/extras/custom_filters/filters/source/source.body.php
trunk/extensions/DonationInterface/payflowpro_gateway/extras/minfraud/minfraud.body.php
trunk/extensions/DonationInterface/payflowpro_gateway/forms/Form.php
trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumn.php
trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumnLetter.php
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.css
Modified:
trunk/extensions/DonationInterface/payflowpro_gateway/extras/custom_filters/filters/referrer/referrer.body.php
===================================================================
---
trunk/extensions/DonationInterface/payflowpro_gateway/extras/custom_filters/filters/referrer/referrer.body.php
2010-09-27 23:11:19 UTC (rev 73832)
+++
trunk/extensions/DonationInterface/payflowpro_gateway/extras/custom_filters/filters/referrer/referrer.body.php
2010-09-27 23:11:21 UTC (rev 73833)
@@ -25,7 +25,11 @@
// a very complex filtering algorithm for referrers
global $wgCustomFiltersRefRules;
foreach ( $wgCustomFiltersRefRules as $regex =>
$risk_score_modifier ) {
- if( preg_match( "/$regex/", $referrer )) {
+ /**
+ * note that the regex pattern does NOT include
delimiters.
+ * these will need to be included in your custom regex
patterns.
+ */
+ if( preg_match( "$regex", $referrer )) {
$this->cfo->risk_score += $risk_score_modifier;
// log it
Modified:
trunk/extensions/DonationInterface/payflowpro_gateway/extras/custom_filters/filters/source/source.body.php
===================================================================
---
trunk/extensions/DonationInterface/payflowpro_gateway/extras/custom_filters/filters/source/source.body.php
2010-09-27 23:11:19 UTC (rev 73832)
+++
trunk/extensions/DonationInterface/payflowpro_gateway/extras/custom_filters/filters/source/source.body.php
2010-09-27 23:11:21 UTC (rev 73833)
@@ -25,7 +25,11 @@
// a very complex filtering algorithm for sources
global $wgCustomFiltersSrcRules;
foreach ( $wgCustomFiltersSrcRules as $regex =>
$risk_score_modifier ) {
- if( preg_match( "/$regex/", $source )) {
+ /**
+ * Note that regex pattern does not include delimiters.
+ * These will need to be included your custom regex
patterns.
+ */
+ if( preg_match( "$regex", $source )) {
$this->cfo->risk_score += $risk_score_modifier;
// log it
Modified: trunk/extensions/DonationInterface/payflowpro_gateway/forms/Form.php
===================================================================
--- trunk/extensions/DonationInterface/payflowpro_gateway/forms/Form.php
2010-09-27 23:11:19 UTC (rev 73832)
+++ trunk/extensions/DonationInterface/payflowpro_gateway/forms/Form.php
2010-09-27 23:11:21 UTC (rev 73833)
@@ -260,8 +260,8 @@
'language' => $this->form_data[ 'language' ],
'referrer' => $this->form_data[ 'referrer' ],
'comment' => $this->form_data[ 'comment' ],
- 'comment-option' => $this->form_data[
'anonymous' ],
- 'email' => $this->form_data[ 'optout' ],
+ 'comment-option' => $this->form_data[
'comment-option' ],
+ 'email-opt' => $this->form_data[ 'email-opt' ],
'process' => 'CreditCard',
'payment_method' => 'processed',
'token' => $this->form_data[ 'token' ],
Modified:
trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumn.php
===================================================================
--- trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumn.php
2010-09-27 23:11:19 UTC (rev 73832)
+++ trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumn.php
2010-09-27 23:11:21 UTC (rev 73833)
@@ -3,18 +3,22 @@
class PayflowProGateway_Form_TwoColumn extends PayflowProGateway_Form {
public function __construct( &$form_data, &$form_errors ) {
+ global $wgOut, $wgScriptPath;
+
parent::__construct( $form_data, $form_errors );
+
+ // we only want to load this JS if the form is being rendered
+ $wgOut->addHeadItem( 'validatescript', '<script
type="text/javascript" src="' .
+ $wgScriptPath .
+
'/extensions/DonationInterface/payflowpro_gateway/validate_input.js"></script>'
);
}
public function generateFormStart() {
global $wgPayflowGatewayHeader, $wgPayflwGatewayTest, $wgOut;
$form = $this->generateBannerHeader();
- $form .= Xml::openElement( 'div', array( 'id' =>
'mw-creditcard' ) ); /*.
- Xml::openElement( 'div', array( 'id' =>
'mw-creditcard-intro' ) ) .
- Xml::tags( 'p', array( 'class' =>
'mw-creditcard-intro-msg' ), wfMsg( 'payflowpro_gateway-form-message' ) ) .
- Xml::closeElement( 'div' );*/
-
+ $form .= Xml::openElement( 'div', array( 'id' =>
'mw-creditcard' ) );
+
// provide a place at the top of the form for displaying
general messages
if ( $this->form_errors['general'] ) {
$form .= Xml::openElement( 'div', array( 'id' =>
'mw-payflow-general-error' ));
@@ -30,6 +34,7 @@
// open form
$form .= Xml::openElement( 'div', array( 'id' =>
'mw-creditcard-form' ) );
+
// Xml::element seems to convert html to htmlentities
$form .= "<p class='creditcard-error-msg'>" .
$this->form_errors['retryMsg'] . "</p>";
$form .= Xml::openElement( 'form', array( 'name' => 'payment',
'method' => 'post', 'action' => '', 'onsubmit' => 'return validate_form(this)',
'autocomplete' => 'off' ) );
@@ -104,13 +109,6 @@
'<span class="creditcard-error-msg">' . ' ' .
$this->form_errors['fname'] . '</span></td>';
$form .= "</tr>";
- /*// middle name
- $form .= '<tr>';
- $form .= '<td>' . Xml::label( wfMsg(
'payflowpro_gateway-donor-mname' ), 'mname' ) . '</td>';
- $form .= '<td>' . Xml::input( 'mname', '30',
$this->form_data['mname'], array( 'maxlength' => '15', 'id' => 'mname' ) ) .
'</td>';
- $form .= '</tr>';
- */
-
// last name
$form .= '<tr>';
$form .= '<td>' . Xml::label( wfMsg(
'payflowpro_gateway-donor-lname' ), 'lname' ) . '</td>';
Modified:
trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumnLetter.php
===================================================================
---
trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumnLetter.php
2010-09-27 23:11:19 UTC (rev 73832)
+++
trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumnLetter.php
2010-09-27 23:11:21 UTC (rev 73833)
@@ -2,15 +2,16 @@
class PayflowProGateway_Form_TwoColumnLetter extends
PayflowProGateway_Form_TwoColumn {
- public function __construct( &$form_data, &$form_errors ) {
- global $wgOut, $wgScriptPath;
- parent::__construct( $form_data, $form_errors );
+ public function __construct( &$form_data, &$form_errors ) {
+ global $wgOut, $wgScriptPath;
+ parent::__construct( $form_data, $form_errors );
- // add form-specific css
- $wgOut->addExtensionStyle( $wgScriptPath .
'/extensions/DonationInterface/payflowpro_gateway/forms/css/TwoColumnLetter.css');
+ // add form-specific css
+ $wgOut->addExtensionStyle( $wgScriptPath .
'/extensions/DonationInterface/payflowpro_gateway/forms/css/TwoColumnLetter.css');
+ // update the list of hidden fields we need to use in this form.
$this->updateHiddenFields();
- }
+ }
public function generateFormStart() {
global $wgOut, $wgRequest;
@@ -20,6 +21,29 @@
$form .= Xml::openElement( 'div', array( 'id' =>
'payflowpro_gateway-cc_form_form', 'class' =>
'payflowpro_gateway-cc_form_column'));
$form .= Xml::Tags( 'p', array( 'id' =>
'payflowpro_gateway-cc_otherways' ), wfMsg( 'payflowpro_gateway-otherways' ));
+
+ $form .= Xml::openElement( 'div', array( 'id' =>
'mw-creditcard' ) );
+
+ // provide a place at the top of the form for displaying
general messages
+ if ( $this->form_errors['general'] ) {
+ $form .= Xml::openElement( 'div', array( 'id' =>
'mw-payflow-general-error' ));
+ if ( is_array( $this->form_errors['general'] )) {
+ foreach ( $this->form_errors['general'] as
$this->form_errors_msg ) {
+ $form .= Xml::tags( 'p', array( 'class'
=> 'creditcard-error-msg' ), $this->form_errors_msg );
+ }
+ } else {
+ $form .= Xml::tags( 'p', array( 'class' =>
'creditcard-error-msg' ), $this->form_errors_msg );
+ }
+ $form .= Xml::closeElement( 'div' );
+ }
+
+ // open form
+ $form .= Xml::openElement( 'div', array( 'id' =>
'mw-creditcard-form' ) );
+
+ // Xml::element seems to convert html to htmlentities
+ $form .= "<p class='creditcard-error-msg'>" .
$this->form_errors['retryMsg'] . "</p>";
+ $form .= Xml::openElement( 'form', array( 'name' => 'payment',
'method' => 'post', 'action' => '', 'onsubmit' => 'return validate_form(this)',
'autocomplete' => 'off' ) );
+
$form .= parent::generatePersonalContainer();
$form .= parent::generatePaymentContainer();
$form .= $this->generateCommentFields();
@@ -55,6 +79,8 @@
}
public function generateCommentFields() {
+ global $wgRequest;
+
$form = Xml::openElement( 'div', array( 'class' =>
'payflow-cc-form-section', 'id' => 'payflowpro_gateway-comment_form' ));
$form .= Xml::tags( 'h3', array( 'class' =>
'payflow-cc-form-header', 'id' => 'payflow-cc-form-header-comments' ), wfMsg(
'donate_interface-comment-title' ));
$form .= Xml::tags( 'p', array(), wfMsg(
'donate_interface-comment-message' ));
@@ -63,18 +89,20 @@
//comment
$form .= '<tr>';
$form .= '<td>' . Xml::label(
wfMsg('donate_interface-comment-label'), 'comment' ) . '</td>';
- $form .= '<td>' . Xml::input( 'comment', '30', '', array(
'maxlength' => '200' )) . '</td>';
+ $form .= '<td>' . Xml::input( 'comment', '30',
$this->form_data[ 'comment' ], array( 'maxlength' => '200' )) . '</td>';
$form .= '</tr>';
// anonymous
+ $comment_opt_value = ( $this->form_data[ 'numAttempt' ] ) ?
$this->form_data[ 'comment-option' ] : true;
$form .= '<tr>';
- $form .= '<td>' . Xml::check( 'comment-option', TRUE ) .
'</td>';
+ $form .= '<td>' . Xml::check( 'comment-option',
$comment_opt_value ) . '</td>';
$form .= '<td>' . Xml::label( wfMsg(
'donate_interface-anon-message' ), 'comment-option' ) . '</td>';
$form .= '</tr>';
// email agreement
+ $email_opt_value = ( $this->form_data[ 'numAttempt' ]) ?
$this->form_data[ 'email-opt' ] : true;
$form .= '<tr>';
- $form .= '<td>' . Xml::check( 'email-opt', TRUE ) . '</td>';
+ $form .= '<td>' . Xml::check( 'email-opt', $email_opt_value ) .
'</td>';
$form .= '<td>' . Xml::label( wfMsg(
'donate_interface-email-agreement' ), 'email-opt' ) . '</td>';
$form .= '</tr>';
@@ -88,10 +116,14 @@
*/
public function updateHiddenFields() {
$hidden_fields = $this->getHiddenFields();
- $not_needed = array( 'comment-option', 'email', 'comment' );
+
+ // make sure that the below elements are not set in the hidden
fields
+ $not_needed = array( 'comment-option', 'email-opt', 'comment' );
+
foreach ( $not_needed as $field ) {
unset( $hidden_fields[ $field ] );
}
+
$this->setHiddenFields( $hidden_fields );
}
}
Modified:
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
===================================================================
---
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
2010-09-27 23:11:19 UTC (rev 73832)
+++
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
2010-09-27 23:11:21 UTC (rev 73833)
@@ -99,7 +99,7 @@
}
// track the number of attempts the user has made
- $numAttempt = ( $wgRequest->getText( 'numAttempt' ) == '' ) ?
'0' : $wgRequest->getText( 'numAttempt' );
+ $numAttempt = $wgRequest->getVal( 'numAttempt', 0 );
// Get array of default account values necessary for Payflow
require_once( 'includes/payflowUser.inc' );
@@ -108,7 +108,6 @@
// Populate form data
$data = $this->fnGetFormData( $amount, $numAttempt, $token,
$payflow_data['order_id'] );
-
// Check form for errors and display
// match token
$token_check = ( $wgRequest->getText( 'token' ) ) ?
$wgRequest->getText( 'token' ) : $token;
@@ -177,12 +176,7 @@
* The message at the top of the form can be edited in the
payflow_gateway.i18.php file
*/
public function fnPayflowDisplayForm( &$data, &$error ) {
- global $wgOut, $wgScriptPath;
-
- // we only want to load this JS if the form is being rendered
- $wgOut->addHeadItem( 'validatescript', '<script
type="text/javascript" src="' .
- $wgScriptPath .
-
'/extensions/DonationInterface/payflowpro_gateway/validate_input.js"></script>'
);
+ global $wgOut;
// save contrib tracking id early to track abondonment
if ( $data[ 'numAttempt' ] == '0' ) {
@@ -691,9 +685,22 @@
$this->fnPayflowUnsetEditToken();
}
+ /**
+ * Determine proper opt-out settings for contribution tracking
+ *
+ * because the form elements for comment anonymization and email opt-out
+ * are backwards (they are really opt-in) relative to
contribution_tracking
+ * (which is opt-out), we need to reverse the values
+ */
+ function determineOptOut( $data ) {
+ $optout[ 'email' ] = ($data['email-opt'] == "1") ? '0' : '1';
+ $optout[ 'anonymous' ] = ($data['comment-option'] == "1") ? '0'
: '1';
+ return $optout;
+ }
+
function fnPayflowSaveContributionTracking( &$data ) {
- $data['optout'] = ($data['optout'] == "1") ? '0' : '1';
- $data['anonymous'] = ($data['anonymous'] == "1") ? '0' : '1';
+ // determine opt-out settings
+ $optout = $this->determineOptOut( $data );
$db = payflowGatewayConnection();
@@ -704,11 +711,11 @@
$tracked_contribution = array(
'note' => $data['comment'],
'referrer' => $data['referrer'],
- 'anonymous' => $data['anonymous'],
+ 'anonymous' => $optout[ 'anonymous' ],
'utm_source' => $data['utm_source'],
'utm_medium' => $data['utm_medium'],
'utm_campaign' => $data['utm_campaign'],
- 'optout' => $data['optout'],
+ 'optout' => $optout[ 'email' ],
'language' => $data['language'],
'ts' => $ts,
);
@@ -724,8 +731,9 @@
if ($db->insert( 'contribution_tracking', $tracked_contribution
) ) {
$data['contribution_tracking_id'] = $db->insertId();
return true;
- } else { return false; }
-
+ } else {
+ return false;
+ }
}
function fnPayflowReturnCurrencies() {
@@ -826,7 +834,9 @@
*/
public function fnGetFormData( $amount, $numAttempt, $token, $order_id
) {
global $wgPayflowGatewayTest, $wgRequest;
- if ( !$numAttempt && $wgPayflowGatewayTest ) { // if we're in
testing mode, prepopulate the form
+
+ // if we're in testing mode and an action hasn't yet be
specified, prepopulate the form
+ if ( !$wgRequest->getText( 'action', false ) && !$numAttempt &&
$wgPayflowGatewayTest ) {
// define arrays of cc's and cc #s for random selection
$cards = array( 'american' );
$card_nums = array(
@@ -835,14 +845,14 @@
),
);
- // randomly select a credit cards
+ // randomly select a credit card
$card_index = array_rand( $cards );
// randomly select a credit card #
$card_num_index = array_rand( $card_nums[ $cards[
$card_index ]] );
$data = array(
- 'amount' => $amount,
+ 'amount' => ( $amount != "0.00" ) ? $amount :
"30.00",
'email' => '[email protected]',
'fname' => 'Tester',
'mname' => 'T.',
@@ -861,13 +871,13 @@
'order_id' => $order_id,
'numAttempt' => $numAttempt,
'referrer' =>
'http://www.baz.test.com/index.php?action=foo&action=bar',
- 'utm_source' => '.Spam.Support.cc',
+ 'utm_source' => $wgRequest->getText(
'utm_source', '.Spam.Support.cc' ),
'utm_medium' => $wgRequest->getText(
'utm_medium' ),
'utm_campaign' => $wgRequest->getText(
'utm_campaign' ),
'language' => 'en',
- 'comment' => 'This sure is neat',
- 'anonymous' => $wgRequest->getText(
'comment-option' ),
- 'optout' => $wgRequest->getText( 'email' ),
+ 'comment' => ($wgRequest->getVal( 'comment' ))
? $wgRequest->getVal( 'comment' ) : 'This sure is neat',
+ 'comment-option' => $wgRequest->getText(
'comment-option' ),
+ 'email-opt' => $wgRequest->getText( 'email-opt'
),
'test_string' => $wgRequest->getText( 'process'
),
'token' => $token,
'contribution_tracking_id' =>
$wgRequest->getText( 'contribution_tracking_id' ),
@@ -900,8 +910,8 @@
'utm_campaign' => $wgRequest->getText(
'utm_campaign' ),
'language' => $wgRequest->getText( 'language' ),
'comment' => $wgRequest->getText( 'comment' ),
- 'anonymous' => $wgRequest->getText(
'comment-option' ),
- 'optout' => $wgRequest->getText( 'email-opt' ),
+ 'comment-option' => $wgRequest->getText(
'comment-option' ),
+ 'email-opt' => $wgRequest->getText( 'email-opt'
),
'test_string' => $wgRequest->getText( 'process'
), //for showing payflow string during testing
'token' => $token,
'contribution_tracking_id' =>
$wgRequest->getText( 'contribution_tracking_id' ),
@@ -939,6 +949,8 @@
* anything cc form related is out of place for the utm_source, this
* will fix it.
*
+ * the utm_source is structured as:
banner.landing_page.payment_instrument
+ *
* @return string The full utm_source
*/
public function getUtmSource() {
@@ -947,27 +959,35 @@
// fetch whatever was passed in as the utm_source
$utm_source = $wgRequest->getText( 'utm_source' );
- // split the utm_source into its parts for closer examination
+ /**
+ * if we have a utm_source_id, then the user is on a
single-step credit card form.
+ * if that's the case, we treat the single-step credit card
form as a landing page,
+ * which we label as cc#, where # = the utm_source_id
+ */
+ $utm_source_id = $wgRequest->getVal( 'utm_source_id', 0 );
+
+ // this is how the CC portion of the utm_source should be
defined
+ $correct_cc_source = ( $utm_source_id ) ? 'cc' . $utm_source_id
. '.cc' : 'cc';
+
+ // check to see if the utm_source is already correct - if so,
return
+ if ( preg_match('/' . str_replace( ".", "\.",
$correct_cc_source ) . '$/', $utm_source)) {
+ return $utm_source;
+ }
+
+ // split the utm_source into its parts for easier manipulation
$source_parts = explode( ".", $utm_source );
-
- $cc_match = false;
- $utm_source_id = $wgRequest->getVal( 'utm_source_id' );
-
- // check the utm_source bits to see if cc has been added yet
- foreach ( $source_parts as $key => $value ) {
- if ( preg_match( '/^cc/', $value ) ) {
- // append utm_source_id if we have it
- $source_parts[ $key ] = 'cc' . $utm_source_id;
- $cc_match = true;
- break;
- }
- }
-
- // if cc hasn't been added yet, add it with the utm_source_id
- if ( !$cc_match ) {
- $source_parts[] = 'cc' . $utm_source_id;
- }
-
+
+ // if there are no sourceparts element, then the banner portion
of the string needs to be set.
+ // since we don't know what it is, set it to an empty string
+ if ( !count( $source_parts )) $source_parts[0] = '';
+
+ // if the utm_source_id is set, set the landing page portion of
the string to cc#
+ $source_parts[1] = ( $utm_source_id ) ? 'cc' . $utm_source_id :
( isset( $source_parts[1] ) ? $source_parts[1] : '');
+
+ // the payment instrument portion should always be 'cc' if this
method is being accessed
+ $source_parts[2] = 'cc';
+
+ // return a reconstructed string
return implode( ".", $source_parts );
}
@@ -991,8 +1011,8 @@
return;
}
- $data['optout'] = ($data['optout'] == "1") ? '0' : '1';
- $data['anonymous'] = ($data['anonymous'] == "1") ? '0' : '1';
+ // determine opt-out settings
+ $optout = $this->determineOptOut( $data );
$db = payflowGatewayConnection();
@@ -1001,11 +1021,11 @@
$tracked_contribution = array(
'note' => $data['comment'],
'referrer' => $data['referrer'],
- 'anonymous' => $data['anonymous'],
+ 'anonymous' => $optout[ 'anonymous' ],
'utm_source' => $data['utm_source'],
'utm_medium' => $data['utm_medium'],
'utm_campaign' => $data['utm_campaign'],
- 'optout' => $data['optout'],
+ 'optout' => $optout[ 'email '],
'language' => $data['language'],
);
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs