r103514 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103513‎ | r103514 | r103515 >
Date:22:15, 17 November 2011
Author:jpostlethwaite
Status:resolved (Comments)
Tags:
Comment:
Fixing issue with currency JPY. The amount is floored for the last two digits.
Modified paths:
  • /trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
@@ -1726,6 +1726,24 @@
17271727 }
17281728
17291729 /**
 1730+ * Floor the amount
 1731+ *
 1732+ * Some amounts for GlobalCollect cannot have cents. We will not round up.
 1733+ *
 1734+ * For example: JPY 1000.05 get changed to 100005. This need to be 100000.
 1735+ * For example: JPY 1000.95 get changed to 100095. This need to be 100000.
 1736+ *
 1737+ *
 1738+ * @param string $value
 1739+ */
 1740+ protected function floorAmount( $value ) {
 1741+
 1742+ $value = substr( $value, 0, -2 ) . '00';
 1743+
 1744+ return $value;
 1745+ }
 1746+
 1747+ /**
17301748 * Stage: amount
17311749 *
17321750 * @param string $type request|response
@@ -1733,7 +1751,20 @@
17341752 protected function stage_amount( $type = 'request' ) {
17351753 switch ( $type ) {
17361754 case 'request':
 1755+
 1756+ $floor = false;
 1757+
 1758+ if ( $this->staged_data['currency_code'] == 'JPY' ) {
 1759+ $floor = true;
 1760+ }
 1761+
17371762 $this->staged_data['amount'] = $this->staged_data['amount'] * 100;
 1763+
 1764+ // Floor if required
 1765+ if ( $floor ) {
 1766+ $this->staged_data['amount'] = $this->floorAmount( $this->staged_data['amount'] );
 1767+ }
 1768+
17381769 break;
17391770 case 'response':
17401771 $this->staged_data['amount'] = $this->staged_data['amount'] / 100;

Follow-up revisions

RevisionCommit summaryAuthorDate
r103847MFT r102338, r102681, r102685, r102810, r102828, r102829, r102832, r102836, r...khorn22:30, 21 November 2011
r103848MFT r102338, r102681, r102685, r102810, r102828, r102829, r102832, r102836, r...khorn22:31, 21 November 2011
r103863Simplifying process of flooring yen currency. See r103514.jpostlethwaite23:09, 21 November 2011
r103869MFT r103415, r103514, r103837, r103854, r103863, r103866khorn23:41, 21 November 2011

Comments

#Comment by Kaldari (talk | contribs)   20:11, 21 November 2011

This seems like overkill. Why not just insert the following immediately before it gets multiplied by 100:

if ( $this->staged_data['currency_code'] == 'JPY' ) {
    $this->staged_data['amount'] = floor( $this->staged_data['amount'] );
}

and get rid of the rest?

#Comment by Jpostlethwaite (talk | contribs)   20:19, 21 November 2011

it is overkill.

We are not sure if the yen is the only currency with this problem.

#Comment by Kaldari (talk | contribs)   20:33, 21 November 2011

In that case, you could do:

$floorCurrencies = array ( 'JPY' );
if ( in_array( $this->staged_data['currency_code'], $floorCurrencies ) {
    $this->staged_data['amount'] = floor( $this->staged_data['amount'] );
}

Do we really need to rewrite the floor function?

#Comment by Kaldari (talk | contribs)   20:34, 21 November 2011

Oops, that's missing a parenthesis :P

Status & tagging log