Skip to content

Commit

Permalink
tests: add acceptance tests to capture with split rules
Browse files Browse the repository at this point in the history
  • Loading branch information
murilohns committed Mar 2, 2018
1 parent 7b62d7e commit de495c0
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
85 changes: 85 additions & 0 deletions tests/acceptance/TransactionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
use Behat\Gherkin\Node\TableNode;
use Behat\Behat\Tester\Exception\PendingException;
use Behat\Testwork\Hook\Scope\BeforeSuiteScope;
use PagarMe\Sdk\BankAccount\BankAccount;
use PagarMe\Sdk\Customer\Customer;
use PagarMe\Sdk\Recipient\Recipient;
use PagarMe\Sdk\SplitRule\SplitRule;
use PagarMe\Sdk\SplitRule\SplitRuleCollection;

class TransactionContext extends BasicContext
{
Expand Down Expand Up @@ -520,6 +524,40 @@ public function makeABoletoTransactionWithAsync($amount, $async)
);
}

/**
* @Then capture the transaction with split rules
*/
public function captureTransactionWithSplitRules()
{

$transaction = $this->transaction;

$this->transaction = self::getPagarMe()
->transaction()
->capture(
$transaction,
1000,
null,
$this->createValidSplitRule()
);
}

/**
* @When make a authorized credit card transaction
*/
public function authorizeACreditCardTransaction()
{
$this->transaction = self::getPagarMe()
->transaction()
->creditCardTransaction(
1000,
$this->creditCard,
$this->customer,
1,
false
);
}

/**
* @Then must have status :status
*/
Expand All @@ -536,4 +574,51 @@ public function theTransactionCustomerMustBeTheSameRetrieved()
$transactionCustomer = $this->transaction->getCustomer();
assertEquals($transactionCustomer->id, $this->customer->getId());
}

private function createValidSplitRule()
{
$splitRules = new SplitRuleCollection();

$splitRule1 = self::getPagarMe()->
splitRule()->
percentageRule(
80,
$this->createRecipient(),
true,
true,
true
);

$splitRule2 = self::getPagarMe()->
splitRule()->
percentageRule(
20,
$this->createRecipient(),
false,
false,
false
);

$splitRules[] = $splitRule1;
$splitRules[] = $splitRule2;

return $splitRules;
}

private function createRecipient()
{
$accountData = [
"bank_code" => "341",
"agencia" => "0932",
"conta" => "580" . rand(10, 99),
"conta_dv" => "5",
"document_number" => "26268738888",
"legal_name" => "API BANK ACCOUNT"
];

$bankAccount = new BankAccount($accountData);
return self::getPagarMe()
->recipient()
->create($bankAccount);
}
}
8 changes: 8 additions & 0 deletions tests/acceptance/features/transaction.feature
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,11 @@ Feature: Transaction
Given an existent customer
When make a boleto transaction with random amount and metadata
Then the transaction customer must be the same retrieved

Scenario: Capture a transaction with split rules
Given a valid customer
And a valid card
When make a authorized credit card transaction
Then a authorized transaction must be created
And capture the transaction with split rules
And a paid transaction must be created

0 comments on commit de495c0

Please sign in to comment.