-
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 #35 from ionutcalara/master
Add merchant apps support
- Loading branch information
Showing
8 changed files
with
164 additions
and
12 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
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,72 @@ | ||
<?php | ||
|
||
namespace Paylike\Endpoint\Merchant; | ||
|
||
use Paylike\Endpoint\Endpoint; | ||
use Paylike\Utils\Cursor; | ||
|
||
/** | ||
* Class Apps | ||
* | ||
* @package Paylike\Endpoint\Merchant | ||
*/ | ||
class Apps extends Endpoint | ||
{ | ||
|
||
/** | ||
* @link https://github.com/paylike/api-docs#fetch-all-apps-on-a-merchant | ||
* | ||
* @param $merchant_id | ||
* @param array $args | ||
* @return Cursor | ||
* @throws \Exception | ||
*/ | ||
public function find($merchant_id, $args = array()) | ||
{ | ||
$url = 'merchants/' . $merchant_id . '/apps'; | ||
if (!isset($args['limit'])) { | ||
$args['limit'] = 10; | ||
} | ||
$api_response = $this->paylike->client->request('GET', $url, $args); | ||
$apps = $api_response->json; | ||
return new Cursor($url, $args, $apps, $this->paylike); | ||
} | ||
|
||
/** | ||
* @link https://github.com/paylike/api-docs#add-app-to-a-merchant | ||
* | ||
* @param $args array | ||
* | ||
* @return string | ||
*/ | ||
public function add($merchant_id, $app_id) | ||
{ | ||
$url = 'merchants/' . $merchant_id . '/apps'; | ||
|
||
$args = array( | ||
'appId' => $app_id | ||
); | ||
|
||
$api_response = $this->paylike->client->request('POST', $url, $args); | ||
|
||
return $api_response; | ||
} | ||
|
||
/** | ||
* @link https://github.com/paylike/api-docs#revoke-app-from-a-merchant | ||
* | ||
* @param $args array | ||
* | ||
* @return string | ||
*/ | ||
public function revoke($merchant_id, $app_id) | ||
{ | ||
$url = 'merchants/' . $merchant_id . '/apps/'.$app_id; | ||
|
||
|
||
$api_response = $this->paylike->client->request('DELETE', $url); | ||
|
||
return $api_response; | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -31,7 +31,7 @@ class Paylike | |
*/ | ||
private $api_key; | ||
|
||
private $version = '1.0.7'; | ||
private $version = '1.0.8'; | ||
|
||
|
||
/** | ||
|
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\Tests; | ||
|
||
use Paylike\Endpoint\Merchant\Apps; | ||
use Paylike\Paylike; | ||
|
||
class MerchantsAppsTest extends BaseTest | ||
{ | ||
/** | ||
* @var Apps | ||
*/ | ||
protected $apps; | ||
|
||
/** | ||
* | ||
*/ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->apps = $this->paylike->merchants()->apps(); | ||
} | ||
|
||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
public function testGetAllAppsCursor() | ||
{ | ||
$merchant_id = $this->merchant_id; | ||
$apps = $this->apps->find($merchant_id); | ||
$ids = array(); | ||
foreach ($apps as $app) { | ||
// the apps array grows as needed | ||
$ids[] = $app['id']; | ||
} | ||
|
||
$this->assertGreaterThan(0, count($ids), 'number of apps'); | ||
} | ||
|
||
public function testAdd() | ||
{ | ||
$merchant_id = $this->merchant_id; | ||
$app_id = '5f5637ab4691ba779dc2b9b3'; | ||
$response = $this->apps->add($merchant_id, $app_id); | ||
|
||
$this->assertEquals(201, $response->code); | ||
} | ||
|
||
public function testRevoke() | ||
{ | ||
$merchant_id = $this->merchant_id; | ||
$app_id = '5f5637ab4691ba779dc2b9b3'; | ||
$response = $this->apps->revoke($merchant_id, $app_id); | ||
|
||
$this->assertEquals(204, $response->code); | ||
} | ||
|
||
} |
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