Skip to content

Commit 510f0fd

Browse files
authored
Merge pull request #30 from ionutcalara/master
Add lines support
2 parents 85cd1fd + 8aeafd5 commit 510f0fd

File tree

6 files changed

+150
-0
lines changed

6 files changed

+150
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ $merchants->update($merchant_id, $args);
6666
$all_merchants = $merchants->find($app_id,$args);
6767
$some_merchants = $merchants->before($app_id,$before);
6868
$some_merchants = $merchants->after($app_id,$before);
69+
$all_lines = $merchants->lines()->find($merchant_id,$args);
70+
$some_lines = $merchants->lines()->before($merchant_id,$before);
71+
$some_lines = $merchants->lines()->after($merchant_id, $after);
6972

7073
$cards = $paylike->cards();
7174
$cards->create($merchant_id, $args);

src/Endpoint/Merchant/Lines.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace Paylike\Endpoint\Merchant;
4+
5+
use Paylike\Endpoint\Endpoint;
6+
use Paylike\Utils\Cursor;
7+
8+
/**
9+
* Class Lines
10+
*
11+
* @package Paylike\Endpoint\Merchant
12+
*/
13+
class Lines extends Endpoint
14+
{
15+
/**
16+
* @link https://github.com/paylike/api-docs#fetch-all-merchants
17+
*
18+
* @param $merchant_id
19+
* @param array $args
20+
* @return Cursor
21+
* @throws \Exception
22+
*/
23+
public function find($merchant_id, $args = array())
24+
{
25+
$url = 'merchants/' . $merchant_id . '/lines';
26+
if (!isset($args['limit'])) {
27+
$args['limit'] = 10;
28+
}
29+
$api_response = $this->paylike->client->request('GET', $url, $args);
30+
$lines = $api_response->json;
31+
return new Cursor($url, $args, $lines, $this->paylike);
32+
}
33+
34+
/**
35+
* @link https://github.com/paylike/api-docs#fetch-all-lines-on-a-merchant
36+
*
37+
* @param $merchant_id
38+
* @param $line_id
39+
* @return Cursor
40+
* @throws \Exception
41+
*/
42+
public function before($merchant_id, $line_id)
43+
{
44+
return $this->find($merchant_id, array('before' => $line_id));
45+
}
46+
47+
/**
48+
* @link https://github.com/paylike/api-docs#fetch-all-lines-on-a-merchant
49+
*
50+
* @param $merchant_id
51+
* @param $line_id
52+
* @return Cursor
53+
* @throws \Exception
54+
*/
55+
public function after($merchant_id, $line_id)
56+
{
57+
return $this->find($merchant_id, array('after' => $line_id));
58+
}
59+
}

src/Endpoint/Merchants.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Paylike\Endpoint;
44

5+
use Paylike\Endpoint\Merchant\Lines;
56
use Paylike\Utils\Cursor;
67

78
/**
@@ -101,4 +102,12 @@ public function after($app_id, $merchant_id)
101102
{
102103
return $this->find($app_id, array('after' => $merchant_id));
103104
}
105+
106+
/**
107+
* return Lines
108+
*/
109+
public function lines()
110+
{
111+
return new Lines($this->paylike);
112+
}
104113
}

src/Paylike.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class Paylike
3131
*/
3232
private $api_key;
3333

34+
private $version = '1.0.6';
35+
3436

3537
/**
3638
* Paylike constructor.
@@ -86,4 +88,11 @@ public function cards()
8688
{
8789
return new Cards($this);
8890
}
91+
92+
/**
93+
* @return string
94+
*/
95+
public function getVersion(){
96+
return $this->version;
97+
}
8998
}

tests/BaseTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ public function setUp()
2222
$this->transaction_id = "5da8272132aad22568a511b7";
2323
$this->merchant_id = "594d3c455be12d547cbe2ebe";
2424
}
25+
2526
}

tests/MerchantsLinesTest.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace Paylike\Tests;
4+
5+
use Paylike\Endpoint\Merchant\Lines;
6+
7+
class MerchantsLinesTest extends BaseTest
8+
{
9+
/**
10+
* @var Lines
11+
*/
12+
protected $lines;
13+
14+
/**
15+
*
16+
*/
17+
public function setUp() {
18+
parent::setUp();
19+
$this->lines = $this->paylike->merchants()->lines();
20+
}
21+
22+
23+
/**
24+
* @throws \Exception
25+
*/
26+
public function testGetAllLinesCursor() {
27+
$merchant_id = $this->merchant_id;
28+
$api_lines = $this->lines->find($merchant_id);
29+
$ids = array();
30+
foreach ($api_lines as $line) {
31+
// the lines array grows as needed
32+
$ids[] = $line['id'];
33+
}
34+
35+
$this->assertGreaterThan(0, count($ids), 'number of lines');
36+
}
37+
38+
/**
39+
* @throws \Exception
40+
*/
41+
public function testGetAllLinesCursorBefore() {
42+
$merchant_id = $this->merchant_id;
43+
$before = '5da8594efd0c53603c7bb3a5';
44+
$api_lines = $this->lines->before($merchant_id, $before);
45+
$ids = array();
46+
foreach ($api_lines as $line) {
47+
// the lines array grows as needed
48+
$ids[] = $line['id'];
49+
}
50+
51+
$this->assertGreaterThan(0, count($api_lines), 'number of lines');
52+
}
53+
54+
/**
55+
* @throws \Exception
56+
*/
57+
public function testGetAllMerchantsCursorAfter() {
58+
$merchant_id = $this->merchant_id;
59+
$after = '5da8594efd0c53603c7bb3a5';
60+
$api_lines = $this->lines->after($merchant_id, $after);
61+
$ids = array();
62+
foreach ($api_lines as $line) {
63+
// the lines array grows as needed
64+
$ids[] = $line['id'];
65+
}
66+
67+
$this->assertGreaterThan(0, count($api_lines), 'number of lines');
68+
}
69+
}

0 commit comments

Comments
 (0)