Skip to content

Commit

Permalink
endpoints: add the search endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sfwill-dev authored and murilohns committed May 13, 2020
1 parent f271a31 commit 7158c6f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ Você pode acessar a documentação oficial do Pagar.me acessando esse [link](ht
- [Retornando links de pagamento](#retornando-links-de-pagamento)
- [Retornando um link de pagamento](#retornando-um-link-de-pagamento)
- [Cancelando um link de pagamento](#cancelando-um-link-de-pagamento)
- [Buscas avançadas (Elasticsearch)](#buscas-avançadas-elasticsearch)
- [Realizando uma busca](#realizando-uma-busca)

## Instalação

Expand Down Expand Up @@ -1154,3 +1156,21 @@ $canceledPaymentLink = $pagarme->paymentLinks()->cancel([
'id' => 'ID_DO_LINK_DE_PAGAMENTO'
]);
```

## Buscas avançadas (Elasticsearch)

### Realizando uma busca

```php
<?php
$search = $pagarme->search()->get([
"type" => "transaction",
"query" => [
"query" => [
"terms" => [
"items.id" => [8, 9] // Busca transações com itens de ID 8 e 9
]
]
]
]);
```
15 changes: 15 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use PagarMe\Endpoints\Payables;
use PagarMe\Endpoints\BalanceOperations;
use PagarMe\Endpoints\Chargebacks;
use PagarMe\Endpoints\Search;
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Exception\ClientException as ClientException;
use PagarMe\Exceptions\InvalidJsonException;
Expand Down Expand Up @@ -126,6 +127,11 @@ class Client
*/
private $chargebacks;

/**
* @var \PagarMe\Endpoints\Search
*/
private $search;

/**
* @param string $apiKey
* @param array|null $extras
Expand Down Expand Up @@ -164,6 +170,7 @@ public function __construct($apiKey, array $extras = null)
$this->payables = new Payables($this);
$this->balanceOperations = new BalanceOperations($this);
$this->chargebacks = new Chargebacks($this);
$this->search = new Search($this);
}

/**
Expand Down Expand Up @@ -365,4 +372,12 @@ public function chargebacks()
{
return $this->chargebacks;
}

/**
* @return \PagarMe\Endpoints\Search
*/
public function search()
{
return $this->search;
}
}
24 changes: 24 additions & 0 deletions src/Endpoints/Search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace PagarMe\Endpoints;

use PagarMe\Client;
use PagarMe\Routes;
use PagarMe\Endpoints\Endpoint;

class Search extends Endpoint
{
/**
* @param array|null $payload
*
* @return \ArrayObject
*/
public function get(array $payload = null)
{
return $this->client->request(
self::GET,
Routes::search()->base(),
['query' => $payload]
);
}
}
15 changes: 15 additions & 0 deletions src/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,19 @@ public static function chargebacks()

return $anonymous;
}


/**
* @return \PagarMe\Anonymous
*/
public static function search()
{
$anonymous = new Anonymous();

$anonymous->base = static function () {
return "search";
};

return $anonymous;
}
}

0 comments on commit 7158c6f

Please sign in to comment.