Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ $merchants = $paylike->merchants();
$merchants->create($args);
$merchants->fetch($merchant_id);
$merchants->update($merchant_id, $args);
$all_merchants = $merchants->get($app_id,$limit,$before);
$all_merchants = $merchants->find($app_id,$args);
$some_merchants = $merchants->before($app_id,$before);
$some_merchants = $merchants->after($app_id,$before);

$cards = $paylike->cards();
$cards->create($merchant_id, $args);
Expand All @@ -75,28 +77,13 @@ $transactions->fetch($transaction_id);
$transactions->capture($transaction_id, $args);
$transactions->void($transaction_id, $args);
$transactions->refund($transaction_id, $args);
$all_transactions = $transactions->get($merchant_id,$limit,$before);
$all_transactions = $transactions->find($merchant_id,$args);
$some_transactions = $transactions->before($merchant_id,$before);
$some_transactions = $transactions->after($merchant_id,$before);
```

## Pagination
The methods that allow fetching all transactions/merchants support pagination. By default they are limited to the last 10 items.
An example of handling pagination to fetch all available transactions:

```php
$transactions = array();
$limit = 10;
$before = null;

do {
$api_transactions = $this->transactions->get($merchant_id, $limit, $before);
if (count($api_transactions) < $limit) {
$before = null;
} else {
$before = $api_transactions[$limit - 1]['id'];
}
$transactions = array_merge($transactions, $api_transactions);
} while ($before);
```
The methods that return multiple merchants/transactions (find,after,before) use cursors, so you don't need to worry about pagination, you can access any index, or iterate all the items, this is handled in the background.

## Error handling

Expand Down
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Paylike client (PHP)

## 1.0.2 - 2018-09-12
### Changed
- Transactions and Merchants now support find and return a filter

### Removed
- Transactions and Merchants no longer have get method

## 1.0.1 - 2018-09-04
### Added
- This CHANGELOG file
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "paylike/php-api",
"description": "PHP SDK to communicate with the Paylike HTTP api",
"version": "1.0.1",
"version": "1.0.2",
"license": "MIT",
"authors": [
{
Expand Down
3 changes: 2 additions & 1 deletion src/Paylike.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class Paylike
* Paylike constructor.
*
* @param $api_key
* @param HttpClientInterface $client
* @param HttpClientInterface $client
* @throws Exception\ApiException
*/
public function __construct($api_key, HttpClientInterface $client = null)
{
Expand Down
51 changes: 40 additions & 11 deletions src/Resource/Merchants.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Paylike\Resource;

use Paylike\Utils\Cursor;

/**
* Class Merchants
*
Expand Down Expand Up @@ -56,20 +58,47 @@ public function update($merchant_id, $args)
}

/**
* https://github.com/paylike/api-docs#fetch-all-merchants
* @param int $app_id
* @param int $limit
* @param null $before
* @return array
* @link https://github.com/paylike/api-docs#fetch-all-merchants
*
* @param $app_id
* @param array $args
* @return Cursor
* @throws \Exception
*/
public function get($app_id, $limit = 10, $before = null)
public function find($app_id, $args = array())
{
$url = 'identities/' . $app_id . '/merchants?limit=' . $limit;
if ($before) {
$url .= '&before=' . $before;
$url = 'identities/' . $app_id . '/merchants';
if (!isset($args['limit'])) {
$args['limit'] = 10;
}
$api_response = $this->paylike->client->request('GET', $url);
$api_response = $this->paylike->client->request('GET', $url, $args);
$merchants = $api_response->json;
return $merchants;
return new Cursor($url, $args, $merchants, $this->paylike);
}

/**
* @link https://github.com/paylike/api-docs#fetch-all-merchants
*
* @param $app_id
* @param $merchant_id
* @return Cursor
* @throws \Exception
*/
public function before($app_id, $merchant_id)
{
return $this->find($app_id, array('before' => $merchant_id));
}

/**
* @link https://github.com/paylike/api-docs#fetch-all-merchants
*
* @param $app_id
* @param $merchant_id
* @return Cursor
* @throws \Exception
*/
public function after($app_id, $merchant_id)
{
return $this->find($app_id, array('after' => $merchant_id));
}
}
48 changes: 39 additions & 9 deletions src/Resource/Transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Paylike\Resource;

use Paylike\Utils\Cursor;

/**
* Class Transactions
*
Expand Down Expand Up @@ -97,16 +99,44 @@ public function refund($transaction_id, $args)
* @link https://github.com/paylike/api-docs#fetch-all-transactions
*
* @param $merchant_id
* @param int $limit
* @param null $before
* @param array $args
* @return Cursor
* @throws \Exception
*/
public function get($merchant_id, $limit = 10, $before = null){
$url = 'merchants/' . $merchant_id . '/transactions?limit=' . $limit;
if ($before) {
$url .= '&before=' . $before;
public function find($merchant_id, $args = array())
{
$url = 'merchants/' . $merchant_id . '/transactions';
if (!isset($args['limit'])) {
$args['limit'] = 10;
}
$api_response = $this->paylike->client->request('GET', $url);
$merchants = $api_response->json;
return $merchants;
$api_response = $this->paylike->client->request('GET', $url, $args);
$transactions = $api_response->json;
return new Cursor($url, $args, $transactions, $this->paylike);
}

/**
* @link https://github.com/paylike/api-docs#fetch-all-transactions
*
* @param $merchant_id
* @param $transaction_id
* @return Cursor
* @throws \Exception
*/
public function before($merchant_id, $transaction_id)
{
return $this->find($merchant_id, array('before' => $transaction_id));
}

/**
* @link https://github.com/paylike/api-docs#fetch-all-transactions
*
* @param $merchant_id
* @param $transaction_id
* @return Cursor
* @throws \Exception
*/
public function after($merchant_id, $transaction_id)
{
return $this->find($merchant_id, array('after' => $transaction_id));
}
}
Loading