Skip to content

Commit

Permalink
Merge pull request #30 from ionutcalara/master
Browse files Browse the repository at this point in the history
Add lines support
  • Loading branch information
ionutcalara committed Jun 11, 2020
2 parents 85cd1fd + 8aeafd5 commit 510f0fd
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ $merchants->update($merchant_id, $args);
$all_merchants = $merchants->find($app_id,$args);
$some_merchants = $merchants->before($app_id,$before);
$some_merchants = $merchants->after($app_id,$before);
$all_lines = $merchants->lines()->find($merchant_id,$args);
$some_lines = $merchants->lines()->before($merchant_id,$before);
$some_lines = $merchants->lines()->after($merchant_id, $after);

$cards = $paylike->cards();
$cards->create($merchant_id, $args);
Expand Down
59 changes: 59 additions & 0 deletions src/Endpoint/Merchant/Lines.php
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));
}
}
9 changes: 9 additions & 0 deletions src/Endpoint/Merchants.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Paylike\Endpoint;

use Paylike\Endpoint\Merchant\Lines;
use Paylike\Utils\Cursor;

/**
Expand Down Expand Up @@ -101,4 +102,12 @@ public function after($app_id, $merchant_id)
{
return $this->find($app_id, array('after' => $merchant_id));
}

/**
* return Lines
*/
public function lines()
{
return new Lines($this->paylike);
}
}
9 changes: 9 additions & 0 deletions src/Paylike.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Paylike
*/
private $api_key;

private $version = '1.0.6';


/**
* Paylike constructor.
Expand Down Expand Up @@ -86,4 +88,11 @@ public function cards()
{
return new Cards($this);
}

/**
* @return string
*/
public function getVersion(){
return $this->version;
}
}
1 change: 1 addition & 0 deletions tests/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ public function setUp()
$this->transaction_id = "5da8272132aad22568a511b7";
$this->merchant_id = "594d3c455be12d547cbe2ebe";
}

}
69 changes: 69 additions & 0 deletions tests/MerchantsLinesTest.php
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');
}
}

0 comments on commit 510f0fd

Please sign in to comment.