Skip to content

Commit

Permalink
Drop float support for transferAmount
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored and monofone committed Jun 19, 2020
1 parent e3b77b4 commit 36b3216
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 153 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ project.xml
Session.vim
bin/
/vendor/
composer.lock
composer.lock
.phpunit.result.cache
20 changes: 4 additions & 16 deletions src/TransferInformation/BaseTransferInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class BaseTransferInformation implements TransferInformationInterface
protected $bic;

/**
* Must be between 0.01 and 999999999.99
* Amount in cents; must be between 1 and 99999999999
*
* @var string
* @var int
*/
protected $transferAmount;

Expand Down Expand Up @@ -101,24 +101,12 @@ class BaseTransferInformation implements TransferInformationInterface
protected $postalAddress;

/**
* @param string|int|float $amount If int is provided, the amount should be in cents
* If float is provided, the amount will be multiply by 100
* If string is provided, it depends on the value
* @param int $amount amount in cents
* @param string $iban
* @param string $name
*
* @throws InvalidArgumentException
*/
public function __construct($amount, $iban, $name)
{
$amount += 0;
if (is_float($amount)) {
if (!function_exists('bcscale')) {
throw new InvalidArgumentException('Using floats for amount is only possible with bcmath enabled');
}
bcscale(2);
$amount = (integer)bcmul(sprintf('%01.4F', $amount), '100');
}
$this->transferAmount = $amount;
$this->iban = $iban;
$this->name = StringHelper::sanitizeString($name);
Expand All @@ -133,7 +121,7 @@ public function accept(DomBuilderInterface $domBuilder)
}

