moiplabs / moip-php

Biblioteca de integração com o MoIP em PHP
http://labs.moip.com.br/
83 stars 68 forks source link

Bug in validation MoIP::addCommision() #19

Closed holtkamp closed 13 years ago

holtkamp commented 13 years ago

The MoIP::addCommission() method contains the following validation:

<?php
//When either one is not set, an exception is thrown (incorrect: in this case an exception is ALWAYS thrown)
if (!isset($param['valor_fixo']) or !isset($param['valor_percentual']))
            throw new InvalidArgumentException('Você deve especificar um tipo de valor para comissionar.');

//When both are set, an exception is thrown (correct)
if (isset($param['valor_fixo']) and isset($param['valor_percentual']))
            throw new InvalidArgumentException('Você deve especificar somente um tipo de valor de comissão');
?>

The result of these validations is that none of the options are allowed. The solution is to use an 'and' in the first validation:

<?php
//When BOTH are not set, we don't know how to proceed: throw exception
if (!isset($param['valor_fixo']) and !isset($param['valor_percentual']))
            throw new InvalidArgumentException('Você deve especificar um tipo de valor para comissionar.');
?>

Also note that the provided unit test does not cover this area.

Cheers

herberthamaral commented 13 years ago

Hi holtkamp,

Thank you for your contribution. I'll write some unit tests for it and I should release a patch in few hours :-)

holtkamp commented 13 years ago

Hi Herbert,

so its been a while now, did you manage to find time to fix this?

Cheers

herberthamaral commented 13 years ago

Sorry, I no longer maintain this repo. I have forwarded your message to the new maintainer :-)