Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
[RELEASE] v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
joaolucasl authored Sep 29, 2017
2 parents 4a5840e + 32efdae commit 1f0278f
Show file tree
Hide file tree
Showing 33 changed files with 615 additions and 43 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ 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).

<a name="v2.0.0"></a>
### [2.0.0](https://github.com/moip/moip-sdk-php/compare/v1.3.2...v2.0.0) (2017-09-29)

### Features

* **Account:** Create method to check if an account exists ([17e6cd2](https://github.com/moip/moip-sdk-php/commit/17e6cd2))
* **Webhooks:** Create method to get a list of webhooks([fa4a7d4](https://github.com/moip/moip-sdk-php/commit/fa4a7d49c2650813592a1f764be51e336247a9f5))
* added methods to get boleto print link and token from webhook([ab158a6](https://github.com/moip/moip-sdk-php/commit/ab158a6746cc75138111353301c5c066af8b962e))

## BREAKING CHANGES
Method `generateListPath` from MoipResource changed last parameter to array instead string.

<a name="v1.3.2"></a>
### [1.3.2](https://github.com/moip/moip-sdk-php/compare/v1.3.0...v1.3.2) (2017-09-18)

Expand Down
118 changes: 111 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/9e877cf78f844b9a9e40cec175c3aa5a)](https://www.codacy.com/app/jeancesargarcia/moip-sdk-php?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=moip/moip-sdk-php&amp;utm_campaign=Badge_Grade)
[![StyleCI](https://styleci.io/repos/19941899/shield)](https://styleci.io/repos/19941899)
[![Build Status](https://travis-ci.org/moip/moip-sdk-php.svg?branch=master)](https://travis-ci.org/moip/moip-sdk-php)
[![Circleci Status](https://circleci.com/gh/moip/moip-sdk-php/tree/analysis-qg67K6.svg?style=shield)](#)

> Estatísticas
Expand All @@ -34,6 +33,8 @@
- [Clientes](#clientes)
- [Criação](#criando-um-comprador)
- [Consulta](#consultando-os-dados-de-um-comprador)
- [Adicionar cartão de crédito](#adicionar-cartão-de-crédito)
- [Deletar cartão de crédito](#deletar-cartão-de-crédito)
- [Pedidos](#pedidos)
- [Criação](#criando-um-pedido-com-o-comprador-que-acabamos-de-criar)
- [Consulta](#consultando-um-pedido)
Expand All @@ -55,7 +56,12 @@
- [Consulta](#consultando-um-multipedido)
- [Multipagamentos](#multipagamentos)
- [Criação](#criando-um-multipagamento)
- [Webhooks](#webhooks)
- [Conta Moip](#conta-moip)
- [Criação](#criação)
- [Consulta](#consulta-3)
- [Verifica se usuário já possui Conta Moip](#verifica-se-usuário-já-possui-conta-moip)
- [Webhooks](#webhooks)
- [Consulta](#consulta-4)
- [Packages](#packages)
- [Documentação](#documentação)
- [Testes](#testes)
Expand Down Expand Up @@ -144,6 +150,33 @@ try {
}
```

### Adicionar cartão de crédito
```php
try {
$customer = $moip->customers()->creditCard()
->setExpirationMonth('05')
->setExpirationYear(2018)
->setNumber('4012001037141112')
->setCVC('123')
->setFullName('Jose Portador da Silva')
->setBirthDate('1988-12-30')
->setTaxDocument('CPF', '33333333333')
->setPhone('55','11','66778899')
->create(CUSTOMER_ID);
} catch (Exception $e) {
printf($e->__toString());
}
```

### Deletar cartão de crédito
```php
try {
$moip->customers()->creditCard()->delete(CREDIT_CARD_ID);
} catch (Exception $e) {
printf($e->__toString());
}
```

## Pedidos
### Criando um pedido com o comprador que acabamos de criar
Nesse exemplo com vários produtos e ainda especificando valor de frete, valor adicional e ainda valor de desconto.
Expand Down Expand Up @@ -350,16 +383,75 @@ try {
$hash = 'i1naupwpTLrCSXDnigLLTlOgtm+xBWo6iX54V/hSyfBeFv3rvqa1VyQ8/pqWB2JRQX2GhzfGppXFPCmd/zcmMyDSpdnf1GxHQHmVemxu4AZeNxs+TUAbFWsqEWBa6s95N+O4CsErzemYZHDhsjEgJDe17EX9MqgbN3RFzRmZpJqRvqKXw9abze8hZfEuUJjC6ysnKOYkzDBEyQibvGJjCv3T/0Lz9zFruSrWBw+NxWXNZjXSY0KF8MKmW2Gx1XX1znt7K9bYNfhA/QO+oD+v42hxIeyzneeRcOJ/EXLEmWUsHDokevOkBeyeN4nfnET/BatcDmv8dpGXrTPEoxmmGQ==';
$payment = $multiorder->multipayments()
->setCreditCardHash($hash, $customer)
->setInstallmentCount(3)
->setStatementDescriptor('teste de pag')
->setDelayCapture(false)
->execute();
print_r($payment);
->setInstallmentCount(3)
->setStatementDescriptor('teste de pag')
->setDelayCapture(false)
->execute();
print_r($payment);
} catch (Exception $e) {
printf($e->__toString());
}
```

## Conta Moip

### Criação
```php
try {
$street = 'Rua de teste';
$number = 123;
$district = 'Bairro';
$city = 'Sao Paulo';
$state = 'SP';
$zip = '01234567';
$complement = 'Apt. 23';
$country = 'BRA';
$area_code = 11;
$phone_number = 66778899;
$country_code = 55;
$identity_document = '4737283560';
$issuer = 'SSP';
$issue_date = '2015-06-23';
$account = $moip->accounts()
->setName('Fulano')
->setLastName('De Tal')
->setEmail('[email protected]')
->setIdentityDocument($identity_document, $issuer, $issue_date)
->setBirthDate('1988-12-30')
->setTaxDocument('16262131000')
->setType('MERCHANT')
->setPhone($area_code, $phone_number, $country_code)
->addAlternativePhone(11, 66448899, 55)
->addAddress($street, $number, $district, $city, $state, $zip, $complement, $country)
->setCompanyName('Empresa Teste', 'Teste Empresa ME')
->setCompanyOpeningDate('2011-01-01')
->setCompanyPhone(11, 66558899, 55)
->setCompanyTaxDocument('69086878000198')
->setCompanyAddress('Rua de teste 2', 123, 'Bairro Teste', 'Sao Paulo', 'SP', '01234567', 'Apt. 23', 'BRA')
->setCompanyMainActivity('82.91-1/00', 'Atividades de cobranças e informações cadastrais')
->create();
print_r($account);
} catch (Exception $e) {
printf($e->__toString());
}
```

### Consulta
```php
try {
$account = $moip->accounts()->get(ACCOUNT_ID);
print_r($account);
} catch (Exception $e) {
printf($e->__toString());
}
```

### Verifica se usuário já possui conta Moip
```php
// retorna verdadeiro se já possui e falso caso não possuir conta Moip
$moip->accounts()->checkAccountExists(CPF);
```

## Webhooks
> O PHP, por padrão, está preparado para receber apenas alguns tipos de `content-type` (`application/x-www-form-urlencoded` e `multipart/form-data`). A plataforma do Moip, no entanto, envia dados no formato JSON, o qual a linguagem não está preparada para receber por padrão.
Para receber e acessar os dados enviados pelo Moip, você precisa adicionar o seguinte código ao seu arquivo que receberá os webhooks:
Expand All @@ -371,6 +463,18 @@ $json = file_get_contents('php://input');
$response = json_decode($json, true);
```

### Consulta

#### Sem paginação ou filtro por resource/evento
```php
$moip->webhooks()->get();
```

#### Com paginação e filtros por resource/evento
```php
$moip->webhooks()->get(new Pagination(10, 0), 'ORD-ID', 'ORDER.PAID');
```

## Documentação

[Documentação oficial](https://documentao-moip.readme.io/v2.0/reference)
Expand Down
8 changes: 8 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
{
"name": "Joao Batista Neto",
"email": "[email protected]"
},
{
"name": "Caio Gaspar",
"email": "[email protected]"
},
{
"name": "João Lucas Lucchetta",
"email": "[email protected]"
}
],
"require": {
Expand Down
11 changes: 11 additions & 0 deletions src/Moip.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Moip\Resource\Orders;
use Moip\Resource\Payment;
use Moip\Resource\Transfers;
use Moip\Resource\WebhookList;
use Requests_Session;

/**
Expand Down Expand Up @@ -202,6 +203,16 @@ public function notifications()
return new NotificationPreferences($this);
}

/**
* Create a new WebhookList instance.
*
* @return WebhookList
*/
public function webhooks()
{
return new WebhookList($this);
}

/**
* Get the endpoint.
*
Expand Down
23 changes: 23 additions & 0 deletions src/Resource/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Moip\Resource;

use Moip\Exceptions\ValidationException;
use stdClass;

/**
Expand Down Expand Up @@ -130,6 +131,28 @@ public function get($moip_id)
return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::PATH, $moip_id));
}

/**
* Check if an account exists.
*
* @param string $tax_document
*
* @return bool
*/
public function checkExistence($tax_document)
{
try {
$this->getByPathNoPopulate(sprintf('/%s/%s/%s?tax_document=%s', MoipResource::VERSION, self::PATH, 'exists', $tax_document));

return true;
} catch (ValidationException $e) {
if ($e->getStatusCode() != 404) {
throw new ValidationException($e->getStatusCode(), $e->getErrors());
}
}

return false;
}

/**
* Get account id.
*
Expand Down
50 changes: 50 additions & 0 deletions src/Resource/CustomerCreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,54 @@ public function setPhone($country_code, $area_code, $number)

return $this;
}

/**
* Get credit card id.
*
* @return string
*/
public function getId()
{
return $this->data->creditCard->id;
}

/**
* Get brand.
*
* @return string
*/
public function getBrand()
{
return $this->data->creditCard->brand;
}

/**
* Get first 6 characters from credit card.
*
* @return string
*/
public function getFirst6()
{
return $this->data->creditCard->first6;
}

/**
* Get last 4 characters from credit card.
*
* @return string
*/
public function getLast4()
{
return $this->data->creditCard->last4;
}

/**
* Get if a credit card was stored or not.
*
* @return bool
*/
public function getStore()
{
return $this->data->creditCard->store;
}
}
26 changes: 21 additions & 5 deletions src/Resource/MoipResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ public function generatePath($action, $id = null)
*
* @param Pagination $pagination
* @param Filters $filters
* @param string $qParam Query a specific value.
* @param array $params
*
* @return string
*/
public function generateListPath(Pagination $pagination = null, Filters $filters = null, $qParam = '')
public function generateListPath(Pagination $pagination = null, Filters $filters = null, $params = [])
{
$queryParams = [];

Expand All @@ -195,11 +195,15 @@ public function generateListPath(Pagination $pagination = null, Filters $filters
$queryParams['filters'] = $filters->__toString();
}

if (!empty($qParam)) {
$queryParams['q'] = $qParam;
if (!empty($params)) {
$queryParams = array_merge($queryParams, $params);
}

return sprintf('/%s/%s?%s', self::VERSION, static::PATH, http_build_query($queryParams));
if (!empty($queryParams)) {
return sprintf('/%s/%s?%s', self::VERSION, static::PATH, http_build_query($queryParams));
}

return sprintf('/%s/%s', self::VERSION, static::PATH);
}

/**
Expand Down Expand Up @@ -265,6 +269,18 @@ public function getByPath($path)
return $this->populate($response);
}

/**
* Find by path with no populate method.
*
* @param string $path
*
* @return stdClass
*/
public function getByPathNoPopulate($path)
{
return $this->httpRequest($path, Requests::GET);
}

/**
* Create a new item in Moip.
*
Expand Down
10 changes: 10 additions & 0 deletions src/Resource/NotificationPreferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ public function getId()
return $this->data->id;
}

/**
* Returns notification token.
*
* @return stdClass
*/
public function getToken()
{
return $this->data->token;
}

/**
* Create a new notification preference.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/OrdersList.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getOrders()
*/
public function get(Pagination $pagination = null, Filters $filters = null, $qParam = '')
{
return $this->getByPath($this->generateListPath($pagination, $filters, $qParam));
return $this->getByPath($this->generateListPath($pagination, $filters, ['q' => $qParam]));
}

protected function populate(stdClass $response)
Expand Down
Loading

0 comments on commit 1f0278f

Please sign in to comment.