diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9e25d29..661f175 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,8 +4,28 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
+
+## v3.1.0 (2018-01-17)
+
+
+#### Bug Fixes
+
+* **Accounts**: Resolves Warning on account creation. ([4a712974](https://github.com/moip/moip-sdk-php/commit/4a712974))
+
+#### Features
+
+* **Orders**: Adds item category argument into `addItem()` method. ([749fa85e](https://github.com/moip/moip-sdk-php/commit/749fa85e))
+
+* **Accounts**: Adds `getPasswordLink()` method. ([fe2c4d6d](https://github.com/moip/moip-sdk-php/commit/fe2c4d6d))
+
+* **Balances**: Get balances of Moip Account. ([37b085a8](https://github.com/moip/moip-sdk-php/commit/37b085a8))
+
+* **Transfers**:
+ * Create a transfer to a saved bank account. ([749fa85e](https://github.com/moip/moip-sdk-php/commit/749fa85e))
+ * Adds set and get `ownId` to a transfer. ([1c297d14](https://github.com/moip/moip-sdk-php/commit/1c297d14))
+
-## v3.0.0 (2018-01-04)
+# [](https://github.com/moip/moip-sdk-php/compare/v2.2.0...v3.0.0) (2018-01-04)
#### Bug Fixes
diff --git a/README.md b/README.md
index 29961ad..6baa2e2 100644
--- a/README.md
+++ b/README.md
@@ -59,10 +59,10 @@
- [Cartão de crédito](#cartão-de-crédito-1)
- [Valor Total](#valor-total)
- [Valor Parcial](#valor-parcial)
- - [Conta Bancária](#conta-bancária)
+ - [Conta bancária](#conta-bancária)
- [Valor Total](#valor-total-1)
- [Valor Parcial](#valor-parcial-1)
- - [Consulta](#consulta-1)
+ - [Consulta](#consultar-reembolso)
- [OAuth (Moip Connect)](#oauth-moip-connect)
- [Solicitar permissões de acesso ao usuário](#solicitar-permissões-de-acesso-ao-usuário)
- [Gerando access token OAuth](#gerando-access-token-oauth)
@@ -78,13 +78,26 @@
- [Consulta](#consulta-1)
- [Verifica se usuário já possui Conta Moip](#verifica-se-usuário-já-possui-conta-moip)
- [Obter chave pública de uma Conta Moip](#obter-chave-pública-de-uma-conta-moip)
+ - [Saldo Moip](#saldo-moip)
+ - [Consulta](#consultar-saldos)
+ - [Conta Bancária](#conta-bancária-1)
+ - [Criação](#criar-conta-bancária)
+ - [Consulta](#consultar-conta-bancária)
+ - [Listagem](#listar-contas-bancárias)
+ - [Atualização](#atualizar-conta-bancária)
+ - [Deletar](#deletar-conta-bancária)
+ - [Transferência](#transferência)
+ - [Criação](#criando/executando-uma-transferência)
+ - [Consulta](#consultar-transferência)
+ - [Listagem](#listar-transferências)
+ - [Reversão](#reverter-transferência)
- [Preferências de Notificação](#preferências-de-notificação)
- [Criação](#criação-2)
- - [Consulta](#consulta-4)
+ - [Consulta](#consulta-5)
- [Exclusão](#exclusão)
- [Listagem](#listagem)
- [Webhooks](#webhooks)
- - [Consulta](#consulta-5)
+ - [Consulta](#consulta-6)
- [Packages](#packages)
- [Tratamento de exceções](#tratamento-de-exceções)
- [Documentação](#documentação)
@@ -260,11 +273,11 @@ Após criar o pedido basta criar um pagamento nesse pedido.
Para realizar o pagamento, via cartão de crédito, utilizando o cartão de um terceiro (quando o cliente não é o portador do cartão que será utilizado), é necessário que estes dados sejam diferenciados e informados corretamente, para cada etapa do fluxo.
```php
-$holder = $this->moip->holders()->setFullname('Jose Silva')
- ->setBirthDate(\DateTime::createFromFormat($this->date_format, $this->date_string))
+$holder = $moip->holders()->setFullname('Jose Silva')
+ ->setBirthDate("1990-10-10")
->setTaxDocument('22222222222', 'CPF')
->setPhone(11, 66778899, 55)
- ->setAddress(Holder::ADDRESS_BILLING, 'Avenida Faria Lima', '2927', 'Itaim', 'Sao Paulo', 'SP', '01234000', 'Apt 101');
+ ->setAddress('BILLING', 'Avenida Faria Lima', '2927', 'Itaim', 'Sao Paulo', 'SP', '01234000', 'Apt 101');
```
##### Com hash
> Para mais detalhes sobre a geração de hash com os dados do cartão [consulte a documentação.](https://dev.moip.com.br/docs/criptografia-de-cartao)
@@ -404,6 +417,12 @@ $refund = $payment->refunds()
);
print_r($refund);
```
+
+### Consultar reembolso
+```php
+$refund = $payment->refunds()->get($refund_id);
+```
+
## OAuth (Moip Connect)
### Solicitar permissões de acesso ao usuário
Para solicitar as permissões você deverá invocar o método getAuthUrl (que monta a URL) e redirecionar o usuário para a URL gerada. O usuário deverá conceder a permissão e então ele será redirecionado para a URL determinada pelo seu App e passada como atributo para o objeto Connect.
@@ -559,6 +578,55 @@ $keys = $moip->keys()->get();
print_r($keys);
```
+## Saldo Moip
+O Saldo é a composição de valores atuais disponíveis, indisponíveis (bloqueados) e futuros de uma determinada **Conta Moip**.
+
+> Esta API está na versão 2.1, contendo o _header_ **Accept**, com o valor `application/json;version=2.1`.
+### Consultar saldos
+```php
+$balances = $moip->balances()->get();
+```
+
+_Requer autenticação `OAuth`._
+
+## Conta Bancária
+A Conta bancária é o domicílio bancário de uma determinada Conta Moip. Esta API permite a criação, a consulta e a alteração dos dados de uma Conta Bancária.
+
+### Criar Conta Bancária
+```php
+$bank_account = $moip->bankaccount()
+ ->setBankNumber('237')
+ ->setAgencyNumber('12345')
+ ->setAgencyCheckNumber('0')
+ ->setAccountNumber('12345678')
+ ->setAccountCheckNumber('7')
+ ->setType('CHECKING')
+ ->setHolder('Demo Moip', '622.134.533-22', 'CPF')
+ ->create($moip_account_id);
+```
+
+### Consultar Conta Bancária
+```php
+$bank_account = $moip->bankaccount()->get($bank_account_id);
+```
+
+### Listar Contas Bancárias
+```php
+$bank_accounts = $moip->bankaccount()->getList($account_id)->getBankAccounts();
+```
+
+### Atualizar Conta Bancária
+```php
+$bank_account = $moip->bankaccount()
+ ->setAccountCheckNumber('8')
+ ->update($bank_account_id);
+```
+
+### Deletar Conta Bancária
+```php
+$moip->bankaccount()->delete($bank_account_id);
+```
+
## Preferências de notificação
### Criação
@@ -612,8 +680,11 @@ $moip->webhooks()->get(new Pagination(10, 0), 'ORD-ID', 'ORDER.PAID');
```
## Transferência
+A Transferência é uma movimentação de fundos entre uma Conta Moip e outra conta de pagamento (pode ser uma Conta bancária ou uma determinada Conta Moip).
### Criando/executando uma transferência
+#### Por conta bancária
+
```php
$amount = 500;
$bank_number = '001';
@@ -632,82 +703,37 @@ $transfer = $moip->transfers()
print_r($transfer);
```
-### Consulta
-#### Transferência específica
-```php
-$transfer_id = 'TRA-28HRLYNLMUFH';
-$transfer = $this->moip->transfers()->get($transfer_id);
-
-print_r($transfer);
-```
-
-#### Todas transferências
-##### Sem paginação
-```php
-$transfers = $this->moip->transfers()->getList();
-```
-
-##### Com paginação
+Para realizar uma transferência utilizando uma conta bancária já cadastrada:
```php
-$transfers = $this->moip->transfers()->getList(new Pagination(10,0));
+$transfer = $moip->transfers()
+ ->setTransfersToBankAccount($amount, $bank_account_id)
+ ->execute();
```
-### Reverter
+### Consultar transferência
```php
$transfer_id = 'TRA-28HRLYNLMUFH';
+$transfer = $moip->transfers()->get($transfer_id);
-$transfer = $this->moip->transfers()->revert($transfer_id);
-```
-
-## Contas bancárias
-
-### Criação
-```php
-$account_id = 'MPA-05E8C79EAAAA';
-$bank_account = $moip->bankaccount()
- ->setBankNumber('237')
- ->setAgencyNumber('12345')
- ->setAgencyCheckNumber('0')
- ->setAccountNumber('12345678')
- ->setAccountCheckNumber('7')
- ->setType('CHECKING')
- ->setHolder('Demo Moip', '622.134.533-22', 'CPF')
- ->create($account_id);
-
-print_r($bank_account);
-```
-
-### Consulta
-#### Conta bancária específica
-```php
-$bank_account_id = 'BKA-397X21X1G6LT';
-$bank_account = $moip->bankaccount()->get($bank_account_id);
-
-print_r($bank_account);
+print_r($transfer);
```
-#### Todas contas bancárias
+### Listar transferências
+#### Sem paginação
```php
-$account_id = 'MPA-05E8C79EAAAA';
-$bank_accounts = $moip->bankaccount()->getList($account_id)->getBankAccounts();
-
-print_r($bank_accounts);
+$transfers = $moip->transfers()->getList();
```
-### Exclusão
+#### Com paginação
```php
-$bank_account_id = 'BKA-397X21X1G6LT';
-$moip->bankaccount()->delete($bank_account_id);
+$transfers = $moip->transfers()->getList(new Pagination(10,0));
```
-### Atualização
+### Reverter transferência
```php
-$bank_account_id = 'BKA-397X21X1G6LT';
-$bank_account = $moip->bankaccount()->get($bank_account_id);
-$bank_account->setAccountCheckNumber('7');
-$bank_account->update();
+$transfer_id = 'TRA-28HRLYNLMUFH';
-print_r($bank_account);
+$transfer = $moip->transfers()->revert($transfer_id);
```
## Tratamento de Exceções
diff --git a/src/Moip.php b/src/Moip.php
index ac4968a..9ad12a1 100644
--- a/src/Moip.php
+++ b/src/Moip.php
@@ -4,6 +4,7 @@
use Moip\Contracts\Authentication;
use Moip\Resource\Account;
+use Moip\Resource\Balances;
use Moip\Resource\BankAccount;
use Moip\Resource\Customer;
use Moip\Resource\Entry;
@@ -49,7 +50,7 @@ class Moip
*
* @const string
*/
- const CLIENT_VERSION = '3.0.0';
+ const CLIENT_VERSION = '3.1.0';
/**
* Authentication that will be added to the header of request.
@@ -257,6 +258,16 @@ public function bankaccount()
return new BankAccount($this);
}
+ /**
+ * Create a new Balances instance.
+ *
+ * @return Balances
+ */
+ public function balances()
+ {
+ return new Balances($this);
+ }
+
/**
* Get the endpoint.
*
diff --git a/src/Resource/Account.php b/src/Resource/Account.php
index 4345fca..db20109 100644
--- a/src/Resource/Account.php
+++ b/src/Resource/Account.php
@@ -54,6 +54,7 @@ public function initialize()
$this->data->email = new stdClass();
$this->data->person = new stdClass();
$this->data->person->alternativePhones = [];
+ $this->data->businessSegment = new stdClass();
$this->data->type = self::ACCOUNT_TYPE;
}
@@ -363,6 +364,36 @@ public function getType()
return $this->getIfSet('type', $this->data);
}
+ /**
+ * Get business segment id.
+ *
+ * @return int id.
+ */
+ public function getBusinessSegmentId()
+ {
+ return $this->getIfSet('id', $this->data->businessSegment);
+ }
+
+ /**
+ * Get business segment name.
+ *
+ * @return string name.
+ */
+ public function getBusinessSegmentName()
+ {
+ return $this->getIfSet('name', $this->data->businessSegment);
+ }
+
+ /**
+ * Get business segment mcc.
+ *
+ * @return int mcc.
+ */
+ public function getBusinessSegmentMcc()
+ {
+ return $this->getIfSet('mcc', $this->data->businessSegment);
+ }
+
/**
* Get transparent account (true/false).
*
@@ -383,6 +414,16 @@ public function getCreatedAt()
return $this->getIfSet('createdAt', $this->data);
}
+ /**
+ * Get link to set the password of created account.
+ *
+ * @return string
+ */
+ public function getPasswordLink()
+ {
+ return $this->getIfSet('href', $this->data->_links->setPassword);
+ }
+
/**
* Mount the seller structure from account.
*
@@ -434,8 +475,21 @@ protected function populate(stdClass $response)
$account->data->person->alternativePhones = $this->getIfSet('alternativePhones', $person);
+ $businessSegment = $this->getIfSet('businessSegment', $response);
+
+ $account->data->businessSegment->id = $this->getIfSet('id', $businessSegment);
+ $account->data->businessSegment->name = $this->getIfSet('name', $businessSegment);
+ $account->data->businessSegment->mcc = $this->getIfSet('mcc', $businessSegment);
+
$account->data->company = $this->getIfSet('company', $response);
- $account->data->_links = $this->getIfSet('_links', $response);
+ $account->data->_links = new stdClass();
+
+ $_links = $this->getIfSet('_links', $response);
+ $account->data->_links->setPassword = new stdClass();
+
+ $setPassword = $this->getIfSet('setPassword', $_links);
+ $account->data->_links->setPassword->href = $this->getIfSet('href', $setPassword);
+
$account->data->type = $this->getIfSet('type', $response);
$account->data->id = $this->getIfSet('id', $response);
$account->data->accessToken = $this->getIfSet('accessToken', $response);
diff --git a/src/Resource/Balances.php b/src/Resource/Balances.php
new file mode 100644
index 0000000..3ebc3a3
--- /dev/null
+++ b/src/Resource/Balances.php
@@ -0,0 +1,88 @@
+data = new stdClass();
+ $this->data->unavailable = [];
+ $this->data->future = [];
+ $this->data->current = [];
+ }
+
+ /**
+ * Populate this instance.
+ *
+ * @param stdClass $response response object
+ *
+ * @return mixed|Balances
+ */
+ protected function populate(stdClass $response)
+ {
+ $balances = clone $this;
+ $balances->data->unavailable = $this->getIfSet('unavailable', $response) ?: [];
+ $balances->data->future = $this->getIfSet('future', $response) ?: [];
+ $balances->data->current = $this->getIfSet('current', $response) ?: [];
+
+ return $balances;
+ }
+
+ /**
+ * Get all balances.
+ *
+ * @return stdClass
+ */
+ public function get()
+ {
+ $path = sprintf('/%s/%s', MoipResource::VERSION, self::PATH);
+
+ return $this->getByPath($path, ['Accept' => static::ACCEPT_VERSION]);
+ }
+
+ /**
+ * Get unavailable balances. Returns an array of objects with the amount and currency.
+ *
+ * @return array
+ */
+ public function getUnavailable()
+ {
+ return $this->data->unavailable;
+ }
+
+ /**
+ * Get future balances. Returns an array of objects with the amount and currency.
+ *
+ * @return array
+ */
+ public function getFuture()
+ {
+ return $this->data->future;
+ }
+
+ /**
+ * Get current balances. Returns an array of objects with the amount and currency.
+ *
+ * @return array
+ */
+ public function getCurrent()
+ {
+ return $this->data->current;
+ }
+}
diff --git a/src/Resource/MoipResource.php b/src/Resource/MoipResource.php
index da840cf..a73ca3c 100644
--- a/src/Resource/MoipResource.php
+++ b/src/Resource/MoipResource.php
@@ -24,6 +24,13 @@ abstract class MoipResource implements JsonSerializable
*/
const VERSION = 'v2';
+ /**
+ * Api version content type.
+ *
+ * @cont string
+ */
+ const ACCEPT_VERSION = 'application/json;version=2.1';
+
/**
* @var \Moip\Moip
*/
@@ -210,9 +217,10 @@ public function generateListPath(Pagination $pagination = null, Filters $filters
* Execute a http request. If payload == null no body will be sent. Empty body ('{}') is supported by sending a
* empty stdClass.
*
- * @param string $path
- * @param string $method
- * @param mixed|null $payload
+ * @param string $path request path
+ * @param string $method http method
+ * @param mixed|null $payload request body
+ * @param array $headers request headers
*
* @throws Exceptions\ValidationException if the API returns a 4xx http status code. Usually means invalid data was sent.
* @throws Exceptions\UnautorizedException if the API returns a 401 http status code. Check API token and key.
@@ -220,14 +228,13 @@ public function generateListPath(Pagination $pagination = null, Filters $filters
*
* @return stdClass
*/
- protected function httpRequest($path, $method, $payload = null)
+ protected function httpRequest($path, $method, $payload = null, $headers = [])
{
$http_sess = $this->moip->getSession();
- $headers = [];
$body = null;
if ($payload !== null) {
$body = json_encode($payload, JSON_UNESCAPED_SLASHES);
- if ($body) {// if it's json serializable
+ if ($body) { // if it's json serializable
$headers['Content-Type'] = 'application/json';
} else {
$body = null;
@@ -258,13 +265,14 @@ protected function httpRequest($path, $method, $payload = null)
/**
* Find by path.
*
- * @param string $path
+ * @param string $path resource path
+ * @param array $headers request headers
*
* @return stdClass
*/
- public function getByPath($path)
+ public function getByPath($path, $headers = [])
{
- $response = $this->httpRequest($path, Requests::GET);
+ $response = $this->httpRequest($path, Requests::GET, null, $headers);
if (is_array($response)) {
$response = (object) $response;
diff --git a/src/Resource/Orders.php b/src/Resource/Orders.php
index 6585c84..fa6b327 100644
--- a/src/Resource/Orders.php
+++ b/src/Resource/Orders.php
@@ -50,10 +50,11 @@ class Orders extends MoipResource
* @param int $quantity Product Quantity.
* @param string $detail Additional product description.
* @param int $price Initial value of the item.
+ * @param string category Product category. see: https://dev.moip.com.br/v2.1/reference#tabela-de-categorias-de-produtos.
*
* @return $this
*/
- public function addItem($product, $quantity, $detail, $price)
+ public function addItem($product, $quantity, $detail, $price, $category = 'OTHER_CATEGORIES')
{
if (!is_int($price)) {
throw new \UnexpectedValueException('Informe o valor do item como inteiro');
@@ -68,7 +69,7 @@ public function addItem($product, $quantity, $detail, $price)
$item->quantity = $quantity;
$item->detail = $detail;
$item->price = $price;
-
+ $item->category = $category;
$this->data->items[] = $item;
return $this;
diff --git a/src/Resource/Refund.php b/src/Resource/Refund.php
index 0c1cba1..ab86559 100644
--- a/src/Resource/Refund.php
+++ b/src/Resource/Refund.php
@@ -115,6 +115,18 @@ public function getId()
return $this->getIfSet('id');
}
+ /**
+ * Get a Refund.
+ *
+ * @param string $moip_id Refund id.
+ *
+ * @return stdClass
+ */
+ public function get($moip_id)
+ {
+ return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::PATH, $moip_id));
+ }
+
/**
* Get status from MoIP refund.
*
diff --git a/src/Resource/Transfers.php b/src/Resource/Transfers.php
index 415485c..404c4a0 100644
--- a/src/Resource/Transfers.php
+++ b/src/Resource/Transfers.php
@@ -52,7 +52,9 @@ protected function initialize()
protected function populate(stdClass $response)
{
$transfers = clone $this;
+
$transfers->data->id = $this->getIfSet('id', $response);
+ $transfers->data->ownId = $this->getIfSet('ownId', $response);
$transfers->data->amount = $this->getIfSet('amount', $response);
$transfer_instrument = $this->getIfSet('transferInstrument', $response);
@@ -61,6 +63,7 @@ protected function populate(stdClass $response)
$bank_account = $this->getIfSet('bankAccount', $transfer_instrument);
$transfers->data->transferInstrument->bankAccount = new stdClass();
+ $transfers->data->transferInstrument->bankAccount->id = $this->getIfSet('id', $bank_account);
$transfers->data->transferInstrument->bankAccount->type = $this->getIfSet('type', $bank_account);
$transfers->data->transferInstrument->bankAccount->bankNumber = $this->getIfSet('bankNumber', $bank_account);
$transfers->data->transferInstrument->bankAccount->agencyNumber = $this->getIfSet('agencyNumber', $bank_account);
@@ -112,6 +115,23 @@ public function setTransfers(
return $this;
}
+ /**
+ * Set info of transfers to a saved bank account.
+ *
+ * @param int $amount Amount
+ * @param string $bankAccountId Saved bank account id.
+ *
+ * @return $this
+ */
+ public function setTransfersToBankAccount($amount, $bankAccountId)
+ {
+ $this->data->amount = $amount;
+ $this->data->transferInstrument->method = self::METHOD;
+ $this->data->transferInstrument->bankAccount->id = $bankAccountId;
+
+ return $this;
+ }
+
/**
* Returns transfer.
*
@@ -122,6 +142,20 @@ public function getTransfers()
return $this->data;
}
+ /**
+ * Get own request id. external reference.
+ *
+ * @param mixed $ownId id
+ *
+ * @return $this
+ */
+ public function setOwnId($ownId)
+ {
+ $this->data->ownId = $ownId;
+
+ return $this;
+ }
+
/**
* Set info of holder.
*
@@ -212,4 +246,14 @@ public function getId()
{
return $this->getIfSet('id');
}
+
+ /**
+ * Get own request id. external reference.
+ *
+ * @return mixed
+ */
+ public function getOwnId()
+ {
+ return $this->getIfSet('ownId');
+ }
}
diff --git a/tests/Resource/AccountTest.php b/tests/Resource/AccountTest.php
index 6c57ed4..dc1fb38 100644
--- a/tests/Resource/AccountTest.php
+++ b/tests/Resource/AccountTest.php
@@ -24,6 +24,7 @@ public function testShouldCreateAccount()
->setPhone(11, 965213244, 55)
->addAlternativePhone(11, 912345678, 55)
->setTransparentAccount(false)
+ ->setBusinessSegment(5)
->addAddress('Av. Brigadeiro Faria Lima', 2927, 'Itaim', 'São Paulo', 'SP', '01234000', 'Apt. X', 'BRA')
->create();
@@ -35,6 +36,10 @@ public function testShouldCreateAccount()
$this->assertEquals('SSP', $account->getIdentityDocumentIssuer());
$this->assertEquals('2017-10-25', $account->getIdentityDocumentIssueDate());
$this->assertEquals('RG', $account->getIdentityDocumentType());
+ $this->assertEquals('https://desenvolvedor.moip.com.br/sandbox/AskForNewPassword.do?method=confirm&email=dev.moip%40labs.moip.com.br&code=8e3b306d59907f4a47508913956c96ba', $account->getPasswordLink());
+ $this->assertEquals(5, $account->getBusinessSegmentId());
+ $this->assertEquals('Antiguidades / Negociante de artes / Galerias', $account->getBusinessSegmentName());
+ $this->assertEquals(5971, $account->getBusinessSegmentMcc());
}
public function testShouldCreateAccountWithCompany()
diff --git a/tests/Resource/BalancesTest.php b/tests/Resource/BalancesTest.php
new file mode 100644
index 0000000..6572c56
--- /dev/null
+++ b/tests/Resource/BalancesTest.php
@@ -0,0 +1,23 @@
+mockHttpSession($this->body_balances);
+
+ $balances = $this->moip->balances()->get();
+ $current = $balances->getCurrent();
+ $future = $balances->getFuture();
+ $unavailable = $balances->getUnavailable();
+
+ $this->assertNotEmpty($current);
+ $this->assertNotEmpty($future);
+ $this->assertNotEmpty($unavailable);
+ $this->assertEquals(44592168, $current[0]->amount);
+ }
+}
diff --git a/tests/Resource/RefundTest.php b/tests/Resource/RefundTest.php
index 8668d3f..521640b 100644
--- a/tests/Resource/RefundTest.php
+++ b/tests/Resource/RefundTest.php
@@ -186,6 +186,21 @@ public function testRefundOrderBankAccountPartialWithResourceId()
$this->assertEquals('PARTIAL', $refund->getType());
}
+ public function testShouldGetRefund()
+ {
+ $payment = $this->paymentCreditCard();
+
+ $this->mockHttpSession($this->body_payment_refund_full_cc);
+ $refund_id = $payment->refunds()->creditCardFull()->getId();
+
+ $this->mockHttpSession($this->body_payment_refund_full_cc);
+ $refund = $payment->refunds()->get($refund_id);
+
+ $this->assertEquals($refund_id, $refund->getId());
+ $this->assertEquals('FULL', $refund->getType());
+ $this->assertEquals('COMPLETED', $refund->getStatus());
+ }
+
private function bankAccount()
{
return $this->moip->bankaccount()
diff --git a/tests/Resource/TransfersTest.php b/tests/Resource/TransfersTest.php
index 37f473b..ca9ba3a 100644
--- a/tests/Resource/TransfersTest.php
+++ b/tests/Resource/TransfersTest.php
@@ -26,12 +26,45 @@ private function createTransfer()
return $transfer;
}
+ private function createBankAccount()
+ {
+ $this->mockHttpSession($this->body_bank_account_create);
+
+ $account_id = 'MPA-3C5358FF2296';
+
+ $bank_account = $this->moip->bankaccount()
+ ->setBankNumber('237')
+ ->setAgencyNumber('12345')
+ ->setAgencyCheckNumber('0')
+ ->setAccountNumber('12345678')
+ ->setAccountCheckNumber('7')
+ ->setType('CHECKING')
+ ->setHolder('Demo Moip', '622.134.533-22', 'CPF')
+ ->create($account_id);
+
+ return $bank_account;
+ }
+
public function testShouldCreateTransfer()
{
$transfer = $this->createTransfer();
$this->assertNotEmpty($transfer->getId());
}
+ public function testShouldCreateTransferWithBankAccountId()
+ {
+ $bank_account = $this->createBankAccount();
+
+ $this->mockHttpSession($this->body_transfers_create);
+
+ $amount = 500;
+ $transfer = $this->moip->transfers()
+ ->setTransfersToBankAccount($amount, $bank_account->getId())
+ ->execute();
+
+ $this->assertNotEmpty($transfer->getId());
+ }
+
public function testShouldGetTransfer()
{
$transfer_id = $this->createTransfer()->getId();
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 4913bf6..afa8ccb 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -141,6 +141,11 @@ abstract class TestCase extends BaseTestCase
*/
protected $body_bank_account_update;
+ /**
+ * @var string response from moip API.
+ */
+ protected $body_balances;
+
/**
* @var string holds the last generated customer ownId. In mock mode it'll be always the default, but it changes on sandbox mode.
*/
@@ -243,6 +248,8 @@ public function __construct()
$this->body_bank_account_list = $this->readJsonFile('jsons/bank_account/list');
$this->body_bank_account_update = $this->readJsonFile('jsons/bank_account/update');
+
+ $this->body_balances = $this->readJsonFile('jsons/balances/get');
}
/**
@@ -374,8 +381,8 @@ public function createOrder()
}
$order = $this->moip->orders()->setCustomer($this->createCustomer())
- ->addItem('Nome do produto', 1, 'Mais info...', 100000)
- ->addItem('abacaxi', 2, 'Abacaxi de terra de areia', 990)
+ ->addItem('Nome do produto', 1, 'Mais info...', 100000, 'SHOES')
+ ->addItem('abacaxi', 2, 'Abacaxi de terra de areia', 990, 'OTHER_CATEGORIES')
->setDiscount(1000)
->setShippingAmount(1490)
->setOwnId($this->last_ord_id);
diff --git a/tests/jsons/account/create.json b/tests/jsons/account/create.json
index 93135f4..c948183 100644
--- a/tests/jsons/account/create.json
+++ b/tests/jsons/account/create.json
@@ -1 +1 @@
-{"id":"MPA-61B1FE0940A2","login":"fortestsminecustomercompany@mailinator.com","accessToken":"dbb1cee101444f7a9f74c576854b9103_v2","channelId":"APP-QGAGZRIX1CUF","type":"MERCHANT","transparentAccount":false,"email":{"address":"fortestsminecustomercompany@mailinator.com","confirmed":false},"person":{"name":"For tests","lastName":"Mine Customer Company","birthDate":"1990-01-01","taxDocument":{"type":"CPF","number":"028.229.218-73"},"address":{"street":"Av. Brigadeiro Faria Lima","streetNumber":"2927","district":"Itaim","zipcode":"01234000","zipCode":"01234000","city":"São Paulo","state":"SP","country":"BRA","complement":"Ap. X"},"phone":{"countryCode":"55","areaCode":"11","number":"965213244","verified":false,"phoneType":"not_informed"},"nationality":"BRA","identityDocument":{"number":"144563480","issuer":"SSP","issueDate":"2017-10-25","type":"RG"},"alternativePhones":[{"countryCode":"55","areaCode":"11","number":"912345678","verified":false,"phoneType":"not_informed"}],"birthPlace":"São Paulo","parentsName":{"father":"Father of Mine Customer","mother":"Mother of Mine Customer"}},"company":{"name":"Mine Customer Company","businessName":"Company Business","taxDocument":{"type":"CNPJ","number":"64.893.609/0001-10"},"address":{"street":"R. Company","streetNumber":"321","district":"Bairro Company","zipcode":"12345678","zipCode":"12345678","city":"São Paulo","state":"SP","country":"BRA","complement":"Ap. Y"},"phone":{"countryCode":"55","areaCode":"11","number":"987654321","verified":false,"phoneType":"not_informed"},"openingDate":"2017-10-20"},"businessSegment":{"id":33,"name":"Jogos online","mcc":null},"site":"https://www.meusite.com","createdAt":"2017-10-25T14:05:46.050Z","_links":{"self":{"href":"https://sandbox.moip.com.br/moipaccounts/MPA-61B1FE0940A2","title":null}}}
\ No newline at end of file
+{"id":"MPA-61B1FE0940A2","login":"fortestsminecustomercompany@mailinator.com","accessToken":"dbb1cee101444f7a9f74c576854b9103_v2","channelId":"APP-QGAGZRIX1CUF","type":"MERCHANT","transparentAccount":false,"email":{"address":"fortestsminecustomercompany@mailinator.com","confirmed":false},"person":{"name":"For tests","lastName":"Mine Customer Company","birthDate":"1990-01-01","taxDocument":{"type":"CPF","number":"028.229.218-73"},"address":{"street":"Av. Brigadeiro Faria Lima","streetNumber":"2927","district":"Itaim","zipcode":"01234000","zipCode":"01234000","city":"São Paulo","state":"SP","country":"BRA","complement":"Ap. X"},"phone":{"countryCode":"55","areaCode":"11","number":"965213244","verified":false,"phoneType":"not_informed"},"nationality":"BRA","identityDocument":{"number":"144563480","issuer":"SSP","issueDate":"2017-10-25","type":"RG"},"alternativePhones":[{"countryCode":"55","areaCode":"11","number":"912345678","verified":false,"phoneType":"not_informed"}],"birthPlace":"São Paulo","parentsName":{"father":"Father of Mine Customer","mother":"Mother of Mine Customer"}},"company":{"name":"Mine Customer Company","businessName":"Company Business","taxDocument":{"type":"CNPJ","number":"64.893.609/0001-10"},"address":{"street":"R. Company","streetNumber":"321","district":"Bairro Company","zipcode":"12345678","zipCode":"12345678","city":"São Paulo","state":"SP","country":"BRA","complement":"Ap. Y"},"phone":{"countryCode":"55","areaCode":"11","number":"987654321","verified":false,"phoneType":"not_informed"},"openingDate":"2017-10-20"},"businessSegment":{"id":5,"name":"Antiguidades / Negociante de artes / Galerias","mcc":5971},"site":"https://www.meusite.com","createdAt":"2017-10-25T14:05:46.050Z","_links":{"self":{"href":"https://sandbox.moip.com.br/moipaccounts/MPA-61B1FE0940A2","title":null},"setPassword":{"href":"https://desenvolvedor.moip.com.br/sandbox/AskForNewPassword.do?method=confirm&email=dev.moip%40labs.moip.com.br&code=8e3b306d59907f4a47508913956c96ba"}}}
\ No newline at end of file
diff --git a/tests/jsons/balances/get.json b/tests/jsons/balances/get.json
new file mode 100644
index 0000000..f7b017a
--- /dev/null
+++ b/tests/jsons/balances/get.json
@@ -0,0 +1 @@
+{"unavailable": [{"amount": 0, "currency": "BRL"}], "future": [{"amount": 0, "currency": "BRL"}], "current": [{"amount": 44592168, "currency": "BRL"}]}
\ No newline at end of file