Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php |
— | — | @@ -313,8 +313,8 @@ |
314 | 314 | |
315 | 315 | // check amount |
316 | 316 | 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 ) ) { |
319 | 319 | $error['invalidamount'] = wfMsg( 'payflowpro_gateway-error-msg-invalid-amount' ); |
320 | 320 | $error_result = '1'; |
321 | 321 | } |
— | — | @@ -1264,4 +1264,82 @@ |
1265 | 1265 | syslog( $log_level, $msg ); |
1266 | 1266 | closelog(); |
1267 | 1267 | } |
| 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 | + } |
1268 | 1346 | } // end class |
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.php |
— | — | @@ -147,7 +147,8 @@ |
148 | 148 | $wgPayflowGatewayUseSyslog = false; |
149 | 149 | |
150 | 150 | /** |
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. |
152 | 153 | */ |
153 | 154 | $wgPayflowPriceFloor = '1.00'; |
154 | 155 | $wgPayflowPriceCieling = '10000.00'; |