r79217 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79216‎ | r79217 | r79218 >
Date:23:16, 29 December 2010
Author:awjrichards
Status:deferred
Tags:
Comment:
Added rudimentary method for currency conversion (following the same method the WMF uses w/ javascript on donation landing pages to ensure price floor/cieling values are not exceeded) - yes these are hardcoded values, yes this should be done better (ie using a webservice), but we needed a quick-and-dirty way to convert currencies to normalize donation amounts to help with fraud prevention (eg we often see fraudsters enter in values like '99999999999999999999999999' to the amount field); Added currency conversion to amount validtion to ensure that all currencies are (mostly) treated equally
Modified paths:
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
@@ -313,8 +313,8 @@
314314
315315 // check amount
316316 if ( !preg_match( '/^\d+(\.(\d+)?)?$/', $data[ 'amount' ] ) ||
317 - ( (float) $data[ 'amount' ] < (float) $wgPayflowPriceFloor ||
318 - (float) $data[ 'amount' ] > (float) $wgPayflowPriceCieling ) ) {
 317+ ( (float) $this->convert_to_usd( $data[ 'currency_code' ], $data[ 'amount' ] ) <= (float) $wgPayflowPriceFloor ||
 318+ (float) $this->convert_to_usd( $data[ 'currency_code' ], $data[ 'amount' ] ) >= (float) $wgPayflowPriceCieling ) ) {
319319 $error['invalidamount'] = wfMsg( 'payflowpro_gateway-error-msg-invalid-amount' );
320320 $error_result = '1';
321321 }
@@ -1264,4 +1264,82 @@
12651265 syslog( $log_level, $msg );
12661266 closelog();
12671267 }
 1268+
 1269+ /**
 1270+ * Convert an amount for a particular currency to an amount in USD
 1271+ *
 1272+ * This is grosley rudimentary and likely wildly inaccurate.
 1273+ * This mimicks the hard-coded values used by the WMF to convert currencies
 1274+ * for validatoin on the front-end on the first step landing pages of their
 1275+ * donation process - the idea being that we can get a close approximation
 1276+ * of converted currencies to ensure that contributors are not going above
 1277+ * or below the price ceiling/floor, even if they are using a non-US currency.
 1278+ *
 1279+ * In reality, this probably ought to use some sort of webservice to get real-time
 1280+ * conversion rates.
 1281+ *
 1282+ * @param $currency_code
 1283+ * @param $amount
 1284+ * @return unknown_type
 1285+ */
 1286+ public function convert_to_usd( $currency_code, $amount ) {
 1287+ switch ( strtoupper( $currency_code ) ) {
 1288+ case 'USD':
 1289+ $usd_amount = $amount * 1;
 1290+ break;
 1291+ case 'GBP':
 1292+ $usd_amount = $amount * 1;
 1293+ break;
 1294+ case 'EUR':
 1295+ $usd_amount = $amount * 1;
 1296+ break;
 1297+ case 'AUD':
 1298+ $usd_amount = $amount * 2;
 1299+ break;
 1300+ case 'CAD':
 1301+ $usd_amount = $amount * 1;
 1302+ break;
 1303+ case 'CHF':
 1304+ $usd_amount = $amount * 1;
 1305+ break;
 1306+ case 'CZK':
 1307+ $usd_amount = $amount * 20;
 1308+ break;
 1309+ case 'DKK':
 1310+ $usd_amount = $amount * 5;
 1311+ break;
 1312+ case 'HKD':
 1313+ $usd_amount = $amount * 10;
 1314+ break;
 1315+ case 'HUF':
 1316+ $usd_amount = $amount * 200;
 1317+ break;
 1318+ case 'JPY':
 1319+ $usd_amount = $amount * 100;
 1320+ break;
 1321+ case 'NZD':
 1322+ $usd_amount = $amount * 2;
 1323+ break;
 1324+ case 'NOK':
 1325+ $usd_amount = $amount * 10;
 1326+ break;
 1327+ case 'PLN':
 1328+ $usd_amount = $amount * 5;
 1329+ break;
 1330+ case 'SGD':
 1331+ $usd_amount = $amount * 2;
 1332+ break;
 1333+ case 'SEK':
 1334+ $usd_amount = $amount * 10;
 1335+ break;
 1336+ case 'ILS':
 1337+ $usd_amount = $amount * 5;
 1338+ break;
 1339+ default:
 1340+ $usd_amount = $amount;
 1341+ break;
 1342+ }
 1343+
 1344+ return $usd_amount;
 1345+ }
12681346 } // end class
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.php
@@ -147,7 +147,8 @@
148148 $wgPayflowGatewayUseSyslog = false;
149149
150150 /**
151 - * Configure price cieling and floor for valid contribution amount
 151+ * Configure price cieling and floor for valid contribution amount. Values
 152+ * should be in USD.
152153 */
153154 $wgPayflowPriceFloor = '1.00';
154155 $wgPayflowPriceCieling = '10000.00';

Status & tagging log