Skip to content

Commit

Permalink
v1.2.2 - Laravel Pint Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
theposeidonas committed Oct 9, 2024
1 parent eecee6e commit 0a808ac
Show file tree
Hide file tree
Showing 58 changed files with 546 additions and 1,214 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
### Changelog

#### V1.2.2

**9 Ekim 2024**

- Laravel Pint Formatting

#### V1.2.1

**7 Ekim 2024**
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Paraşüt v4 API for Laravel Projects",
"keywords": ["laravel", "Parasut", "Paraşüt"],
"license": "MIT",
"version": "v1.2.1",
"version": "v1.2.2",
"authors": [
{
"name": "Baran Arda",
Expand All @@ -28,6 +28,7 @@
"test": "phpunit"
},
"require-dev": {
"laravel/pint": "^1.18",
"orchestra/testbench": "^6.0",
"phpunit/phpunit": "^8.0"
},
Expand Down
4 changes: 2 additions & 2 deletions config/parasut.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
|
*/

return [
return [
'username' => env('PARASUT_USERNAME'),
'password' => env('PARASUT_PASSWORD'),
'company_id' => env('PARASUT_COMPANY_ID'),
'client_id' => env('PARASUT_CLIENT_ID'),
'client_secret' => env('PARASUT_CLIENT_SECRET'),
'redirect_uri' => env('PARASUT_REDIRECT_URI'),
'api_url' => env('PARASUT_API_URL', 'https://api.parasut.com/v4/'),
];
];
24 changes: 9 additions & 15 deletions src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;


/**
* Paraşüt OAuth2 işlemleri
*/
Expand All @@ -15,7 +14,6 @@ class Auth

/**
* Auth constructor.
* @param array $config
*/
public function __construct(array $config)
{
Expand All @@ -24,14 +22,12 @@ public function __construct(array $config)

/**
* Get the cached token or fetch a new one.
*
* @return string
*/
public function getToken(): string
{
$accessToken = Cache::get('parachute_token');

if (!$accessToken) {
if (! $accessToken) {
return $this->fetchNewToken();
}

Expand All @@ -40,33 +36,31 @@ public function getToken(): string

/**
* Fetch a new access token from the OAuth endpoint.
*
* @return string
*/
private function fetchNewToken(): string
{
$tokenEndpoint = 'https://api.parasut.com/oauth/token';

try {
$response = Http::asForm()->post($tokenEndpoint, [
'grant_type' => 'password',
'client_id' => $this->config['client_id'],
'grant_type' => 'password',
'client_id' => $this->config['client_id'],
'client_secret' => $this->config['client_secret'],
'username' => $this->config['username'],
'password' => $this->config['password'],
'redirect_uri' => $this->config['redirect_uri'],
'username' => $this->config['username'],
'password' => $this->config['password'],
'redirect_uri' => $this->config['redirect_uri'],
]);

if ($response->successful()) {
$data = $response->json();
Cache::put('parachute_token', $data['access_token'], now()->addSeconds($data['expires_in']));

return $data['access_token'];
}

throw new \Exception('Token fetch failed: ' . $response->body());

throw new \Exception('Token fetch failed: '.$response->body());
} catch (\Exception $e) {
return 'Error: ' . $e->getMessage();
return 'Error: '.$e->getMessage();
}
}
}
21 changes: 20 additions & 1 deletion src/Contracts/ParasutV4.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,42 @@
interface ParasutV4
{
public function Account();

public function Transaction();

public function Bank();

public function Employee();

public function Receipt();

public function Salary();

public function Supplier();

public function Tax();

public function EArchive();

public function EBill();

public function ESmm();

public function Inbox();

public function Bill();

public function Customer();

public function Category();

public function Tag();

public function Product();

public function StockMovement();

public function Warehouse();

public function Waybill();
}
}
8 changes: 2 additions & 6 deletions src/Facades/Parasut.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@

namespace Theposeidonas\LaravelParasutApi\Facades;

use Theposeidonas\LaravelParasutApi\ParasutV4;
use Illuminate\Support\Facades\Facade;
use Theposeidonas\LaravelParasutApi\ParasutV4;

class Parasut extends Facade
{

/**
* @return string
*/
public static function getFacadeAccessor(): string
{
return ParasutV4::class;
}
}
}
59 changes: 12 additions & 47 deletions src/Models/Cash/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,14 @@
*/
class Account extends ParasutV4
{
/**
* @var string
*/
private string $serviceUrl;

/**
* @param $config
*/
public function __construct($config)
{
parent::__construct($config);
$this->serviceUrl = $this->config['api_url'].$this->config['company_id'].'/accounts';
}

/**
* @param array $parameters
* @return array
*/
public function index(array $parameters = []): array
{
Validator::validate($parameters, [
Expand All @@ -41,120 +31,95 @@ public function index(array $parameters = []): array
'filter.iban' => 'nullable|string',
'sort' => 'nullable|string|in:id,balance,balance_in_trl,-id,-balance,-balance_in_trl',
'page.number' => 'nullable|integer|min:1',
'page.size' => 'nullable|integer|min:1|max:25'
'page.size' => 'nullable|integer|min:1|max:25',
]);

$response = Http::withHeaders([
'Authorization' => 'Bearer '.$this->token,
'Content-Type' => 'application/json',
])->get($this->serviceUrl, $parameters);

return $this->handleResponse($response);
}

/**
* @param array $data
* @return array
*/
public function create(array $data): array
{
$response = Http::withHeaders([
'Authorization' => 'Bearer '.$this->token,
'Content-Type' => 'application/json',
])->post($this->serviceUrl, $data);

return $this->handleResponse($response);
}

/**
* @param string $id
* @return array
*/
public function show(string $id): array
{
$response = Http::withHeaders([
'Authorization' => 'Bearer '.$this->token,
'Content-Type' => 'application/json',
])->get($this->serviceUrl.'/'.$id);

return $this->handleResponse($response);
}

/**
* @param string $id
* @param array $data
* @return array
*/
public function edit(string $id, array $data): array
{
$response = Http::withHeaders([
'Authorization' => 'Bearer '.$this->token,
'Content-Type' => 'application/json',
])->put($this->serviceUrl.'/'.$id, $data);

return $this->handleResponse($response);
}

/**
* @param string $id
* @return array
*/
public function delete(string $id): array
{
$response = Http::withHeaders([
'Authorization' => 'Bearer '.$this->token,
'Content-Type' => 'application/json',
])->delete($this->serviceUrl.'/'.$id);

return $this->handleResponse($response);
}

/**
* @param string $id
* @param array $parameters
* @return array
*/
public function transactions(string $id, array $parameters = []): array
{
Validator::validate($parameters, [
'filter.date' => 'nullable|string',
'sort' => 'nullable|string|in:id,-id',
'page.number' => 'nullable|integer|min:1',
'page.size' => 'nullable|integer|min:1|max:25',
'include' => 'nullable|string|in:debit_account,credit_account'
'include' => 'nullable|string|in:debit_account,credit_account',
]);

$response = Http::withHeaders([
'Authorization' => 'Bearer '.$this->token,
'Content-Type' => 'application/json',
])->get($this->serviceUrl.'/'.$id.'/transactions', $parameters);

return $this->handleResponse($response);
}

/**
* @param string $id
* @param array $data
* @param array $parameters
* @return array
*/
public function debit(string $id, array $data, array $parameters = []): array
{
Validator::validate($parameters, [
'include' => 'nullable|string|in:debit_account,credit_account,payments'
'include' => 'nullable|string|in:debit_account,credit_account,payments',
]);
$response = Http::withHeaders([
'Authorization' => 'Bearer '.$this->token,
'Content-Type' => 'application/json',
])->post($this->serviceUrl.'/'.$id.'/debit_transactions?'.http_build_query($parameters), $data);

return $this->handleResponse($response);
}

/**
* @param string $id
* @param array $data
* @return array
*/
public function credit(string $id, array $data): array
{
$response = Http::withHeaders([
'Authorization' => 'Bearer '.$this->token,
'Content-Type' => 'application/json',
])->post($this->serviceUrl.'/'.$id.'/credit_transactions', $data);

return $this->handleResponse($response);
}
}
}
21 changes: 4 additions & 17 deletions src/Models/Cash/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,35 @@
*/
class Transaction extends ParasutV4
{
/**
* @var string
*/
private string $serviceUrl;

/**
* @param $config
*/
public function __construct($config)
{
parent::__construct($config);
$this->serviceUrl = $this->config['api_url'].$this->config['company_id'].'/transactions';
}

/**
* @param string $id
* @param array $parameters
* @return array
*/
public function show(string $id, array $parameters = []): array
{
Validator::validate($parameters, [
'include' => 'nullable|string|in:debit_account,credit_account,payments'
'include' => 'nullable|string|in:debit_account,credit_account,payments',
]);

$response = Http::withHeaders([
'Authorization' => 'Bearer '.$this->token,
'Content-Type' => 'application/json',
])->get($this->serviceUrl.'/'.$id, $parameters);

return $this->handleResponse($response);
}

/**
* @param string $id
* @return array
*/
public function delete(string $id): array
{
$response = Http::withHeaders([
'Authorization' => 'Bearer '.$this->token,
'Content-Type' => 'application/json',
])->delete($this->serviceUrl.'/'.$id);

return $this->handleResponse($response);
}
}
}
Loading

0 comments on commit 0a808ac

Please sign in to comment.