-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from ionutcalara/master
Add lines support
- Loading branch information
Showing
6 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Paylike\Endpoint\Merchant; | ||
|
||
use Paylike\Endpoint\Endpoint; | ||
use Paylike\Utils\Cursor; | ||
|
||
/** | ||
* Class Lines | ||
* | ||
* @package Paylike\Endpoint\Merchant | ||
*/ | ||
class Lines extends Endpoint | ||
{ | ||
/** | ||
* @link https://github.com/paylike/api-docs#fetch-all-merchants | ||
* | ||
* @param $merchant_id | ||
* @param array $args | ||
* @return Cursor | ||
* @throws \Exception | ||
*/ | ||
public function find($merchant_id, $args = array()) | ||
{ | ||
$url = 'merchants/' . $merchant_id . '/lines'; | ||
if (!isset($args['limit'])) { | ||
$args['limit'] = 10; | ||
} | ||
$api_response = $this->paylike->client->request('GET', $url, $args); | ||
$lines = $api_response->json; | ||
return new Cursor($url, $args, $lines, $this->paylike); | ||
} | ||
|
||
/** | ||
* @link https://github.com/paylike/api-docs#fetch-all-lines-on-a-merchant | ||
* | ||
* @param $merchant_id | ||
* @param $line_id | ||
* @return Cursor | ||
* @throws \Exception | ||
*/ | ||
public function before($merchant_id, $line_id) | ||
{ | ||
return $this->find($merchant_id, array('before' => $line_id)); | ||
} | ||
|
||
/** | ||
* @link https://github.com/paylike/api-docs#fetch-all-lines-on-a-merchant | ||
* | ||
* @param $merchant_id | ||
* @param $line_id | ||
* @return Cursor | ||
* @throws \Exception | ||
*/ | ||
public function after($merchant_id, $line_id) | ||
{ | ||
return $this->find($merchant_id, array('after' => $line_id)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Paylike\Tests; | ||
|
||
use Paylike\Endpoint\Merchant\Lines; | ||
|
||
class MerchantsLinesTest extends BaseTest | ||
{ | ||
/** | ||
* @var Lines | ||
*/ | ||
protected $lines; | ||
|
||
/** | ||
* | ||
*/ | ||
public function setUp() { | ||
parent::setUp(); | ||
$this->lines = $this->paylike->merchants()->lines(); | ||
} | ||
|
||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
public function testGetAllLinesCursor() { | ||
$merchant_id = $this->merchant_id; | ||
$api_lines = $this->lines->find($merchant_id); | ||
$ids = array(); | ||
foreach ($api_lines as $line) { | ||
// the lines array grows as needed | ||
$ids[] = $line['id']; | ||
} | ||
|
||
$this->assertGreaterThan(0, count($ids), 'number of lines'); | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
public function testGetAllLinesCursorBefore() { | ||
$merchant_id = $this->merchant_id; | ||
$before = '5da8594efd0c53603c7bb3a5'; | ||
$api_lines = $this->lines->before($merchant_id, $before); | ||
$ids = array(); | ||
foreach ($api_lines as $line) { | ||
// the lines array grows as needed | ||
$ids[] = $line['id']; | ||
} | ||
|
||
$this->assertGreaterThan(0, count($api_lines), 'number of lines'); | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
public function testGetAllMerchantsCursorAfter() { | ||
$merchant_id = $this->merchant_id; | ||
$after = '5da8594efd0c53603c7bb3a5'; | ||
$api_lines = $this->lines->after($merchant_id, $after); | ||
$ids = array(); | ||
foreach ($api_lines as $line) { | ||
// the lines array grows as needed | ||
$ids[] = $line['id']; | ||
} | ||
|
||
$this->assertGreaterThan(0, count($api_lines), 'number of lines'); | ||
} | ||
} |