Skip to content

Commit 0bbd02e

Browse files
committed
Add merchant apps support
1 parent 2f53d8b commit 0bbd02e

8 files changed

Lines changed: 164 additions & 12 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ $some_merchants = $merchants->after($app_id,$before);
6969
$all_lines = $merchants->lines()->find($merchant_id,$args);
7070
$some_lines = $merchants->lines()->before($merchant_id,$before);
7171
$some_lines = $merchants->lines()->after($merchant_id, $after);
72+
$all_apps = $merchants->apps()->find($merchant_id,$args);
73+
$merchants->lines()->add($merchant_id,$app_id);
74+
$merchants->lines()->revoke($merchant_id,$app_id);
7275

7376
$cards = $paylike->cards();
7477
$cards->create($merchant_id, $args);

changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## Paylike client (PHP)
88

9+
## 1.0.8 - 2020-09-8
10+
### Added
11+
- Add merchant apps support.
12+
913
## 1.0.7 - 2020-09-2
1014
### Changed
1115
- Update composer to separate dev dependencies and update php version requirement.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "paylike/php-api",
33
"description": "PHP SDK to communicate with the Paylike HTTP API",
4-
"version": "1.0.7",
4+
"version": "1.0.8",
55
"license": "MIT",
66
"authors": [
77
{

src/Endpoint/Merchant/Apps.php

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

src/Endpoint/Merchants.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,12 @@ public function lines()
110110
{
111111
return new Lines($this->paylike);
112112
}
113+
114+
/**
115+
* return Lines
116+
*/
117+
public function apps()
118+
{
119+
return new \Paylike\Endpoint\Merchant\Apps($this->paylike);
120+
}
113121
}

src/Paylike.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Paylike
3131
*/
3232
private $api_key;
3333

34-
private $version = '1.0.7';
34+
private $version = '1.0.8';
3535

3636

3737
/**

tests/MerchantsAppsTest.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\Tests;
4+
5+
use Paylike\Endpoint\Merchant\Apps;
6+
use Paylike\Paylike;
7+
8+
class MerchantsAppsTest extends BaseTest
9+
{
10+
/**
11+
* @var Apps
12+
*/
13+
protected $apps;
14+
15+
/**
16+
*
17+
*/
18+
public function setUp()
19+
{
20+
parent::setUp();
21+
$this->apps = $this->paylike->merchants()->apps();
22+
}
23+
24+
25+
/**
26+
* @throws \Exception
27+
*/
28+
public function testGetAllAppsCursor()
29+
{
30+
$merchant_id = $this->merchant_id;
31+
$apps = $this->apps->find($merchant_id);
32+
$ids = array();
33+
foreach ($apps as $app) {
34+
// the apps array grows as needed
35+
$ids[] = $app['id'];
36+
}
37+
38+
$this->assertGreaterThan(0, count($ids), 'number of apps');
39+
}
40+
41+
public function testAdd()
42+
{
43+
$merchant_id = $this->merchant_id;
44+
$app_id = '5f5637ab4691ba779dc2b9b3';
45+
$response = $this->apps->add($merchant_id, $app_id);
46+
47+
$this->assertEquals(201, $response->code);
48+
}
49+
50+
public function testRevoke()
51+
{
52+
$merchant_id = $this->merchant_id;
53+
$app_id = '5f5637ab4691ba779dc2b9b3';
54+
$response = $this->apps->revoke($merchant_id, $app_id);
55+
56+
$this->assertEquals(204, $response->code);
57+
}
58+
59+
}

tests/MerchantsLinesTest.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Paylike\Tests;
44

55
use Paylike\Endpoint\Merchant\Lines;
6+
use Paylike\Paylike;
67

78
class MerchantsLinesTest extends BaseTest
89
{
@@ -14,7 +15,8 @@ class MerchantsLinesTest extends BaseTest
1415
/**
1516
*
1617
*/
17-
public function setUp() {
18+
public function setUp()
19+
{
1820
parent::setUp();
1921
$this->lines = $this->paylike->merchants()->lines();
2022
}
@@ -23,10 +25,11 @@ public function setUp() {
2325
/**
2426
* @throws \Exception
2527
*/
26-
public function testGetAllLinesCursor() {
28+
public function testGetAllLinesCursor()
29+
{
2730
$merchant_id = $this->merchant_id;
28-
$api_lines = $this->lines->find($merchant_id);
29-
$ids = array();
31+
$api_lines = $this->lines->find($merchant_id);
32+
$ids = array();
3033
foreach ($api_lines as $line) {
3134
// the lines array grows as needed
3235
$ids[] = $line['id'];
@@ -38,11 +41,12 @@ public function testGetAllLinesCursor() {
3841
/**
3942
* @throws \Exception
4043
*/
41-
public function testGetAllLinesCursorBefore() {
44+
public function testGetAllLinesCursorBefore()
45+
{
4246
$merchant_id = $this->merchant_id;
43-
$before = '5da8594efd0c53603c7bb3a5';
47+
$before = '5da8594efd0c53603c7bb3a5';
4448
$api_lines = $this->lines->before($merchant_id, $before);
45-
$ids = array();
49+
$ids = array();
4650
foreach ($api_lines as $line) {
4751
// the lines array grows as needed
4852
$ids[] = $line['id'];
@@ -54,16 +58,18 @@ public function testGetAllLinesCursorBefore() {
5458
/**
5559
* @throws \Exception
5660
*/
57-
public function testGetAllMerchantsCursorAfter() {
61+
public function testGetAllMerchantsCursorAfter()
62+
{
5863
$merchant_id = $this->merchant_id;
59-
$after = '5da8594efd0c53603c7bb3a5';
64+
$after = '5da8594efd0c53603c7bb3a5';
6065
$api_lines = $this->lines->after($merchant_id, $after);
61-
$ids = array();
66+
$ids = array();
6267
foreach ($api_lines as $line) {
6368
// the lines array grows as needed
6469
$ids[] = $line['id'];
6570
}
6671

6772
$this->assertGreaterThan(0, count($api_lines), 'number of lines');
6873
}
74+
6975
}

0 commit comments

Comments
 (0)