Skip to content

Commit

Permalink
Merge pull request #184 from pagarme/feature/boleto-partial-refund
Browse files Browse the repository at this point in the history
  • Loading branch information
devdrops committed May 15, 2017
2 parents 35a93b5 + dee15bd commit 494b7ae
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
19 changes: 18 additions & 1 deletion lib/Transaction/Request/BoletoTransactionRefund.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,24 @@ class BoletoTransactionRefund implements RequestInterface
* @var BankAccount
*/
protected $bankAccount;
/**
* @var int
*/
protected $amount;

/**
* @param BoletoTransaction $transaction
* @param BankAccount $bankAccount
* @param int $amount
*/
public function __construct(
BoletoTransaction $transaction,
BankAccount $bankAccount
BankAccount $bankAccount,
$amount = null
) {
$this->transaction = $transaction;
$this->bankAccount = $bankAccount;
$this->amount = $amount;
}

/**
Expand Down Expand Up @@ -76,4 +83,14 @@ private function getBankAccountData()

return ['bank_account_id' => $bankAccount->getId()];
}

/**
* @return int
* @codeCoverageIgnore
*/
public function getAmount()
{
return $this->amount;
}

}
11 changes: 9 additions & 2 deletions lib/Transaction/TransactionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,20 @@ public function creditCardRefund(CreditCardTransaction $transaction, $amount = n
/**
* @param BoletoTransaction $transaction
* @param PagarMe\Sdk\BankAccount\BankAccount $bankAccount
* @param int @amount
* @return BoletoTransaction
*/
public function boletoRefund(
BoletoTransaction $transaction,
BankAccount $bankAccount
BankAccount $bankAccount,
$amount = null
) {
$request = new BoletoTransactionRefund($transaction, $bankAccount);
$request = new BoletoTransactionRefund(
$transaction,
$bankAccount,
$amount
);

$response = $this->client->send($request);

return $this->buildTransaction($response);
Expand Down
40 changes: 40 additions & 0 deletions tests/acceptance/TransactionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,46 @@ public function refundTheBoletoTransaction()
);
}

/**
* @When make a boleto transaction with the given :amount
*/
public function makeABoletoTransactionWithTheGiven($amount)
{
$this->aValidCustomer();

$this->makeABoletoTransactionWith($amount);

$this->transaction = self::getPagarMe()
->transaction()
->payTransaction($this->transaction);
}

/**
* @When refund the given partial :value of the transaction
*/
public function refundTheGivenPartialOfTheTransaction($value)
{
$bankAccount = new \PagarMe\Sdk\BankAccount\BankAccount(
[
'bank_code' => '237',
'agencia' => '13383',
'agencia_dv' => '1',
'conta' => '133999',
'conta_dv' => '1',
'document_number' => $this->customer->getDocumentNumber(),
'legal_name' => $this->customer->getName()
]
);

$this->transaction = self::getPagarMe()
->transaction()
->boletoRefund(
$this->transaction,
$bankAccount,
$value
);
}

/**
* @Then refunded transaction must be returned
*/
Expand Down
11 changes: 11 additions & 0 deletions tests/acceptance/features/transaction.feature
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ Feature: Transaction
When refund the Boleto Transaction
Then refunded transaction must be returned

Scenario Outline: Create and Partially Refund a Boleto Transaction
Given a valid customer
When make a boleto transaction with the given "<amount>"
And refund the given partial "<value>" of the transaction
Then refunded transaction must be returned
Examples:
| amount | value |
| 1000 | 500 |
| 1300 | 700 |
| 1500 | 100 |

Scenario Outline: Creating a Boleto Transaction using Customers from the API
Given make a boleto transaction with "<amount>", using Customers from the API
Then a list of valid transactions must be created
Expand Down

0 comments on commit 494b7ae

Please sign in to comment.