/**
* @return mixed
* @return int
*/
public function getTransferAmount()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class CustomerCreditTransferInformation extends BaseTransferInformation
{
/**
* @param string $amount
* @param int $amount amount in cents
* @param string $iban
* @param string $name
* @param string $identification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CustomerDirectDebitTransferInformation extends BaseTransferInformation
protected $originalMandateId = null;

/**
* @param string $amount
* @param int $amount amount in cents
* @param string $iban
* @param string $name
* @param string $identification
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/CustomerCreditValidationPain00100103Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Digitick\Sepa\Tests;
namespace Digitick\Sepa\Tests\Functional;

use Digitick\Sepa\DomBuilder\CustomerCreditTransferDomBuilder;
use Digitick\Sepa\GroupHeader;
Expand Down Expand Up @@ -69,7 +69,7 @@ public function testSinglePaymentSingleTransWithMoreInfo($scenario)
$groupHeader->setIssuer('Issuing Party');
$sepaFile = new CustomerCreditTransferFile($groupHeader);

$transfer = new CustomerCreditTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerCreditTransferInformation(2, 'FI1350001540000056', 'Their Corp');
if ($scenario['bic'] !== '') {
$transfer->setBic($scenario['bic']);
}
Expand Down
32 changes: 16 additions & 16 deletions tests/Functional/CustomerCreditValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Digitick\Sepa\Tests;
namespace Digitick\Sepa\Tests\Functional;

use Digitick\Sepa\DomBuilder\CustomerCreditTransferDomBuilder;
use Digitick\Sepa\Exception\InvalidTransferFileConfiguration;
Expand Down Expand Up @@ -75,7 +75,7 @@ public function testSinglePaymentSingleTrans($schema)
$groupHeader = new GroupHeader('transferID', 'Me');
$sepaFile = new CustomerCreditTransferFile($groupHeader);

$transfer = new CustomerCreditTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerCreditTransferInformation(2, 'FI1350001540000056', 'Their Corp');
$transfer->setBic('OKOYFIHH');
$transfer->setRemittanceInformation('Transaction Description');
$transfer->setEndToEndIdentification(uniqid());
Expand Down Expand Up @@ -111,12 +111,12 @@ public function testSinglePaymentMultiTrans($schema)
$sepaFile = new CustomerCreditTransferFile($groupHeader);
$payment = new PaymentInformation('Payment Info ID', 'FR1420041010050500013M02606', 'PSSTFRPPMON', 'My Corp');

$transfer = new CustomerCreditTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerCreditTransferInformation(2, 'FI1350001540000056', 'Their Corp');
$transfer->setBic('OKOYFIHH');
$transfer->setRemittanceInformation('Transaction description');
$payment->addTransfer($transfer);

$transfer = new CustomerCreditTransferInformation('5000.00', 'BE30001216371411', 'GHI Semiconductors');
$transfer = new CustomerCreditTransferInformation(500000, 'BE30001216371411', 'GHI Semiconductors');
$transfer->setBic('DDDDBEBB');
$transfer->setRemittanceInformation('Transaction description');
$payment->addTransfer($transfer);
Expand Down Expand Up @@ -163,12 +163,12 @@ public function testControlSumAndTransactionCount($schema)
$sepaFile = new CustomerCreditTransferFile($groupHeader);
$payment = new PaymentInformation('Payment Info ID', 'FR1420041010050500013M02606', 'PSSTFRPPMON', 'My Corp');

$transfer = new CustomerCreditTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerCreditTransferInformation(2, 'FI1350001540000056', 'Their Corp');
$transfer->setBic('OKOYFIHH');
$transfer->setRemittanceInformation('Transaction description');
$payment->addTransfer($transfer);

$transfer = new CustomerCreditTransferInformation('5000.00', 'BE30001216371411', 'GHI Semiconductors');
$transfer = new CustomerCreditTransferInformation(500000, 'BE30001216371411', 'GHI Semiconductors');
$transfer->setBic('DDDDBEBB');
$transfer->setRemittanceInformation('Transaction description');
$payment->addTransfer($transfer);
Expand Down Expand Up @@ -205,7 +205,7 @@ public function testPaymentMetaData($schema)
$payment->setDueDate(new \DateTime('20.11.2012'));
$payment->setInstructionPriority('NORM');

$transfer = new CustomerCreditTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerCreditTransferInformation(2, 'FI1350001540000056', 'Their Corp');
$transfer->setBic('OKOYFIHH');
$transfer->setRemittanceInformation('Transaction description');
$payment->addTransfer($transfer);
Expand Down Expand Up @@ -254,7 +254,7 @@ public function testCreditorAddressGeneration(array $address)
$payment = new PaymentInformation('Payment Info ID', 'FR1420041010050500013M02606', 'PSSTFRPPMON', 'My Corp');
$payment->setDueDate(new \DateTime('20.11.2012'));

$transfer = new CustomerCreditTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerCreditTransferInformation(2, 'FI1350001540000056', 'Their Corp');
$transfer->setBic('OKOYFIHH');
$transfer->setRemittanceInformation('Transaction description');

Expand Down Expand Up @@ -316,12 +316,12 @@ public function testMultiPaymentMultiTrans($schema)

$payment1 = new PaymentInformation('account settlement', 'FR1420041010050500013M02606', 'PSSTFRPPMON', 'My Corp');

$transfer1 = new CustomerCreditTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer1 = new CustomerCreditTransferInformation(2, 'FI1350001540000056', 'Their Corp');
$transfer1->setBic('OKOYFIHH');
$transfer1->setRemittanceInformation('Transaction description');
$payment1->addTransfer($transfer1);

$transfer2 = new CustomerCreditTransferInformation('5000.00', 'BE30001216371411', 'GHI Semiconductors');
$transfer2 = new CustomerCreditTransferInformation(500000, 'BE30001216371411', 'GHI Semiconductors');
$transfer2->setBic('DDDDBEBB');
$transfer2->setRemittanceInformation('Transaction description');
$payment1->addTransfer($transfer2);
Expand All @@ -330,12 +330,12 @@ public function testMultiPaymentMultiTrans($schema)

$payment2 = new PaymentInformation('account settlement', 'FR1420041010050500013M02606', 'PSSTFRPPMON', 'My Corp');

$transfer1 = new CustomerCreditTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer1 = new CustomerCreditTransferInformation(2, 'FI1350001540000056', 'Their Corp');
$transfer1->setBic('OKOYFIHH');
$transfer1->setRemittanceInformation('Transaction description');
$payment2->addTransfer($transfer1);

$transfer2 = new CustomerCreditTransferInformation('5000.00', 'BE30001216371411', 'GHI Semiconductors');
$transfer2 = new CustomerCreditTransferInformation(500000, 'BE30001216371411', 'GHI Semiconductors');
$transfer2->setBic('DDDDBEBB');
$transfer2->setRemittanceInformation('Transaction description');
$payment2->addTransfer($transfer2);
Expand Down Expand Up @@ -378,7 +378,7 @@ public function testUmlautConversion($schema)
$payment->setSequenceType(PaymentInformation::S_ONEOFF);
$payment->setCreditorId('Only A-Z without äöüßÄÖÜ creditorSchemeId');

$transfer = new CustomerCreditTransferInformation('0.02', 'FI1350001540000056', 'Only A-Z without äöüßÄÖÜ creditorName');
$transfer = new CustomerCreditTransferInformation(2, 'FI1350001540000056', 'Only A-Z without äöüßÄÖÜ creditorName');
$transfer->setBic('OKOYFIHH');
$transfer->setRemittanceInformation('Only A-Z without äöüßÄÖÜ remittanceInformation');
$payment->addTransfer($transfer);
Expand Down Expand Up @@ -425,7 +425,7 @@ public function testSinglePaymentOtherCreationDateTimeFormat($schema)
$groupHeader->setCreationDateTimeFormat($dateTimeFormat);
$sepaFile = new CustomerCreditTransferFile($groupHeader);

$transfer = new CustomerCreditTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerCreditTransferInformation(2, 'FI1350001540000056', 'Their Corp');
$transfer->setBic('OKOYFIHH');
$transfer->setRemittanceInformation('Transaction Description');
$transfer->setEndToEndIdentification(uniqid());
Expand Down Expand Up @@ -465,7 +465,7 @@ public function testSinglePaymentSingleTransWithoutRemitttanceInformation($schem
$groupHeader = new GroupHeader('transferID', 'Me');
$sepaFile = new CustomerCreditTransferFile($groupHeader);

$transfer = new CustomerCreditTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerCreditTransferInformation(2, 'FI1350001540000056', 'Their Corp');
$transfer->setBic('OKOYFIHH');
$transfer->setEndToEndIdentification(uniqid());
$transfer->setInstructionId(uniqid());
Expand Down Expand Up @@ -499,7 +499,7 @@ public function testSinglePaymentSingleTransWithStructuredCreditorReference($sch
$groupHeader = new GroupHeader('transferID', 'Me');
$sepaFile = new CustomerCreditTransferFile($groupHeader);

$transfer = new CustomerCreditTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerCreditTransferInformation(2, 'FI1350001540000056', 'Their Corp');
$transfer->setBic('OKOYFIHH');
$transfer->setEndToEndIdentification(uniqid());
$transfer->setInstructionId(uniqid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Digitick\Sepa\Tests;
namespace Digitick\Sepa\Tests\Functional;

use Digitick\Sepa\DomBuilder\CustomerDirectDebitTransferDomBuilder;
use Digitick\Sepa\Exception\InvalidTransferFileConfiguration;
Expand Down Expand Up @@ -63,7 +63,7 @@ public function test_given_country_is_returned_For_path()
$groupHeader = new GroupHeader('transferID', 'Me');
$sepaFile = new CustomerDirectDebitTransferFile($groupHeader);

$transfer = new CustomerDirectDebitTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerDirectDebitTransferInformation(2, 'FI1350001540000056', 'Their Corp');
$transfer->setMandateSignDate(new \DateTime('16.08.2013'));
$transfer->setMandateId('ABCDE');
$transfer->setRemittanceInformation('Transaction Description');
Expand Down Expand Up @@ -109,7 +109,7 @@ public function test_multiple_address_lines_are_added_with_array()
$groupHeader = new GroupHeader('transferID', 'Me');
$sepaFile = new CustomerDirectDebitTransferFile($groupHeader);

$transfer = new CustomerDirectDebitTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerDirectDebitTransferInformation(2, 'FI1350001540000056', 'Their Corp');
$transfer->setMandateSignDate(new \DateTime('16.08.2013'));
$transfer->setMandateId('ABCDE');
$transfer->setRemittanceInformation('Transaction Description');
Expand Down Expand Up @@ -153,7 +153,7 @@ public function testValidationFailureSeqType()
$groupHeader = new GroupHeader('transferID', 'Me');
$sepaFile = new CustomerDirectDebitTransferFile($groupHeader);

$transfer = new CustomerDirectDebitTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerDirectDebitTransferInformation(2, 'FI1350001540000056', 'Their Corp');

$payment = new PaymentInformation('Payment Info ID', 'FR1420041010050500013M02606', 'PSSTFRPPMON', 'My Corp');
$payment->addTransfer($transfer);
Expand All @@ -172,7 +172,7 @@ public function testValidationFailureCreditorId()
$groupHeader = new GroupHeader('transferID', 'Me');
$sepaFile = new CustomerDirectDebitTransferFile($groupHeader);

$transfer = new CustomerDirectDebitTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerDirectDebitTransferInformation(2, 'FI1350001540000056', 'Their Corp');

$payment = new PaymentInformation('Payment Info ID', 'FR1420041010050500013M02606', 'PSSTFRPPMON', 'My Corp');
$payment->setSequenceType(PaymentInformation::S_ONEOFF);
Expand Down
14 changes: 7 additions & 7 deletions tests/Functional/CustomerDirectDebitValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Digitick\Sepa\Tests;
namespace Digitick\Sepa\Tests\Functional;

use Digitick\Sepa\DomBuilder\CustomerDirectDebitTransferDomBuilder;
use Digitick\Sepa\Exception\InvalidTransferFileConfiguration;
Expand Down Expand Up @@ -72,7 +72,7 @@ public function testSinglePaymentSingleTrans($schema)
$groupHeader = new GroupHeader('transferID', 'Me');
$sepaFile = new CustomerDirectDebitTransferFile($groupHeader);

$transfer = new CustomerDirectDebitTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerDirectDebitTransferInformation(2, 'FI1350001540000056', 'Their Corp');
$transfer->setBic('OKOYFIHH');
$transfer->setMandateSignDate(new \DateTime('16.08.2013'));
$transfer->setMandateId('ABCDE');
Expand Down Expand Up @@ -108,7 +108,7 @@ public function testSinglePaymentSingleTransWithStructuredCreditorReference($sch
$groupHeader = new GroupHeader('transferID', 'Me');
$sepaFile = new CustomerDirectDebitTransferFile($groupHeader);

$transfer = new CustomerDirectDebitTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerDirectDebitTransferInformation(2, 'FI1350001540000056', 'Their Corp');
$transfer->setBic('OKOYFIHH');
$transfer->setMandateSignDate(new \DateTime('16.08.2013'));
$transfer->setMandateId('ABCDE');
Expand Down Expand Up @@ -157,7 +157,7 @@ public function testValidationFailureSeqType($schema)
$groupHeader = new GroupHeader('transferID', 'Me');
$sepaFile = new CustomerDirectDebitTransferFile($groupHeader);

$transfer = new CustomerDirectDebitTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerDirectDebitTransferInformation(2, 'FI1350001540000056', 'Their Corp');

$payment = new PaymentInformation('Payment Info ID', 'FR1420041010050500013M02606', 'PSSTFRPPMON', 'My Corp');
$payment->addTransfer($transfer);
Expand All @@ -181,7 +181,7 @@ public function testValidationFailureCreditorId($schema)
$groupHeader = new GroupHeader('transferID', 'Me');
$sepaFile = new CustomerDirectDebitTransferFile($groupHeader);

$transfer = new CustomerDirectDebitTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerDirectDebitTransferInformation(2, 'FI1350001540000056', 'Their Corp');

$payment = new PaymentInformation('Payment Info ID', 'FR1420041010050500013M02606', 'PSSTFRPPMON', 'My Corp');
$payment->setSequenceType(PaymentInformation::S_ONEOFF);
Expand Down Expand Up @@ -209,7 +209,7 @@ public function testUmlautConversion($schema)
$payment->setSequenceType(PaymentInformation::S_ONEOFF);
$payment->setCreditorId('Only A-Z without äöüßÄÖÜ creditorSchemeId');

$transfer = new CustomerDirectDebitTransferInformation('0.02', 'FI1350001540000056', 'Only A-Z without äöüßÄÖÜ debtorName');
$transfer = new CustomerDirectDebitTransferInformation(2, 'FI1350001540000056', 'Only A-Z without äöüßÄÖÜ debtorName');
$transfer->setBic('OKOYFIHH');
$transfer->setRemittanceInformation('Only A-Z without äöüßÄÖÜ remittanceInformation');
$transfer->setMandateSignDate(new \DateTime());
Expand Down Expand Up @@ -264,7 +264,7 @@ public function testDomBuilderAcceptsPainFormatAsConstructor($scenario)
$groupHeader = new GroupHeader('transferID', 'Me');
$sepaFile = new CustomerDirectDebitTransferFile($groupHeader);

$transfer = new CustomerDirectDebitTransferInformation('0.02', 'FI1350001540000056', 'Their Corp');
$transfer = new CustomerDirectDebitTransferInformation(2, 'FI1350001540000056', 'Their Corp');
$transfer->setBic('OKOYFIHH');
$transfer->setMandateSignDate(new \DateTime('16.08.2013'));
$transfer->setMandateId('ABCDE');
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/TransferFile/Facade/CustomerCreditFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testValidFileCreationWithFacade($schema)
$credit->addTransfer(
'firstPayment',
array(
'amount' => '500',
'amount' => 500,
'creditorIban' => 'FI1350001540000056',
'creditorBic' => 'OKOYFIHH',
'creditorName' => 'Their Company',
Expand Down Expand Up @@ -73,7 +73,7 @@ public function testValidFileCreationWithFacadeWithoutDebtorBic($schema)
$credit->addTransfer(
'firstPayment',
array(
'amount' => '500',
'amount' => 500,
'creditorIban' => 'FI1350001540000056',
'creditorName' => 'Their Company',
'remittanceInformation' => 'Purpose of this credit'
Expand Down
Loading

0 comments on commit 36b3216

Please sign in to comment.