r101648 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101647‎ | r101648 | r101649 >
Date:18:17, 2 November 2011
Author:awjrichards
Status:deferred
Tags:
Comment:
Modified paths:
  • /branches/fundraising/deployment/payments_1.17/extensions/DonationInterface (modified) (history)
  • /branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/gateway_common/DonationData.php (modified) (history)
  • /branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/gateway_forms (modified) (history)
  • /branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/gateway_forms/Form.php (modified) (history)
  • /branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/gateway_forms/includes/payflowUser.inc (deleted) (history)
  • /branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/payflowpro_gateway (modified) (history)
  • /branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/payflowpro_gateway/api_payflowpro_gateway.php (modified) (history)
  • /branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/payflowpro_gateway/forms (modified) (history)
  • /branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js (modified) (history)
  • /branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php (modified) (history)
  • /branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/payflowpro_gateway/pfp_api_controller.js (modified) (history)
  • /branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/tests (modified) (history)
  • /branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/tests/DonationDataTestCase.php (modified) (history)

Diff [purge]

Index: branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/tests/DonationDataTestCase.php
@@ -317,7 +317,7 @@
318318 public static function ensureSession() {
319319 public function checkTokens() {
320320 function wasPosted(){
321 - public static function getUtmSource( $utm_source = null, $utm_source_id = null ) {
 321+ function setUtmSource() {
322322 public function getOptOuts() {
323323 public function getCleanTrackingData( $clean_optouts = false ) {
324324 function saveContributionTracking() {
Property changes on: branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/tests
___________________________________________________________________
Modified: svn:mergeinfo
325325 Merged /trunk/extensions/DonationInterface/tests:r101441
Index: branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/payflowpro_gateway/api_payflowpro_gateway.php
@@ -2,7 +2,7 @@
33 /**
44 * PayflowPro Gateway API extension
55 * Call with api.php?action=pfp
6 - * TODO: Determine if this is being used by anything anymore, and if so, what.
 6+ * TODO: Move this somewhere that looks more gateway-agnostic.
77 */
88
99 class ApiPayflowProGateway extends ApiBase {
@@ -11,7 +11,7 @@
1212 * An array of valid dispatch methods
1313 */
1414 public $validDispatchMethods = array( 'dispatch_get_required_dynamic_form_elements' );
15 -
 15+
1616 /**
1717 * API for PayflowProGateway extension
1818 *
@@ -26,7 +26,7 @@
2727 // extract and validate the parameters
2828 $params = $this->extractRequestParams();
2929 $this->validateParams( $params );
30 -
 30+
3131 // route 'dispatch' requests to the appropriate method
3232 if ( strlen( $params[ 'dispatch' ] ) ) {
3333 $method = $this->getDispatchMethod( $params[ 'dispatch' ] );
@@ -48,6 +48,12 @@
4949 'tracking_data' => array(
5050 ApiBase::PARAM_TYPE => 'string',
5151 ),
 52+ 'gateway' => array(
 53+ ApiBase::PARAM_TYPE => 'string',
 54+ ),
 55+ 'payment_method' => array(
 56+ ApiBase::PARAM_TYPE => 'string',
 57+ ),
5258 );
5359 }
5460
@@ -55,6 +61,8 @@
5662 return array(
5763 'dispatch' => 'the API method from which to return data',
5864 'tracking_data' => 'A JSON formatted string of data to insert into contribution_tracking',
 65+ 'gateway' => 'The current gateway',
 66+ 'payment_method' => 'The current payment method'
5967 );
6068 }
6169
@@ -73,7 +81,7 @@
7482 if ( isset( $params[ 'dispatch' ] ) && strlen( $params[ 'dispatch' ] ) ) {
7583 $method = $this->getDispatchMethod( $params[ 'dispatch' ] );
7684 if ( !in_array( $method, $this->validDispatchMethods ) || !method_exists( $this, $method ) ) {
77 - $this->dieUsage( "Invalid dispatch method <<<$method>>> passed to the PayflowPro Gatweay API.", 'unknown_method' );
 85+ $this->dieUsage( "Invalid dispatch method <<<$method>>> passed to the Donation Interface Gateway API.", 'unknown_method' );
7886 }
7987
8088 // make sure we have tracking data for get_required_dynamic_form_elements
@@ -122,18 +130,21 @@
123131 * elements.
124132 */
125133 protected function dispatch_get_required_dynamic_form_elements( $params ) {
126 - global $wgPayflowProGatewaySalt;
127134
128 - // fetch the order_id
129 - //TODO: This include should be *very* deprecated. All the functionality there has been
130 - //recently eaten by gateway.adapter.php and DontationData.php.
131 - require_once( 'includes/payflowUser.inc' );
132 - $payflow_data = payflowUser();
133 - $order_id = $payflow_data[ 'order_id' ];
134 -
135 - // fetch the CSRF prevention token and set it if it's not already set
136 - $token = PayflowProGateway::fnPayflowEditToken( $wgPayflowProGatewaySalt );
137 -
 135+ //Get the gateway class name. We don't need to instantiate: Just get the name
 136+ //so we can get a new DonationData that *thinks* it's being instantiated by
 137+ //the relevent gateway class.
 138+ $gateway_class = '';
 139+ switch ( $params['gateway'] ){
 140+ case 'globalcollect' :
 141+ $gateway_class = 'GlobalCollectAdapter';
 142+ break;
 143+ case 'payflowpro' :
 144+ default:
 145+ $gateway_class = 'PayflowProAdapter';
 146+ break;
 147+ }
 148+
138149 /**
139150 * retrieve and unpack the json encoded string of tracking data
140151 *
@@ -142,12 +153,17 @@
143154 * pageref => the url-encoded referrer to the full user-requested URL
144155 */
145156 $tracking_data = $this->parseTrackingData( json_decode( $params[ 'tracking_data' ], true ) );
 157+ //instantiate a new DonationData that behaves like it's owned by the correct gateway.
 158+ $donationDataObj = new DonationData( $gateway_class, false, $tracking_data );
 159+ // fetch the order_id
 160+ $order_id = $donationDataObj->getVal( 'order_id' );
146161
147 - // clean up tracking data to make sure everything is set correctly
148 - $tracking_data = PayflowProGateway::cleanTrackingData( $tracking_data, true );
 162+ // fetch the CSRF prevention token and set it if it's not already set
 163+ $token = $donationDataObj->token_getSaltedSessionToken();
149164
150 - // fetch the contribution_tracking_id by inserting tracking data to contrib tracking table
151 - $contribution_tracking_id = PayflowProGateway::insertContributionTracking( $tracking_data );
 165+ //I'd just call DD's saveContributionTracking, but we need all the parts out here.
 166+ $tracking_data = $donationDataObj->getCleanTrackingData();
 167+ $contribution_tracking_id = $donationDataObj::insertContributionTracking( $tracking_data );
152168
153169 // this try/catch design pattern stolen from ClickTracking/ApiSpecialClickTracking.php
154170 try {
@@ -175,11 +191,7 @@
176192 // add the referrer to the tracked_data array
177193 $tracking_data[ 'referrer' ] = urldecode( $unparsed_tracking_data[ 'pageref' ] );
178194
179 - // ensure the utm_source is formatted correctly
180 - $utm_source_str = ( isset( $tracking_data[ 'utm_source' ] ) ) ? $tracking_data[ 'utm_source' ] : null;
181 - $utm_source_id = ( isset( $tracking_data[ 'utm_source_id' ] ) ) ? $tracking_data[ 'utm_source_id' ] : null;
182 - $tracking_data[ 'utm_source' ] = PayflowProGateway::getUtmSource( $utm_source_str, $utm_source_id );
183 -
 195+ //DonationData handles the utm normalization now.
184196 return $tracking_data;
185197 }
186198
Index: branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
@@ -40,7 +40,7 @@
4141
4242 // dispatch forms/handling
4343 if ( $this->adapter->checkTokens() ) {
44 - if ( $this->adapter->posted) {
 44+ if ( $this->adapter->posted ) {
4545 // The form was submitted and the payment method has been set
4646 // Check form for errors
4747 $form_errors = $this->validateForm( $this->errors );
Index: branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js
@@ -147,7 +147,7 @@
148148 'zip': $( "input[name='zip']" ).val(),
149149 'emailAdd': $( "input[name='emailAdd']" ).val(),
150150 'country': $( "input[name='country']" ).val(),
151 - 'payment_method': 'card',
 151+ 'payment_method': 'cc',
152152 'language': 'en',
153153
154154 'expiration': $( "input[name='expiration']" ).val(),
Property changes on: branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/payflowpro_gateway/forms
___________________________________________________________________
Modified: svn:mergeinfo
155155 Merged /trunk/extensions/DonationInterface/payflowpro_gateway/forms:r101441
Index: branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/payflowpro_gateway/pfp_api_controller.js
@@ -17,7 +17,11 @@
1818 'action' : 'pfp',
1919 'dispatch' : 'get_required_dynamic_form_elements',
2020 'format' : 'json',
21 - 'tracking_data' : '{"url": "'+escape(window.location)+'", "pageref": "'+escape(document.referrer)+'"}'
 21+ 'tracking_data' : '{"url": "'+escape(window.location)+
 22+ '", "pageref": "'+escape(document.referrer)+
 23+ '", "gateway": "'+escape(document.gateway)+
 24+ '", "payment_method": "'+escape(document.payment_method)+
 25+ '"}'
2226 }, processFormElements, 'json' );
2327 };
2428
Property changes on: branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/payflowpro_gateway
___________________________________________________________________
Modified: svn:mergeinfo
2529 Merged /trunk/extensions/DonationInterface/payflowpro_gateway:r101441,101502
Index: branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/gateway_forms/Form.php
@@ -423,6 +423,7 @@
424424 'action' => $this->form_data['action'],
425425 'owa_session' => $this->form_data['owa_session'],
426426 'owa_ref' => $this->form_data['owa_ref'],
 427+ 'gateway' => $this->form_data['gateway'],
427428 );
428429 }
429430
Index: branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/gateway_forms/includes/payflowUser.inc
@@ -1,80 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Payflow Pro account information
6 - * Payflow individual account information must be defined in the LocalSettings.php file
7 - */
8 -function payflowUser() {
9 - // User account information from LocalSettings.php
10 - global $wgPayflowProPartnerID,
11 - $wgPayflowProVendorID,
12 - $wgPayflowProUserID,
13 - $wgPayflowProPassword,
14 - $wgPayflowProURL,
15 - $wgPayflowProTestingURL,
16 - $wgPayflowGatewayTest;
17 -
18 - $payflow_data = array(
19 - 'partner' => $wgPayflowProPartnerID, // PayPal or original authorized reseller
20 - 'vendor' => $wgPayflowProVendorID, // paypal merchant login ID
21 - 'user' => $wgPayflowProUserID, // if one or more users are set up, authorized user ID, else same as VENDOR
22 - 'password' => $wgPayflowProPassword, // merchant login password
23 - 'paypalurl' => $wgPayflowProURL,
24 - 'testingurl' => $wgPayflowProTestingURL, // Payflow testing URL
25 - 'trxtype' => 'S', // transaction type - all donations are a sale
26 - 'tender' => 'C', // credit card - all transactions in this case are credit cards
27 - 'verbosity' => 'MEDIUM', // level of detail in Payflow response
28 - 'user_ip' => ( $wgPayflowGatewayTest ) ? '12.12.12.12' : wfGetIP(), // current user's IP address
29 - 'order_id' => payflowGetOrderId(),
30 - 'i_order_id' => payflowGetInternalOrderId(),
31 - );
32 -
33 - return $payflow_data;
34 -}
35 -
36 -/**
37 - * 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 - *
47 - * @return int
48 - */
49 -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() {
63 - global $wgRequest;
64 -
65 - // is an order_id already set?
66 - $i_order_id = $wgRequest->getText( 'i_order_id', 0 );
67 -
68 - // if the form was not just posted OR there's no order_id set, generate one.
69 - if ( !$wgRequest->wasPosted() || !$i_order_id ) {
70 - $i_order_id = generateOrderId();
71 - }
72 -
73 - return $i_order_id;
74 -}
75 -
76 -/**
77 - * Generate an order id
78 - */
79 -function generateOrderId() {
80 - return (double) microtime() * 1000000 . mt_rand();
81 -}
\ No newline at end of file
Property changes on: branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/gateway_forms
___________________________________________________________________
Modified: svn:mergeinfo
821 Merged /trunk/extensions/DonationInterface/gateway_forms:r101441,101502
Index: branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/gateway_common/DonationData.php
@@ -64,7 +64,8 @@
6565 'i_order_id' => $wgRequest->getText( 'i_order_id', null ), //internal id for each contribution attempt
6666 'numAttempt' => $wgRequest->getVal( 'numAttempt', '0' ),
6767 'referrer' => ( $wgRequest->getVal( 'referrer' ) ) ? $wgRequest->getVal( 'referrer' ) : $wgRequest->getHeader( 'referer' ),
68 - 'utm_source' => self::getUtmSource(), //TODO: yes. That.
 68+ 'utm_source' => $wgRequest->getText( 'utm_source' ),
 69+ 'utm_source_id' => $wgRequest->getVal( 'utm_source_id', null ),
6970 'utm_medium' => $wgRequest->getText( 'utm_medium' ),
7071 'utm_campaign' => $wgRequest->getText( 'utm_campaign' ),
7172 // try to honor the user-set language (uselang), otherwise the language set in the URL (language)
@@ -154,59 +155,58 @@
155156 // randomly select a credit card #
156157 $card_num_index = array_rand( $card_nums[$cards[$card_index]] );
157158
158 - global $wgRequest; //TODO: ARRRGHARGHARGH. That is all.
159 -
160 - $this->normalized = array(
161 - 'amount' => "35",
162 - 'amountOther' => '',
163 - 'email' => 'test@example.com',
164 - 'fname' => 'Tester',
165 - 'mname' => 'T.',
166 - 'lname' => 'Testington',
167 - 'street' => '548 Market St.',
168 - 'city' => 'San Francisco',
169 - 'state' => 'CA',
170 - 'zip' => '94104',
171 - 'country' => 'US',
172 - 'fname2' => 'Testy',
173 - 'lname2' => 'Testerson',
174 - 'street2' => '123 Telegraph Ave.',
175 - 'city2' => 'Berkeley',
176 - 'state2' => 'CA',
177 - 'zip2' => '94703',
178 - 'country2' => 'US',
179 - 'size' => 'small',
180 - 'premium_language' => 'es',
181 - 'card_num' => $card_nums[$cards[$card_index]][$card_num_index],
182 - 'card_type' => $cards[$card_index],
183 - 'expiration' => date( 'my', strtotime( '+1 year 1 month' ) ),
184 - 'cvv' => '001',
185 - 'currency' => 'USD',
186 - 'payment_method' => $wgRequest->getText( 'payment_method' ),
187 - 'payment_submethod' => $wgRequest->getText( 'payment_submethod' ),
188 - 'issuer_id' => $wgRequest->getText( 'issuer_id' ),
189 - 'order_id' => '1234567890',
190 - 'i_order_id' => '1234567890',
191 - 'numAttempt' => 0,
192 - 'referrer' => 'http://www.baz.test.com/index.php?action=foo&action=bar',
193 - 'utm_source' => self::getUtmSource(),
194 - 'utm_medium' => $wgRequest->getText( 'utm_medium' ),
195 - 'utm_campaign' => $wgRequest->getText( 'utm_campaign' ),
196 - 'language' => 'en',
197 - 'comment-option' => $wgRequest->getText( 'comment-option' ),
198 - 'comment' => $wgRequest->getText( 'comment' ),
199 - 'email-opt' => $wgRequest->getText( 'email-opt' ),
200 - // test_string has been disabled - may no longer be needed.
201 - //'test_string' => $wgRequest->getText( 'process' ),
202 - 'token' => '',
203 - 'contribution_tracking_id' => $wgRequest->getText( 'contribution_tracking_id' ),
204 - 'data_hash' => $wgRequest->getText( 'data_hash' ),
205 - 'action' => $wgRequest->getText( 'action' ),
206 - 'gateway' => 'payflowpro',
207 - 'owa_session' => $wgRequest->getText( 'owa_session', null ),
208 - 'owa_ref' => 'http://localhost/defaultTestData',
209 - );
210 - }
 159+ //This array should be populated with general test defaults, or
 160+ //(preferably) mappings to random stuff... if we keep this around at all.
 161+ //Certainly nothing pulled from a form post or get.
 162+ $this->normalized = array(
 163+ 'amount' => "35",
 164+ 'amountOther' => '',
 165+ 'email' => 'test@example.com',
 166+ 'fname' => 'Tester',
 167+ 'mname' => 'T.',
 168+ 'lname' => 'Testington',
 169+ 'street' => '548 Market St.',
 170+ 'city' => 'San Francisco',
 171+ 'state' => 'CA',
 172+ 'zip' => '94104',
 173+ 'country' => 'US',
 174+ 'fname2' => 'Testy',
 175+ 'lname2' => 'Testerson',
 176+ 'street2' => '123 Telegraph Ave.',
 177+ 'city2' => 'Berkeley',
 178+ 'state2' => 'CA',
 179+ 'zip2' => '94703',
 180+ 'country2' => 'US',
 181+ 'size' => 'small',
 182+ 'premium_language' => 'es',
 183+ 'card_num' => $card_nums[$cards[$card_index]][$card_num_index],
 184+ 'card_type' => $cards[$card_index],
 185+ 'expiration' => date( 'my', strtotime( '+1 year 1 month' ) ),
 186+ 'cvv' => '001',
 187+ 'currency' => 'USD',
 188+ 'payment_method' => 'cc',
 189+ 'payment_submethod' => '', //cards have no payment submethods.
 190+ 'issuer_id' => '',
 191+ 'order_id' => '1234567890',
 192+ 'i_order_id' => '1234567890',
 193+ 'numAttempt' => 0,
 194+ 'referrer' => 'http://www.baz.test.com/index.php?action=foo&action=bar',
 195+ 'utm_source' => 'test_src',
 196+ 'utm_source_id' => null,
 197+ 'utm_medium' => 'test_medium',
 198+ 'utm_campaign' => 'test_campaign',
 199+ 'language' => 'en',
 200+ 'comment-option' => 0,
 201+ 'comment' => 0,
 202+ 'email-opt' => 0,
 203+ 'token' => '',
 204+ 'contribution_tracking_id' => '',
 205+ 'data_hash' => '',
 206+ 'action' => '',
 207+ 'gateway' => 'payflowpro',
 208+ 'owa_session' => '',
 209+ 'owa_ref' => 'http://localhost/defaultTestData',
 210+ );
211211 }
212212
213213 /**
@@ -280,7 +280,17 @@
281281 $this->saveContributionTracking();
282282 }
283283 }
284 -
 284+
 285+
 286+ function canCache(){
 287+ if ( $this->getVal( '_cache_' ) === 'true' ){ //::head. hit. keyboard.::
 288+ if ( $this->isSomething( 'utm_source_id' ) && !is_null( 'utm_source_id' ) ){
 289+ return true;
 290+ }
 291+ }
 292+ return false;
 293+ }
 294+
285295 /**
286296 * normalizeAndSanitize helper function.
287297 * Takes all possible sources for the intended donation amount, and
Property changes on: branches/fundraising/deployment/payments_1.17/extensions/DonationInterface
___________________________________________________________________
Modified: svn:mergeinfo
288298 Merged /trunk/extensions/DonationInterface:r101441,101502,101631

Follow-up revisions

RevisionCommit summaryAuthorDate
r101673Revert r101648 - bad mergeawjrichards20:22, 2 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r101441Fixes the api calls that handle gateway forms with _cache_ set to true, and a...khorn00:07, 1 November 2011
r101502Actually fixes the api calls that handle gateway forms with _cache_ set to tr...khorn17:14, 1 November 2011
r101631Defaults utm_source_id to null on a form pull, and checks for not null for ca...khorn15:50, 2 November 2011

Status & tagging log