r83247 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83246‎ | r83247 | r83248 >
Date:22:13, 4 March 2011
Author:awjrichards
Status:deferred
Tags:
Comment:
Changed inconsistent 'orderid' to 'order_id' globally in payflowpro_gateway code; Added internal order id (i_order_id) for more clearly tracking a donation session (why ont just use id? see code comments); Added i_order_id to debug logging statements
Modified paths:
  • /trunk/extensions/DonationInterface/payflowpro_gateway/api_payflowpro_gateway.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/Form.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/RapidHtml.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/html/demo.html (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/includes/payflowUser.inc (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/pfp_api_controller.js (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/payflowpro_gateway/api_payflowpro_gateway.php
@@ -148,7 +148,7 @@
149149 // this try/catch design pattern stolen from ClickTracking/ApiSpecialClickTracking.php
150150 try {
151151 // add dynamic elements to result object
152 - $this->getResult()->addValue( array( 'dynamic_form_elements' ), 'orderid', $order_id );
 152+ $this->getResult()->addValue( array( 'dynamic_form_elements' ), 'order_id', $order_id );
153153 $this->getResult()->addValue( array( 'dynamic_form_elements' ), 'token', $token );
154154 $this->getResult()->addValue( array( 'dynamic_form_elements' ), 'contribution_tracking_id', $contribution_tracking_id );
155155 $this->getResult()->addValue( array( 'dynamic_form_elements' ), 'tracking_data', $tracking_data );
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
@@ -118,7 +118,7 @@
119119
120120 // if _cache_ is requested by the user, do not set a session/token; dynamic data will be loaded via ajax
121121 if ( $wgRequest->getText( '_cache_', false ) ) {
122 - self::log( $payflow_data[ 'order_id' ] . " Cache requested", 'payflowpro_gateway', LOG_DEBUG );
 122+ self::log( $payflow_data[ 'order_id' ] . " " . $payflow_data[ 'i_order_id' ] . " Cache requested", 'payflowpro_gateway', LOG_DEBUG );
123123 $cache = true;
124124 $token = '';
125125 $token_match = false;
@@ -126,7 +126,7 @@
127127 // if we have squid caching enabled, set the maxage
128128 global $wgUseSquid, $wgPayflowSMaxAge;
129129 if ( $wgUseSquid ) {
130 - self::log( $payflow_data[ 'order_id' ] . " Setting s-max-age: " . $wgPayflowSMaxAge, 'payflowpro_gateway', LOG_DEBUG );
 130+ self::log( $payflow_data[ 'order_id' ] . " " . $payflow_data[ 'i_order_id' ] . " Setting s-max-age: " . $wgPayflowSMaxAge, 'payflowpro_gateway', LOG_DEBUG );
131131 $wgOut->setSquidMaxage( $wgPayflowSMaxAge );
132132 }
133133 } else {
@@ -135,21 +135,21 @@
136136 // establish the edit token to prevent csrf
137137 $token = self::fnPayflowEditToken( $wgPayflowGatewaySalt );
138138
139 - self::log( $payflow_data[ 'order_id' ] . " fnPayflowEditToken: " . $token, 'payflowpro_gateway', LOG_DEBUG );
 139+ self::log( $payflow_data[ 'order_id' ] . " " . $payflow_data[ 'i_order_id' ] . " fnPayflowEditToken: " . $token, 'payflowpro_gateway', LOG_DEBUG );
140140
141141 // match token
142142 $token_check = ( $wgRequest->getText( 'token' ) ) ? $wgRequest->getText( 'token' ) : $token;
143143 $token_match = $this->fnPayflowMatchEditToken( $token_check, $wgPayflowGatewaySalt );
144144 if ( $wgRequest->wasPosted() ) {
145 - self::log( $payflow_data[ 'order_id' ] . " Submitted edit token: " . $wgRequest->getText( 'token', 'None' ), 'payflowpro_gateway', LOG_DEBUG);
146 - self::log( $payflow_data[ 'order_id' ] . "Token match: " . $token_match );
 145+ self::log( $payflow_data[ 'order_id' ] . " " . $payflow_data[ 'i_order_id' ] . " Submitted edit token: " . $wgRequest->getText( 'token', 'None' ), 'payflowpro_gateway', LOG_DEBUG);
 146+ self::log( $payflow_data[ 'order_id' ] . " " . $payflow_data[ 'i_order_id' ] . " Token match: " . $token_match, 'payflowpro_gateway', LOG_DEBUG );
147147 }
148148 }
149149
150150 $this->setHeaders();
151151
152152 // Populate form data
153 - $data = $this->fnGetFormData( $amount, $numAttempt, $token, $payflow_data['order_id'] );
 153+ $data = $this->fnGetFormData( $amount, $numAttempt, $token, $payflow_data['order_id'], $payflow_data['i_order_id'] );
154154
155155 /**
156156 * handle PayPal redirection
@@ -953,7 +953,7 @@
954954 * Provides a way to prepopulate the form with test data using $wgPayflowGatewayTest
955955 * @return array
956956 */
957 - public function fnGetFormData( $amount, $numAttempt, $token, $order_id ) {
 957+ public function fnGetFormData( $amount, $numAttempt, $token, $order_id, $i_order_id=0 ) {
958958 global $wgPayflowGatewayTest, $wgRequest;
959959
960960 // fetch ID for the url reference for OWA tracking
@@ -1006,6 +1006,7 @@
10071007 'currency' => 'USD',
10081008 'payment_method' => $wgRequest->getText( 'payment_method' ),
10091009 'order_id' => $order_id,
 1010+ 'i_order_id' => $i_order_id,
10101011 'numAttempt' => $numAttempt,
10111012 'referrer' => 'http://www.baz.test.com/index.php?action=foo&action=bar',
10121013 'utm_source' => self::getUtmSource(),
@@ -1053,6 +1054,7 @@
10541055 'currency' => $wgRequest->getText( 'currency_code' ),
10551056 'payment_method' => $wgRequest->getText( 'payment_method' ),
10561057 'order_id' => $order_id,
 1058+ 'i_order_id' => $i_order_id,
10571059 'numAttempt' => $numAttempt,
10581060 'referrer' => ( $wgRequest->getVal( 'referrer' ) ) ? $wgRequest->getVal( 'referrer' ) : $wgRequest->getHeader( 'referer' ),
10591061 'utm_source' => self::getUtmSource(),
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/Form.php
@@ -358,7 +358,8 @@
359359 'process' => 'CreditCard',
360360 'payment_method' => 'processed',
361361 'token' => $this->form_data[ 'token' ],
362 - 'orderid' => $this->form_data[ 'order_id' ],
 362+ 'order_id' => $this->form_data[ 'order_id' ],
 363+ 'i_order_id' => $this->form_data[ 'i_order_id' ],
363364 'numAttempt' => $this->form_data[ 'numAttempt' ],
364365 'contribution_tracking_id' => $this->form_data[ 'contribution_tracking_id' ],
365366 'data_hash' => $this->form_data[ 'data_hash' ],
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/html/demo.html
@@ -148,7 +148,7 @@
149149 <input type="hidden" value="CreditCard" name="process" />
150150 <input type="hidden" value="processed" name="payment_method" />
151151 <input type="hidden" value="@token" name="token" />
152 - <input type="hidden" value="@orderid" name="orderid" />
 152+ <input type="hidden" value="@order_id" name="order_id" />
153153 <input type="hidden" value="@numAttempt" name="numAttempt" />
154154 <input type="hidden" value="@contribution_tracking_id" name="contribution_tracking_id" />
155155 <input type="hidden" value="@data_hash" name="data_hash" />
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/RapidHtml.php
@@ -33,7 +33,7 @@
3434 '@cvv', // => $wgRequest->getText( 'cvv' ),
3535 '@currency_code', //'currency' => $wgRequest->getText( 'currency_code' ),
3636 '@payment_method', // => $wgRequest->getText( 'payment_method' ),
37 - '@orderid', // => $order_id,
 37+ '@order_id', // => $order_id,
3838 '@numAttempt', // => $numAttempt,
3939 '@referrer', // => ( $wgRequest->getVal( 'referrer' ) ) ? $wgRequest->getVal( 'referrer' ) : $wgRequest->getHeader( 'referer' ),
4040 '@utm_source', // => self::getUtmSource(),
Index: trunk/extensions/DonationInterface/payflowpro_gateway/includes/payflowUser.inc
@@ -26,6 +26,7 @@
2727 'verbosity' => 'MEDIUM', // level of detail in Payflow response
2828 'user_ip' => ( $wgPayflowGatewayTest ) ? '12.12.12.12' : wfGetIP(), // current user's IP address
2929 'order_id' => payflowGetOrderId(),
 30+ 'i_order_id' => payflowGetInternalOrderId(),
3031 );
3132
3233 return $payflow_data;
@@ -33,28 +34,46 @@
3435
3536 /**
3637 * Fetch and return the 'order_id' for a transaction
 38+ *
 39+ * Since transactions to PayPal are initially matched internally on their end
 40+ * with the 'order_id' field, but we don't actually care what the order id is,
 41+ * we generate a sufficiently random number to avoid duplication.
 42+ *
 43+ * We go ahead and always generate a random order id becuse if PayPal detects
 44+ * the same order_id more than once, it considers the request a duplicate, even
 45+ * if the data is completely different.
 46+ *
3747 * @return int
3848 */
3949 function payflowGetOrderId() {
 50+ return generateOrderId();
 51+}
 52+
 53+/**
 54+ * Generate an internal order id
 55+ *
 56+ * This is only used internally for tracking a user's 'session' with the credit
 57+ * card form. I mean 'session' in the sense of the moment a credit card page
 58+ * is loaded for the first time (nothing posted to it - a discrete donation
 59+ * session) as opposed to the $_SESSION - as the $_SESSION id could potentially
 60+ * not change between contribution attempts.
 61+ */
 62+function payflowGetInternalOrderId() {
4063 global $wgRequest;
4164
4265 // is an order_id already set?
43 - $order_id = $wgRequest->getText( 'orderid', 0 );
 66+ $i_order_id = $wgRequest->getText( 'i_order_id', 0 );
4467
4568 // if the form was not just posted OR there's no order_id set, generate one.
46 - if ( !$wgRequest->wasPosted() || !$order_id ) {
47 - $order_id = generateOrderId();
 69+ if ( !$wgRequest->wasPosted() || !$i_order_id ) {
 70+ $i_order_id = generateOrderId();
4871 }
49 -
50 - return $order_id;
 72+
 73+ return $i_order_id;
5174 }
5275
5376 /**
5477 * Generate an order id
55 - *
56 - * Since transactions to PayPal are initially matched internally on their end
57 - * with the 'order_id' field, but we don't actually care what the order id is,
58 - * we generate a sufficiently random number to avoid duplication.
5978 */
6079 function generateOrderId() {
6180 return (double) microtime() * 1000000 . mt_rand();
Index: trunk/extensions/DonationInterface/payflowpro_gateway/pfp_api_controller.js
@@ -3,7 +3,7 @@
44 var tracking_data = {"url": escape(window.location), "pageref": escape(document.referrer)};
55
66 var processFormElements = function (data, status){
7 - $('input[name=orderid]').val(data['dynamic_form_elements']['orderid']);
 7+ $('input[name=order_id]').val(data['dynamic_form_elements']['order_id']);
88 $('input[name=token]').val(data['dynamic_form_elements']['token']);
99 $('input[name=contribution_tracking_id]').val(data['dynamic_form_elements']['contribution_tracking_id']);
1010 $('input[name=utm_source]').val(data['dynamic_form_elements']['tracking_data']['utm_source']);

Status & tagging log