Skip to content

Commit

Permalink
add charge remainder split rule (#192)
Browse files Browse the repository at this point in the history
* Added charge_remainder flag when creating a split rule on the SplitRuleHandler

* Added property to store the chargeRemainder property and the getter for the property

* Fixed some phpdocs typos and paths missing the inital backslash for fully qualified namespace

* Fixed some phpdocs paths missing the inital backslash for fully qualified namespace

* Added unit tests to the new SplitRule's chargeRemainder property

* Added the charge remainder parameters to check that the acceptance tests still working fine with the new parameters

* Removed space

* Force test again

* Removed extra line
  • Loading branch information
williamokano authored and XDUH committed May 24, 2017
1 parent 28fb269 commit facab31
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 19 deletions.
13 changes: 13 additions & 0 deletions lib/SplitRule/SplitRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class SplitRule
* @var bool
*/
private $chargeProcessingFee;
/**
* @var bool
*/
private $chargeRemainder;
/**
* @var bool
*/
Expand Down Expand Up @@ -88,6 +92,15 @@ public function getChargeProcessingFee()
return $this->chargeProcessingFee;
}

/**
* @return bool
* @codeCoverageIgnore
*/
public function getChargeRemainder()
{
return $this->chargeRemainder;
}

/**
* @return bool
* @codeCoverageIgnore
Expand Down
11 changes: 8 additions & 3 deletions lib/SplitRule/SplitRuleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,28 @@

class SplitRuleHandler
{

/**
* @param int $value
* @param Recipient $recipient
* @param bool $liable
* @param bool $chargeProcessingFee
* @param bool $chargeRemainder
* @return SplitRule
*/
public function monetaryRule(
$value,
Recipient $recipient,
$liable = null,
$chargeProcessingFee = null
$chargeProcessingFee = null,
$chargeRemainder = null
) {
return new SplitRule(
[
'amount' => $value,
'recipient' => $recipient,
'liable' => $liable,
'chargeProcessingFee' => $chargeProcessingFee,
'chargeRemainder' => $chargeRemainder,
]
);
}
Expand All @@ -35,20 +37,23 @@ public function monetaryRule(
* @param Recipient $recipient
* @param bool $liable
* @param bool $chargeProcessingFee
* @param bool $chargeRemainder
* @return SplitRule
*/
public function percentageRule(
$value,
Recipient $recipient,
$liable = null,
$chargeProcessingFee = null
$chargeProcessingFee = null,
$chargeRemainder = null
) {
return new SplitRule(
[
'percentage' => $value,
'recipient' => $recipient,
'liable' => $liable,
'chargeProcessingFee' => $chargeProcessingFee,
'chargeRemainder' => $chargeRemainder,
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Transaction/CreditCardTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class CreditCardTransaction extends AbstractTransaction
const PAYMENT_METHOD = 'credit_card';

/**
* @var PagarMe\Sdk\Card\Card
* @var \PagarMe\Sdk\Card\Card
*/
protected $card;

Expand Down
11 changes: 6 additions & 5 deletions lib/Transaction/TransactionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class TransactionHandler extends AbstractHandler

/**
* @param int $amount
* @param PagarMe\Sdk\Card\Card $card
* @param PagarMe\Sdk\Customer\Customer $customer
* @param \PagarMe\Sdk\Card\Card $card
* @param \PagarMe\Sdk\Customer\Customer $customer
* @param int $installments
* @param boolean $capture
* @param string $postBackUrl
* @param array $metaData
* @param array $metadata
* @param array $extraAttributes
* @return CreditCardTransaction
*/
Expand Down Expand Up @@ -66,8 +66,9 @@ public function creditCardTransaction(

/**
* @param int $amount
* @param PagarMe\Sdk\Customer\Customer $customer
* @param \PagarMe\Sdk\Customer\Customer $customer
* @param string $postBackUrl
* @param mixed $metadata
* @param array $extraAttributes
* @return BoletoTransaction
*/
Expand Down Expand Up @@ -160,7 +161,7 @@ public function creditCardRefund(CreditCardTransaction $transaction, $amount = n

/**
* @param BoletoTransaction $transaction
* @param PagarMe\Sdk\BankAccount\BankAccount $bankAccount
* @param \PagarMe\Sdk\BankAccount\BankAccount $bankAccount
* @param int @amount
* @return BoletoTransaction
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/SplitRuleContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public function validSplitrule()
$this->splitRules = new SplitRuleCollection();
$this->splitRules[]= self::getPagarMe()
->splitRule()
->percentageRule(51, $this->createRecipient());
->percentageRule(51, $this->createRecipient(), null, null, true);
$this->splitRules[]=self::getPagarMe()
->splitRule()
->percentageRule(49, $this->createRecipient());
->percentageRule(49, $this->createRecipient(), null, null, false);
}

/**
Expand Down
22 changes: 14 additions & 8 deletions tests/unit/SplitRule/SplitRuleHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class SplitRuleHandlerTest extends \PHPUnit_Framework_TestCase
public function splitData()
{
return [
[100, 123, true, false],
[666, 321, false, false],
[23, 233, null, false],
[42, 800, null, true],
[100, 123, true, false, true],
[666, 321, false, false, false],
[23, 233, null, false, true],
[42, 800, null, true, null],
];
}

Expand All @@ -24,7 +24,8 @@ public function mustReturnSplitRuleWithMonetaryValue(
$value,
$recipientId,
$liable,
$chargeProcessingFee
$chargeProcessingFee,
$chargeRemainder
) {
$recipientMock = $this->getMockBuilder('PagarMe\Sdk\Recipient\Recipient')
->disableOriginalConstructor()
Expand All @@ -36,14 +37,16 @@ public function mustReturnSplitRuleWithMonetaryValue(
$value,
$recipientMock,
$liable,
$chargeProcessingFee
$chargeProcessingFee,
$chargeRemainder
);

$this->assertEquals($value, $rule->getAmount());
$this->assertNull($rule->getPercentage());
$this->assertEquals($liable, $rule->getLiable());
$this->assertEquals($chargeProcessingFee, $rule->getChargeProcessingFee());
$this->assertEquals($recipientId, $rule->getRecipient()->getId());
$this->assertEquals($chargeRemainder, $rule->getChargeRemainder());
}

/**
Expand All @@ -54,7 +57,8 @@ public function mustReturnSplitRuleWithPercentageValue(
$value,
$recipientId,
$liable,
$chargeProcessingFee
$chargeProcessingFee,
$chargeRemainder
) {
$recipientMock = $this->getMockBuilder('PagarMe\Sdk\Recipient\Recipient')
->disableOriginalConstructor()
Expand All @@ -66,13 +70,15 @@ public function mustReturnSplitRuleWithPercentageValue(
$value,
$recipientMock,
$liable,
$chargeProcessingFee
$chargeProcessingFee,
$chargeRemainder
);

$this->assertEquals($value, $rule->getPercentage());
$this->assertNull($rule->getAmount());
$this->assertEquals($liable, $rule->getLiable());
$this->assertEquals($chargeProcessingFee, $rule->getChargeProcessingFee());
$this->assertEquals($recipientId, $rule->getRecipient()->getId());
$this->assertEquals($chargeRemainder, $rule->getChargeRemainder());
}
}

0 comments on commit facab31

Please sign in to comment.