Skip to content

Commit

Permalink
v1.0.2
Browse files Browse the repository at this point in the history
Fix separators in the given amount (expected format, e.g. 1000.00
instead of 1,000.00 or 1.000,00)
  • Loading branch information
wpawel committed Jan 12, 2018
1 parent 2782c6f commit 27e7df6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Tool/AmountFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ public static function format($amount, $currency, $rounded = true)
$amount = round($amount, $precision);
}

return number_format($amount, $precision);
$amount1 = number_format($amount, $precision);
return self::fixAmountSeparator($amount1);

This comment has been minimized.

Copy link
@yrdus

yrdus Jan 15, 2018

Calling non-static method with a static operator.
Exception #0 (Exception): Deprecated Functionality: Non-static method Dotpay\Tool\AmountFormatter::fixAmountSeparator() should not be called statically in [...]/vendor/dotpay/php-sdk/src/Tool/AmountFormatter.php on line 74

}

/**
* Fix separators in the given amount (expected format, e.g. 1000.00 instead of 1,000.00 or 1.000,00)
* @param string $inputAmount Input amount
* @param string $separator Separator which should be removed besides the last one
* @return type
*/
protected function fixAmountSeparator($inputAmount, $separator = '.') {
$amount = preg_replace('/[^0-9.]/', '', str_replace(',', '.', $inputAmount));
$part1 = str_replace($separator, '', substr($amount, 0, strrpos($amount, $separator)));
$part2 = substr($amount, strrpos($amount, $separator));
return $part1.$part2;
}
}

0 comments on commit 27e7df6

Please sign in to comment.