Skip to content

Commit

Permalink
Merge pull request #160 from pagarme/fix/boleto-refund
Browse files Browse the repository at this point in the history
Fix/boleto refund
  • Loading branch information
devdrops committed Apr 7, 2017
2 parents 1e013a8 + ed7df61 commit 81abfde
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 22 deletions.
16 changes: 9 additions & 7 deletions lib/Transaction/Request/BoletoTransactionRefund.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ private function getBankAccountData()

if (is_null($bankAccount->getId())) {
return [
'bank_code' => $bankAccount->getBankCode(),
'agencia' => $bankAccount->getAgencia(),
'agencia_dv' => $bankAccount->getAgenciaDv(),
'conta' => $bankAccount->getConta(),
'conta_dv' => $bankAccount->getContaDv(),
'document_number' => $bankAccount->getDocumentNumber(),
'legal_name' => $bankAccount->getLegalName()
'bank_account' => [
'bank_code' => $bankAccount->getBankCode(),
'agencia' => $bankAccount->getAgencia(),
'agencia_dv' => $bankAccount->getAgenciaDv(),
'conta' => $bankAccount->getConta(),
'conta_dv' => $bankAccount->getContaDv(),
'document_number' => $bankAccount->getDocumentNumber(),
'legal_name' => $bankAccount->getLegalName()
]
];
}

Expand Down
2 changes: 2 additions & 0 deletions tests/acceptance/BulkAnticipationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public function registerAAnticipationWith($paymentDate, $timeframe, $requestedAm

$paymentDate = new \Datetime($paymentDate);

$paymentDate->setTime(0, 0, 0);

$this->expectedPaymentDate = $paymentDate;
$this->expectedTimeframe = $timeframe;
$this->expectedRequestedAmount = $requestedAmount;
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/PlanContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function aPreviousCreatedPlans()
*/
public function iQueryForPlans()
{
sleep(1);
sleep(2);
$this->plans = self::getPagarMe()
->plan()
->getList();
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/SubscriptionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function previousCreatedSubscriptions()
$this->aPreviousCreatedSubscription();
$this->aPreviousCreatedSubscription();
$this->aPreviousCreatedSubscription();
sleep(1);
sleep(2);
}

/**
Expand Down
67 changes: 66 additions & 1 deletion tests/acceptance/TransactionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function makeABoletoTransactionWithAGivenAmountUsingCustomersFromTheAPI($
{
$customersIdList = $this->getCustomerIdsFromAPI();

foreach($customersIdList as $id) {
foreach ($customersIdList as $id) {
/** @var $customer \PagarMe\Sdk\Customer\Customer */
$customer = self::getPagarMe()
->customer()
Expand Down Expand Up @@ -362,6 +362,71 @@ public function makeABoletoTransactionWithRandomAmountAndMetadata()
);
}

/**
* @Given a paid Boleto Transaction
*/
public function aPaidBoletoTransaction()
{
$this->aValidCustomer();
$this->makeABoletoTransactionWith(rand(1000, 10000));

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

/**
* @Given suficient funds
*/
public function suficientFunds()
{
$transaction = self::getPagarMe()
->transaction()
->boletoTransaction(
rand(10000, 10001),
$this->customer,
self::POSTBACK_URL
);

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


/**
* @When refund the Boleto Transaction
*/
public function refundTheBoletoTransaction()
{
$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
);
}

/**
* @Then refunded transaction must be returned
*/
public function refundedTransactionMustBeReturned()
{
assertTrue($this->transaction->isPendingRefund());
}

private function getRandomMetadata()
{
$this->metadata = [uniqid('key') => uniqid('value')];
Expand Down
6 changes: 3 additions & 3 deletions tests/acceptance/features/bulk_anticipation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ Feature: Bulk Anticipation
Then a anticipation must be created
And must anticipation contain same data
Examples:
| payment_date | timeframe | requested_amount | build |
| 2017-04-01 | start | 1000 | true |
| 2017-04-01 | start | 1000 | false |
| payment_date | timeframe | requested_amount | build |
| +5 days | start | 1000 | true |
| +6 days | start | 1000 | false |
8 changes: 6 additions & 2 deletions tests/acceptance/features/transaction.feature
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ Feature: Transaction
| 123456 |
| 1000001 |

Scenario: Refund a Boleto Transaction
Given a paid Boleto Transaction
And suficient funds
When refund the Boleto Transaction
Then refunded transaction must be returned

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 Expand Up @@ -128,15 +134,13 @@ Feature: Transaction
When query transactions events
Then an array of events must be returned

@only
Scenario: Create credit card transaction with metadata
Given a valid customer
And register a card with "4556425889100276", "João Silva" and "0623"
When make a credit card transaction with random amount and metadata
Then a valid transaction must be created
And must contain same metadata

@only
Scenario: Creating a Boleto Transaction
Given a valid customer
When make a boleto transaction with random amount and metadata
Expand Down
16 changes: 9 additions & 7 deletions tests/unit/Transaction/Request/BoletoTransactionRefundTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ public function payloadMustContainBankData()

$this->assertEquals(
[
'bank_code' => self::BANK_CODE,
'agencia' => self::AGENCIA,
'agencia_dv' => self::AGENCIA_DV,
'conta' => self::CONTA,
'conta_dv' => self::CONTA_DV,
'document_number' => self::DOCUMENT_NUMBER,
'legal_name' => self::LEGAL_NAME,
'bank_account' => [
'bank_code' => self::BANK_CODE,
'agencia' => self::AGENCIA,
'agencia_dv' => self::AGENCIA_DV,
'conta' => self::CONTA,
'conta_dv' => self::CONTA_DV,
'document_number' => self::DOCUMENT_NUMBER,
'legal_name' => self::LEGAL_NAME,
]
],
$transactionCreate->getPayload()
);
Expand Down

0 comments on commit 81abfde

Please sign in to comment.