Skip to content

Commit

Permalink
applied pint styles, added action to check for expired token
Browse files Browse the repository at this point in the history
  • Loading branch information
dcblogdev committed Sep 1, 2024
1 parent 700b1a0 commit b59b0ba
Show file tree
Hide file tree
Showing 19 changed files with 134 additions and 141 deletions.
3 changes: 1 addition & 2 deletions src/Actions/tokenExpiredAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Dcblogdev\Xero\Actions;

use Dcblogdev\Xero\Exceptions\XeroTokenExpiredException;
use Dcblogdev\Xero\Models\XeroToken;
use Exception;
use Illuminate\Http\RedirectResponse;
Expand All @@ -26,4 +25,4 @@ public function __invoke(array $result, XeroToken $token): ?RedirectResponse

return null;
}
}
}
17 changes: 9 additions & 8 deletions src/Console/Commands/XeroKeepAliveCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@

class XeroKeepAliveCommand extends Command
{
protected $signature = 'xero:keep-alive';
protected $signature = 'xero:keep-alive';

protected $description = 'Run this command to refresh token if its due to expire. schedule this to run daily to avoid token expiring when using CLI commands';

public function handle(): void
{
$this->newLine();
// Fetch all tenants for when multiple tenants are in use.
$tenants = XeroToken::all();
foreach($tenants as $tenant) {

foreach ($tenants as $tenant) {

// Set the tenant ID
Xero::setTenantId($tenant->tenant_id);

if (Xero::isConnected()) {
Xero::getAccessToken($redirectWhenNotConnected = false);
$this->info('Refreshing Token for Tenant: '.$tenant->tenant_name . ' - Successful');
$this->info('Refreshing Token for Tenant: '.$tenant->tenant_name.' - Successful');
} else {
$this->info('Refreshing Token for Tenant: '.$tenant->tenant_name . ' - Not Connected');
$this->info('Refreshing Token for Tenant: '.$tenant->tenant_name.' - Not Connected');
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/Console/Commands/XeroShowAllCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Dcblogdev\Xero\Console\Commands;

use Illuminate\Console\Command;
use Dcblogdev\Xero\Models\XeroToken;
use Illuminate\Console\Command;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Support\Facades\Crypt;

Expand All @@ -29,7 +29,7 @@ public function handle()
$this->line('All XERO Tokens in storage');
$this->newLine();

$dataToDisplay = [
$dataToDisplay = [
'id',
'tenant_name',
'tenant_id',
Expand All @@ -40,7 +40,7 @@ public function handle()
$tokens = XeroToken::select($dataToDisplay)->get();

if (config('xero.encrypt')) {
$tokens->map(function($token) {
$tokens->map(function ($token) {
try {
$access_token = Crypt::decryptString($token->access_token);
} catch (DecryptException $e) {
Expand All @@ -53,9 +53,10 @@ public function handle()
} catch (DecryptException $e) {
$refresh_token = $token->refresh_token;
}

$token->access_token = $access_token;
$token->refresh_token = $refresh_token;

return $token;
});
}
Expand Down
7 changes: 4 additions & 3 deletions src/Enums/FilterOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace Dcblogdev\Xero\Enums;

enum FilterOptions: string {
enum FilterOptions: string
{
case IDS = 'ids';
case INCLUDEARCHIVED = 'includeArchived';
case ORDER = 'order';
Expand All @@ -13,8 +14,8 @@ enum FilterOptions: string {

public static function isValid(string $value): bool
{
$validValues = array_map(fn($case) => $case->value, self::cases());
$validValues = array_map(fn ($case) => $case->value, self::cases());

return in_array($value, $validValues);
}
}
}
3 changes: 1 addition & 2 deletions src/Facades/Xero.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
* @method static array post (string $endpoint, array $params = [])
* @method static array patch (string $endpoint, array $params = [])
* @method static array delete (string $endpoint, array $params = [])
*
* @mixin \Dcblogdev\Xero\Xero
*/
class Xero extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Models/XeroToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected static function newFactory(): TokenFactory
protected function expires(): Attribute
{
return Attribute::get(
fn(): DateTimeInterface => $this->updated_at->addSeconds((int)$this->expires_in)
fn (): DateTimeInterface => $this->updated_at->addSeconds((int) $this->expires_in)
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Resources/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ public function store(array $data): array

return $result['body']['Invoices'][0];
}

public function attachments(string $invoiceId): array
{
$result = parent::get('Invoices/'.$invoiceId.'/Attachments');

return $result['body']['Attachments'];
}
public function attachment(string $invoiceId, string $attachmentId = null, string $fileName = null): string

public function attachment(string $invoiceId, ?string $attachmentId = null, ?string $fileName = null): string
{
// Depending on the application we may want to get it by the FileName instead fo the AttachmentId
$nameOrId = $attachmentId ? $attachmentId : $fileName;

$result = parent::get('Invoices/'.$invoiceId.'/Attachments/'.$nameOrId);

return $result['body'];
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Webhooks extends Xero

public function validate(): bool
{
$this->payload = file_get_contents("php://input");
$this->payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_XERO_SIGNATURE'];

return hash_equals($this->getSignature(), $signature);
Expand Down
Loading

0 comments on commit b59b0ba

Please sign in to comment.