Skip to content

Commit

Permalink
Merge pull request #35 from ionutcalara/master
Browse files Browse the repository at this point in the history
Add merchant apps support
  • Loading branch information
ionutcalara authored Sep 8, 2020
2 parents 2f53d8b + 0bbd02e commit bcdf66a
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 12 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ $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);
$all_apps = $merchants->apps()->find($merchant_id,$args);
$merchants->lines()->add($merchant_id,$app_id);
$merchants->lines()->revoke($merchant_id,$app_id);

$cards = $paylike->cards();
$cards->create($merchant_id, $args);
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Paylike client (PHP)

## 1.0.8 - 2020-09-8
### Added
- Add merchant apps support.

## 1.0.7 - 2020-09-2
### Changed
- Update composer to separate dev dependencies and update php version requirement.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "paylike/php-api",
"description": "PHP SDK to communicate with the Paylike HTTP API",
"version": "1.0.7",
"version": "1.0.8",
"license": "MIT",
"authors": [
{
Expand Down
72 changes: 72 additions & 0 deletions src/Endpoint/Merchant/Apps.php
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;
}

}
8 changes: 8 additions & 0 deletions src/Endpoint/Merchants.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,12 @@ public function lines()
{
return new Lines($this->paylike);
}

/**
* return Lines
*/
public function apps()
{
return new \Paylike\Endpoint\Merchant\Apps($this->paylike);
}
}
2 changes: 1 addition & 1 deletion src/Paylike.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Paylike
*/
private $api_key;

private $version = '1.0.7';
private $version = '1.0.8';


/**
Expand Down
59 changes: 59 additions & 0 deletions tests/MerchantsAppsTest.php
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);
}

}
26 changes: 16 additions & 10 deletions tests/MerchantsLinesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Paylike\Tests;

use Paylike\Endpoint\Merchant\Lines;
use Paylike\Paylike;

class MerchantsLinesTest extends BaseTest
{
Expand All @@ -14,7 +15,8 @@ class MerchantsLinesTest extends BaseTest
/**
*
*/
public function setUp() {
public function setUp()
{
parent::setUp();
$this->lines = $this->paylike->merchants()->lines();
}
Expand All @@ -23,10 +25,11 @@ public function setUp() {
/**
* @throws \Exception
*/
public function testGetAllLinesCursor() {
public function testGetAllLinesCursor()
{
$merchant_id = $this->merchant_id;
$api_lines = $this->lines->find($merchant_id);
$ids = array();
$api_lines = $this->lines->find($merchant_id);
$ids = array();
foreach ($api_lines as $line) {
// the lines array grows as needed
$ids[] = $line['id'];
Expand All @@ -38,11 +41,12 @@ public function testGetAllLinesCursor() {
/**
* @throws \Exception
*/
public function testGetAllLinesCursorBefore() {
public function testGetAllLinesCursorBefore()
{
$merchant_id = $this->merchant_id;
$before = '5da8594efd0c53603c7bb3a5';
$before = '5da8594efd0c53603c7bb3a5';
$api_lines = $this->lines->before($merchant_id, $before);
$ids = array();
$ids = array();
foreach ($api_lines as $line) {
// the lines array grows as needed
$ids[] = $line['id'];
Expand All @@ -54,16 +58,18 @@ public function testGetAllLinesCursorBefore() {
/**
* @throws \Exception
*/
public function testGetAllMerchantsCursorAfter() {
public function testGetAllMerchantsCursorAfter()
{
$merchant_id = $this->merchant_id;
$after = '5da8594efd0c53603c7bb3a5';
$after = '5da8594efd0c53603c7bb3a5';
$api_lines = $this->lines->after($merchant_id, $after);
$ids = array();
$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 bcdf66a

Please sign in to comment.